{"action":"created","comment":{"url":"https://api.github.com/repos/GPII/windows/pulls/comments/197772189","pull_request_review_id":131578292,"id":197772189,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5Nzc3MjE4OQ==","diff_hunk":"@@ -0,0 +1,159 @@\n+/* The GPII windows service.\n+ *\n+ * Copyright 2017 Raising the Floor - International\n+ *\n+ * Licensed under the New BSD license. You may not use this file except in\n+ * compliance with this License.\n+ *\n+ * The R&D leading to these results received funding from the\n+ * Department of Education - Grant H421A150005 (GPII-APCP). However,\n+ * these results do not necessarily represent the policy of the\n+ * Department of Education, and you should not assume endorsement by the\n+ * Federal Government.\n+ *\n+ * You may obtain a copy of the License at\n+ * https://github.com/GPII/universal/blob/master/LICENSE.txt\n+ */\n+\n+\"use strict\";\n+\n+var os_service = require(\"os-service\"),\n+    path = require(\"path\"),\n+    fs = require(\"fs\"),\n+    events = require(\"events\"),\n+    logging = require(\"./logging.js\"),\n+    windows = require(\"./windows.js\"),\n+    parseArgs = require(\"minimist\");\n+\n+// Different parts of the service are isolated, and will communicate by emitting events through this central \"service\"\n+// object.\n+var service = new events.EventEmitter();\n+\n+service.args = parseArgs(process.argv.slice(2));\n+\n+// true if the process running as a Windows Service, otherwise a normal user process.\n+service.isService = !!service.args.service;\n+// true if the service is an exe file (rather than node)\n+service.isExe = !!process.versions.pkg;\n+\n+/** Log something */\n+service.log = logging.log;\n+service.logFatal = logging.fatal;\n+service.logError = logging.error;\n+service.logWarn = logging.warn;\n+service.logDebug = logging.debug;\n+\n+// Change directory to a sane location, allowing relative paths in the config file.\n+var dir = null;\n+if (service.isExe) {\n+    // The path of gpii-app.exe\n+    dir = path.dirname(process.execPath);\n+} else {\n+    // Path of the index.js.\n+    dir = path.join(__dirname, \"..\");\n+}\n+\n+process.chdir(dir);\n+\n+// Load the config file.\n+var configFile = service.args.config;\n+if (!configFile) {\n+    if (service.isService) {\n+        // Check if there's a config file next to the service executable.\n+        var tryFile = path.join(dir, \"service.json\");\n+        if (fs.existsSync(tryFile)) {\n+            configFile = tryFile;\n+        }\n+    }\n+    if (!configFile) {\n+        // Use the built-in config file.\n+        configFile = (service.isService ? \"../config/service.json\" : \"../config/service.dev.json\");\n+    }\n+}\n+if ((configFile.indexOf(\"/\") === -1) && (configFile.indexOf(\"\\\\\") === -1)) {\n+    configFile = path.join(dir, \"config\", configFile);\n+}\n+\n+service.log(\"Loading config file\", configFile);\n+service.config = require(configFile);\n+\n+// Change to the configured log level (if it's not passed via command line)\n+if (!service.args.loglevel && service.config.logging && service.config.logging.level) {\n+    logging.setLogLevel(service.config.logging.level);\n+}\n+\n+/**\n+ * Called when the service has just started.\n+ */\n+service.start = function () {\n+    service.isService = os_service.getState() !== \"stopped\";\n+    // Control codes are how Windows tells services about certain system events. These are caught in os_service.\n+    // Register the control codes that the service would be interested in.\n+    os_service.acceptControl([\"start\", \"stop\", \"shutdown\", \"sessionchange\"], true);\n+    // Handle all registered control codes.\n+    os_service.on(\"*\", service.controlHandler);\n+    os_service.on(\"stop\", service.stop);\n+\n+    service.event(\"start\");\n+    service.log(\"service start\");\n+\n+    if (windows.isUserLoggedOn) {\n+        // The service was started while a user is already active; fake a session-change event to get things started.\n+        service.controlHandler(\"sessionchange\", \"session-logon\");\n+    }\n+};\n+\n+/**\n+ * Stop the service.\n+ */\n+service.stop = function () {\n+    service.event(\"stop\");\n+    os_service.stop();\n+};\n+\n+/**\n+ * Called when the service receives a control code. This is what's used to detect a shutdown, service stop, or Windows\n+ * user log-in/out.\n+ *\n+ * Possible control codes: start, stop, pause, continue, interrogate, shutdown, paramchange, netbindadd, netbindremove,\n+ * netbindenable, netbinddisable, deviceevent, hardwareprofilechange, powerevent, sessionchange, preshutdown,\n+ * timechange, triggerevent.\n+ *\n+ * For this function to receive a control code, it needs to be added via os_service.acceptControl()\n+ *\n+ * See also: https://msdn.microsoft.com/library/ms683241\n+ *\n+ * @param controlName Name of the control code.","path":"service/src/service.js","position":126,"original_position":126,"commit_id":"8d126ca206c8be4bc6d6a2c479a1af34537bd875","original_commit_id":"8d126ca206c8be4bc6d6a2c479a1af34537bd875","user":{"login":"amb26","id":561418,"node_id":"MDQ6VXNlcjU2MTQxOA==","avatar_url":"https://avatars0.githubusercontent.com/u/561418?v=4","gravatar_id":"","url":"https://api.github.com/users/amb26","html_url":"https://github.com/amb26","followers_url":"https://api.github.com/users/amb26/followers","following_url":"https://api.github.com/users/amb26/following{/other_user}","gists_url":"https://api.github.com/users/amb26/gists{/gist_id}","starred_url":"https://api.github.com/users/amb26/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amb26/subscriptions","organizations_url":"https://api.github.com/users/amb26/orgs","repos_url":"https://api.github.com/users/amb26/repos","events_url":"https://api.github.com/users/amb26/events{/privacy}","received_events_url":"https://api.github.com/users/amb26/received_events","type":"User","site_admin":false},"body":"Types?","created_at":"2018-06-25T12:08:25Z","updated_at":"2018-06-25T12:08:26Z","html_url":"https://github.com/GPII/windows/pull/155#discussion_r197772189","pull_request_url":"https://api.github.com/repos/GPII/windows/pulls/155","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/GPII/windows/pulls/comments/197772189"},"html":{"href":"https://github.com/GPII/windows/pull/155#discussion_r197772189"},"pull_request":{"href":"https://api.github.com/repos/GPII/windows/pulls/155"}}},"pull_request":{"url":"https://api.github.com/repos/GPII/windows/pulls/155","id":147753924,"node_id":"MDExOlB1bGxSZXF1ZXN0MTQ3NzUzOTI0","html_url":"https://github.com/GPII/windows/pull/155","diff_url":"https://github.com/GPII/windows/pull/155.diff","patch_url":"https://github.com/GPII/windows/pull/155.patch","issue_url":"https://api.github.com/repos/GPII/windows/issues/155","number":155,"state":"open","locked":false,"title":"GPII-2338: Windows service.","user":{"login":"stegru","id":1867587,"node_id":"MDQ6VXNlcjE4Njc1ODc=","avatar_url":"https://avatars2.githubusercontent.com/u/1867587?v=4","gravatar_id":"","url":"https://api.github.com/users/stegru","html_url":"https://github.com/stegru","followers_url":"https://api.github.com/users/stegru/followers","following_url":"https://api.github.com/users/stegru/following{/other_user}","gists_url":"https://api.github.com/users/stegru/gists{/gist_id}","starred_url":"https://api.github.com/users/stegru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stegru/subscriptions","organizations_url":"https://api.github.com/users/stegru/orgs","repos_url":"https://api.github.com/users/stegru/repos","events_url":"https://api.github.com/users/stegru/events{/privacy}","received_events_url":"https://api.github.com/users/stegru/received_events","type":"User","site_admin":false},"body":"Here's the Windows Service, that starts GPII and the listeners when a user logs into windows, and restarts them if they die.\r\n\r\nAt the moment, this provides no value; GPII will operate the same as before. ~~The installer needs to be adjusted to install and start the service.~~\r\n\r\nMore info in the [README](https://github.com/stegru/windows/blob/GPII-2338/service/README.md).\r\n\r\n**Update:**\r\nThis changes the way GPII is started. Instead of using the AutoRun registry key, the service starts GPII when the user logs on. Its passed an environment value `GPII_SERVICE_PIPE` which instructs gpii to connect to the pipe (GPII-2399).\r\n\r\nIf it's ok if GPII is started normally - it just wont be able to enjoy the goodness of the service (currently nothing but restart on crash). However, if the service is started from within the source code (ie, via node service/index.js), then it will open an insecure pipe to which GPII will connect.\r\n\r\nThe service writes a log to `C:\\ProgramData\\GPII\\gpii-service.log` (`%APPDATA%/GPII/` is not used, because that's the user's profile directory, and the service doesn't run as the user)\r\n","created_at":"2017-10-20T09:18:05Z","updated_at":"2018-06-25T12:08:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cd4597a3c5ab065e2bcf2a1952d5f31d091f9a1b","assignee":{"login":"stegru","id":1867587,"node_id":"MDQ6VXNlcjE4Njc1ODc=","avatar_url":"https://avatars2.githubusercontent.com/u/1867587?v=4","gravatar_id":"","url":"https://api.github.com/users/stegru","html_url":"https://github.com/stegru","followers_url":"https://api.github.com/users/stegru/followers","following_url":"https://api.github.com/users/stegru/following{/other_user}","gists_url":"https://api.github.com/users/stegru/gists{/gist_id}","starred_url":"https://api.github.com/users/stegru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stegru/subscriptions","organizations_url":"https://api.github.com/users/stegru/orgs","repos_url":"https://api.github.com/users/stegru/repos","events_url":"https://api.github.com/users/stegru/events{/privacy}","received_events_url":"https://api.github.com/users/stegru/received_events","type":"User","site_admin":false},"assignees":[{"login":"stegru","id":1867587,"node_id":"MDQ6VXNlcjE4Njc1ODc=","avatar_url":"https://avatars2.githubusercontent.com/u/1867587?v=4","gravatar_id":"","url":"https://api.github.com/users/stegru","html_url":"https://github.com/stegru","followers_url":"https://api.github.com/users/stegru/followers","following_url":"https://api.github.com/users/stegru/following{/other_user}","gists_url":"https://api.github.com/users/stegru/gists{/gist_id}","starred_url":"https://api.github.com/users/stegru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stegru/subscriptions","organizations_url":"https://api.github.com/users/stegru/orgs","repos_url":"https://api.github.com/users/stegru/repos","events_url":"https://api.github.com/users/stegru/events{/privacy}","received_events_url":"https://api.github.com/users/stegru/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/GPII/windows/pulls/155/commits","review_comments_url":"https://api.github.com/repos/GPII/windows/pulls/155/comments","review_comment_url":"https://api.github.com/repos/GPII/windows/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GPII/windows/issues/155/comments","statuses_url":"https://api.github.com/repos/GPII/windows/statuses/8d126ca206c8be4bc6d6a2c479a1af34537bd875","head":{"label":"stegru:GPII-2338","ref":"GPII-2338","sha":"8d126ca206c8be4bc6d6a2c479a1af34537bd875","user":{"login":"stegru","id":1867587,"node_id":"MDQ6VXNlcjE4Njc1ODc=","avatar_url":"https://avatars2.githubusercontent.com/u/1867587?v=4","gravatar_id":"","url":"https://api.github.com/users/stegru","html_url":"https://github.com/stegru","followers_url":"https://api.github.com/users/stegru/followers","following_url":"https://api.github.com/users/stegru/following{/other_user}","gists_url":"https://api.github.com/users/stegru/gists{/gist_id}","starred_url":"https://api.github.com/users/stegru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stegru/subscriptions","organizations_url":"https://api.github.com/users/stegru/orgs","repos_url":"https://api.github.com/users/stegru/repos","events_url":"https://api.github.com/users/stegru/events{/privacy}","received_events_url":"https://api.github.com/users/stegru/received_events","type":"User","site_admin":false},"repo":{"id":64118154,"node_id":"MDEwOlJlcG9zaXRvcnk2NDExODE1NA==","name":"windows","full_name":"stegru/windows","owner":{"login":"stegru","id":1867587,"node_id":"MDQ6VXNlcjE4Njc1ODc=","avatar_url":"https://avatars2.githubusercontent.com/u/1867587?v=4","gravatar_id":"","url":"https://api.github.com/users/stegru","html_url":"https://github.com/stegru","followers_url":"https://api.github.com/users/stegru/followers","following_url":"https://api.github.com/users/stegru/following{/other_user}","gists_url":"https://api.github.com/users/stegru/gists{/gist_id}","starred_url":"https://api.github.com/users/stegru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stegru/subscriptions","organizations_url":"https://api.github.com/users/stegru/orgs","repos_url":"https://api.github.com/users/stegru/repos","events_url":"https://api.github.com/users/stegru/events{/privacy}","received_events_url":"https://api.github.com/users/stegru/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stegru/windows","description":"Windows-specific code for the GPII realtime framework","fork":true,"url":"https://api.github.com/repos/stegru/windows","forks_url":"https://api.github.com/repos/stegru/windows/forks","keys_url":"https://api.github.com/repos/stegru/windows/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stegru/windows/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stegru/windows/teams","hooks_url":"https://api.github.com/repos/stegru/windows/hooks","issue_events_url":"https://api.github.com/repos/stegru/windows/issues/events{/number}","events_url":"https://api.github.com/repos/stegru/windows/events","assignees_url":"https://api.github.com/repos/stegru/windows/assignees{/user}","branches_url":"https://api.github.com/repos/stegru/windows/branches{/branch}","tags_url":"https://api.github.com/repos/stegru/windows/tags","blobs_url":"https://api.github.com/repos/stegru/windows/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stegru/windows/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stegru/windows/git/refs{/sha}","trees_url":"https://api.github.com/repos/stegru/windows/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stegru/windows/statuses/{sha}","languages_url":"https://api.github.com/repos/stegru/windows/languages","stargazers_url":"https://api.github.com/repos/stegru/windows/stargazers","contributors_url":"https://api.github.com/repos/stegru/windows/contributors","subscribers_url":"https://api.github.com/repos/stegru/windows/subscribers","subscription_url":"https://api.github.com/repos/stegru/windows/subscription","commits_url":"https://api.github.com/repos/stegru/windows/commits{/sha}","git_commits_url":"https://api.github.com/repos/stegru/windows/git/commits{/sha}","comments_url":"https://api.github.com/repos/stegru/windows/comments{/number}","issue_comment_url":"https://api.github.com/repos/stegru/windows/issues/comments{/number}","contents_url":"https://api.github.com/repos/stegru/windows/contents/{+path}","compare_url":"https://api.github.com/repos/stegru/windows/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stegru/windows/merges","archive_url":"https://api.github.com/repos/stegru/windows/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stegru/windows/downloads","issues_url":"https://api.github.com/repos/stegru/windows/issues{/number}","pulls_url":"https://api.github.com/repos/stegru/windows/pulls{/number}","milestones_url":"https://api.github.com/repos/stegru/windows/milestones{/number}","notifications_url":"https://api.github.com/repos/stegru/windows/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stegru/windows/labels{/name}","releases_url":"https://api.github.com/repos/stegru/windows/releases{/id}","deployments_url":"https://api.github.com/repos/stegru/windows/deployments","created_at":"2016-07-25T08:41:23Z","updated_at":"2018-03-27T09:50:00Z","pushed_at":"2018-06-24T15:23:20Z","git_url":"git://github.com/stegru/windows.git","ssh_url":"git@github.com:stegru/windows.git","clone_url":"https://github.com/stegru/windows.git","svn_url":"https://github.com/stegru/windows","homepage":"http://gpii.net","size":43884,"stargazers_count":0,"watchers_count":0,"language":"PowerShell","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"GPII:master","ref":"master","sha":"92c7c83a1991f185bc820d87fdc41ffd88fb66d3","user":{"login":"GPII","id":1343050,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzNDMwNTA=","avatar_url":"https://avatars0.githubusercontent.com/u/1343050?v=4","gravatar_id":"","url":"https://api.github.com/users/GPII","html_url":"https://github.com/GPII","followers_url":"https://api.github.com/users/GPII/followers","following_url":"https://api.github.com/users/GPII/following{/other_user}","gists_url":"https://api.github.com/users/GPII/gists{/gist_id}","starred_url":"https://api.github.com/users/GPII/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GPII/subscriptions","organizations_url":"https://api.github.com/users/GPII/orgs","repos_url":"https://api.github.com/users/GPII/repos","events_url":"https://api.github.com/users/GPII/events{/privacy}","received_events_url":"https://api.github.com/users/GPII/received_events","type":"Organization","site_admin":false},"repo":{"id":3623725,"node_id":"MDEwOlJlcG9zaXRvcnkzNjIzNzI1","name":"windows","full_name":"GPII/windows","owner":{"login":"GPII","id":1343050,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzNDMwNTA=","avatar_url":"https://avatars0.githubusercontent.com/u/1343050?v=4","gravatar_id":"","url":"https://api.github.com/users/GPII","html_url":"https://github.com/GPII","followers_url":"https://api.github.com/users/GPII/followers","following_url":"https://api.github.com/users/GPII/following{/other_user}","gists_url":"https://api.github.com/users/GPII/gists{/gist_id}","starred_url":"https://api.github.com/users/GPII/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GPII/subscriptions","organizations_url":"https://api.github.com/users/GPII/orgs","repos_url":"https://api.github.com/users/GPII/repos","events_url":"https://api.github.com/users/GPII/events{/privacy}","received_events_url":"https://api.github.com/users/GPII/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GPII/windows","description":"Windows-specific code for the GPII realtime framework","fork":false,"url":"https://api.github.com/repos/GPII/windows","forks_url":"https://api.github.com/repos/GPII/windows/forks","keys_url":"https://api.github.com/repos/GPII/windows/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GPII/windows/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GPII/windows/teams","hooks_url":"https://api.github.com/repos/GPII/windows/hooks","issue_events_url":"https://api.github.com/repos/GPII/windows/issues/events{/number}","events_url":"https://api.github.com/repos/GPII/windows/events","assignees_url":"https://api.github.com/repos/GPII/windows/assignees{/user}","branches_url":"https://api.github.com/repos/GPII/windows/branches{/branch}","tags_url":"https://api.github.com/repos/GPII/windows/tags","blobs_url":"https://api.github.com/repos/GPII/windows/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GPII/windows/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GPII/windows/git/refs{/sha}","trees_url":"https://api.github.com/repos/GPII/windows/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GPII/windows/statuses/{sha}","languages_url":"https://api.github.com/repos/GPII/windows/languages","stargazers_url":"https://api.github.com/repos/GPII/windows/stargazers","contributors_url":"https://api.github.com/repos/GPII/windows/contributors","subscribers_url":"https://api.github.com/repos/GPII/windows/subscribers","subscription_url":"https://api.github.com/repos/GPII/windows/subscription","commits_url":"https://api.github.com/repos/GPII/windows/commits{/sha}","git_commits_url":"https://api.github.com/repos/GPII/windows/git/commits{/sha}","comments_url":"https://api.github.com/repos/GPII/windows/comments{/number}","issue_comment_url":"https://api.github.com/repos/GPII/windows/issues/comments{/number}","contents_url":"https://api.github.com/repos/GPII/windows/contents/{+path}","compare_url":"https://api.github.com/repos/GPII/windows/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GPII/windows/merges","archive_url":"https://api.github.com/repos/GPII/windows/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GPII/windows/downloads","issues_url":"https://api.github.com/repos/GPII/windows/issues{/number}","pulls_url":"https://api.github.com/repos/GPII/windows/pulls{/number}","milestones_url":"https://api.github.com/repos/GPII/windows/milestones{/number}","notifications_url":"https://api.github.com/repos/GPII/windows/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GPII/windows/labels{/name}","releases_url":"https://api.github.com/repos/GPII/windows/releases{/id}","deployments_url":"https://api.github.com/repos/GPII/windows/deployments","created_at":"2012-03-05T04:02:15Z","updated_at":"2018-06-08T13:20:04Z","pushed_at":"2018-06-24T15:23:21Z","git_url":"git://github.com/GPII/windows.git","ssh_url":"git@github.com:GPII/windows.git","clone_url":"https://github.com/GPII/windows.git","svn_url":"https://github.com/GPII/windows","homepage":"http://gpii.net","size":40058,"stargazers_count":20,"watchers_count":20,"language":"PowerShell","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":38,"mirror_url":null,"archived":false,"open_issues_count":16,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":38,"open_issues":16,"watchers":20,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GPII/windows/pulls/155"},"html":{"href":"https://github.com/GPII/windows/pull/155"},"issue":{"href":"https://api.github.com/repos/GPII/windows/issues/155"},"comments":{"href":"https://api.github.com/repos/GPII/windows/issues/155/comments"},"review_comments":{"href":"https://api.github.com/repos/GPII/windows/pulls/155/comments"},"review_comment":{"href":"https://api.github.com/repos/GPII/windows/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GPII/windows/pulls/155/commits"},"statuses":{"href":"https://api.github.com/repos/GPII/windows/statuses/8d126ca206c8be4bc6d6a2c479a1af34537bd875"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"amb26"}}