{"action":"created","comment":{"url":"https://api.github.com/repos/ants/patroni/pulls/comments/85739876","pull_request_review_id":6436204,"id":85739876,"diff_hunk":"@@ -698,31 +690,28 @@ def start(self, block_callbacks=False):\n \n         self.set_state('starting')\n \n-        env = {'PATH': os.environ.get('PATH')}\n-        # pg_ctl will write a FATAL if the username is incorrect. exporting PGUSER if necessary\n-        if 'username' in self._superuser and self._superuser['username'] != os.environ.get('USER'):\n-            env['PGUSER'] = self._superuser['username']\n-\n         self._write_postgresql_conf()\n         self.resolve_connection_addresses()\n \n-        options = ' '.join(\"--{0}='{1}'\".format(p, self._server_parameters[p]) for p, v in self.CMDLINE_OPTIONS.items()\n+        options = ' '.join('--{0}=\"{1}\"'.format(p, self._server_parameters[p]) for p, v in self.CMDLINE_OPTIONS.items()\n                            if self._major_version >= v[2])\n \n+        cmd = 'exec \"{0}\" -D \"{1}\" {2} < \"/dev/null\" 2>&1'.format(self._pgcommand('postgres'), self._data_dir, options)\n+\n         start_initiated = time.time()\n-        ret = self.pg_ctl('start', '-o', options, env=env, preexec_fn=os.setsid)\n-        start_completed = time.time()\n-        if ret:\n-            # We want postmaster to open ports before we continue\n-            try:\n-                start_timeout = float(self.config.get('pg_ctl_timeout', 60))\n-            except ValueError:\n-                start_timeout = 60\n-            ret = self.wait_for_port_open(start_timeout, start_initiated, start_completed)\n+        pid = os.fork()\n+        if pid == 0:\n+            os.setsid()\n+            os.execle(\"/bin/sh\", \"/bin/sh\", \"-c\", cmd, {'PATH': os.environ.get('PATH')})","path":"patroni/postgresql.py","position":97,"original_position":94,"commit_id":"0bbafe763730e1c5f79e2b6ca8f876a28d123523","original_commit_id":"308fc3afd508ddd5384806358885a2eabfe1a746","user":{"login":"ants","id":64938,"avatar_url":"https://avatars.githubusercontent.com/u/64938?v=3","gravatar_id":"","url":"https://api.github.com/users/ants","html_url":"https://github.com/ants","followers_url":"https://api.github.com/users/ants/followers","following_url":"https://api.github.com/users/ants/following{/other_user}","gists_url":"https://api.github.com/users/ants/gists{/gist_id}","starred_url":"https://api.github.com/users/ants/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ants/subscriptions","organizations_url":"https://api.github.com/users/ants/orgs","repos_url":"https://api.github.com/users/ants/repos","events_url":"https://api.github.com/users/ants/events{/privacy}","received_events_url":"https://api.github.com/users/ants/received_events","type":"User","site_admin":false},"body":"Not a Windows expert by far, but I'll hazard a guess that this doesn't work on Windows :) Do we care?\r\n\r\nBefore execing there is probably some cleanup stuff to do, I know that watchdog support wants that the watchdog device file handle is closed and not passed on to postgres. Probably good to close the rest too. Why did you decide to go through `/bin/sh` and `os.execle`? Using `subprocess.Popen` to execute postgres directly might be more portable and give us stuff like close_fds.","created_at":"2016-10-31T13:43:47Z","updated_at":"2016-10-31T13:43:47Z","html_url":"https://github.com/ants/patroni/pull/4#discussion_r85739876","pull_request_url":"https://api.github.com/repos/ants/patroni/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/ants/patroni/pulls/comments/85739876"},"html":{"href":"https://github.com/ants/patroni/pull/4#discussion_r85739876"},"pull_request":{"href":"https://api.github.com/repos/ants/patroni/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/ants/patroni/pulls/4","id":91592645,"html_url":"https://github.com/ants/patroni/pull/4","diff_url":"https://github.com/ants/patroni/pull/4.diff","patch_url":"https://github.com/ants/patroni/pull/4.patch","issue_url":"https://api.github.com/repos/ants/patroni/issues/4","number":4,"state":"open","locked":false,"title":"Reimplement pg_ctl start in python to simplify port opening detection","user":{"login":"CyberDem0n","id":3407345,"avatar_url":"https://avatars.githubusercontent.com/u/3407345?v=3","gravatar_id":"","url":"https://api.github.com/users/CyberDem0n","html_url":"https://github.com/CyberDem0n","followers_url":"https://api.github.com/users/CyberDem0n/followers","following_url":"https://api.github.com/users/CyberDem0n/following{/other_user}","gists_url":"https://api.github.com/users/CyberDem0n/gists{/gist_id}","starred_url":"https://api.github.com/users/CyberDem0n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CyberDem0n/subscriptions","organizations_url":"https://api.github.com/users/CyberDem0n/orgs","repos_url":"https://api.github.com/users/CyberDem0n/repos","events_url":"https://api.github.com/users/CyberDem0n/events{/privacy}","received_events_url":"https://api.github.com/users/CyberDem0n/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-31T11:22:00Z","updated_at":"2016-10-31T13:49:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a429f1e43e0549808ec28faace7dcd4849b7499f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ants/patroni/pulls/4/commits","review_comments_url":"https://api.github.com/repos/ants/patroni/pulls/4/comments","review_comment_url":"https://api.github.com/repos/ants/patroni/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ants/patroni/issues/4/comments","statuses_url":"https://api.github.com/repos/ants/patroni/statuses/0bbafe763730e1c5f79e2b6ca8f876a28d123523","head":{"label":"CyberDem0n:feature/pg_ctl_start","ref":"feature/pg_ctl_start","sha":"0bbafe763730e1c5f79e2b6ca8f876a28d123523","user":{"login":"CyberDem0n","id":3407345,"avatar_url":"https://avatars.githubusercontent.com/u/3407345?v=3","gravatar_id":"","url":"https://api.github.com/users/CyberDem0n","html_url":"https://github.com/CyberDem0n","followers_url":"https://api.github.com/users/CyberDem0n/followers","following_url":"https://api.github.com/users/CyberDem0n/following{/other_user}","gists_url":"https://api.github.com/users/CyberDem0n/gists{/gist_id}","starred_url":"https://api.github.com/users/CyberDem0n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CyberDem0n/subscriptions","organizations_url":"https://api.github.com/users/CyberDem0n/orgs","repos_url":"https://api.github.com/users/CyberDem0n/repos","events_url":"https://api.github.com/users/CyberDem0n/events{/privacy}","received_events_url":"https://api.github.com/users/CyberDem0n/received_events","type":"User","site_admin":false},"repo":{"id":69675571,"name":"patroni","full_name":"CyberDem0n/patroni","owner":{"login":"CyberDem0n","id":3407345,"avatar_url":"https://avatars.githubusercontent.com/u/3407345?v=3","gravatar_id":"","url":"https://api.github.com/users/CyberDem0n","html_url":"https://github.com/CyberDem0n","followers_url":"https://api.github.com/users/CyberDem0n/followers","following_url":"https://api.github.com/users/CyberDem0n/following{/other_user}","gists_url":"https://api.github.com/users/CyberDem0n/gists{/gist_id}","starred_url":"https://api.github.com/users/CyberDem0n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CyberDem0n/subscriptions","organizations_url":"https://api.github.com/users/CyberDem0n/orgs","repos_url":"https://api.github.com/users/CyberDem0n/repos","events_url":"https://api.github.com/users/CyberDem0n/events{/privacy}","received_events_url":"https://api.github.com/users/CyberDem0n/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/CyberDem0n/patroni","description":"A template for PostgreSQL High Availability with ZooKeeper, etcd or Consul","fork":true,"url":"https://api.github.com/repos/CyberDem0n/patroni","forks_url":"https://api.github.com/repos/CyberDem0n/patroni/forks","keys_url":"https://api.github.com/repos/CyberDem0n/patroni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CyberDem0n/patroni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CyberDem0n/patroni/teams","hooks_url":"https://api.github.com/repos/CyberDem0n/patroni/hooks","issue_events_url":"https://api.github.com/repos/CyberDem0n/patroni/issues/events{/number}","events_url":"https://api.github.com/repos/CyberDem0n/patroni/events","assignees_url":"https://api.github.com/repos/CyberDem0n/patroni/assignees{/user}","branches_url":"https://api.github.com/repos/CyberDem0n/patroni/branches{/branch}","tags_url":"https://api.github.com/repos/CyberDem0n/patroni/tags","blobs_url":"https://api.github.com/repos/CyberDem0n/patroni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CyberDem0n/patroni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CyberDem0n/patroni/git/refs{/sha}","trees_url":"https://api.github.com/repos/CyberDem0n/patroni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CyberDem0n/patroni/statuses/{sha}","languages_url":"https://api.github.com/repos/CyberDem0n/patroni/languages","stargazers_url":"https://api.github.com/repos/CyberDem0n/patroni/stargazers","contributors_url":"https://api.github.com/repos/CyberDem0n/patroni/contributors","subscribers_url":"https://api.github.com/repos/CyberDem0n/patroni/subscribers","subscription_url":"https://api.github.com/repos/CyberDem0n/patroni/subscription","commits_url":"https://api.github.com/repos/CyberDem0n/patroni/commits{/sha}","git_commits_url":"https://api.github.com/repos/CyberDem0n/patroni/git/commits{/sha}","comments_url":"https://api.github.com/repos/CyberDem0n/patroni/comments{/number}","issue_comment_url":"https://api.github.com/repos/CyberDem0n/patroni/issues/comments{/number}","contents_url":"https://api.github.com/repos/CyberDem0n/patroni/contents/{+path}","compare_url":"https://api.github.com/repos/CyberDem0n/patroni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CyberDem0n/patroni/merges","archive_url":"https://api.github.com/repos/CyberDem0n/patroni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CyberDem0n/patroni/downloads","issues_url":"https://api.github.com/repos/CyberDem0n/patroni/issues{/number}","pulls_url":"https://api.github.com/repos/CyberDem0n/patroni/pulls{/number}","milestones_url":"https://api.github.com/repos/CyberDem0n/patroni/milestones{/number}","notifications_url":"https://api.github.com/repos/CyberDem0n/patroni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CyberDem0n/patroni/labels{/name}","releases_url":"https://api.github.com/repos/CyberDem0n/patroni/releases{/id}","deployments_url":"https://api.github.com/repos/CyberDem0n/patroni/deployments","created_at":"2016-09-30T14:51:39Z","updated_at":"2016-09-30T14:51:40Z","pushed_at":"2016-10-31T13:40:07Z","git_url":"git://github.com/CyberDem0n/patroni.git","ssh_url":"git@github.com:CyberDem0n/patroni.git","clone_url":"https://github.com/CyberDem0n/patroni.git","svn_url":"https://github.com/CyberDem0n/patroni","homepage":"","size":1950,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ants:feature/master_start_timeout","ref":"feature/master_start_timeout","sha":"34f660feab1ea9caa16aaf31834380176cf776ca","user":{"login":"ants","id":64938,"avatar_url":"https://avatars.githubusercontent.com/u/64938?v=3","gravatar_id":"","url":"https://api.github.com/users/ants","html_url":"https://github.com/ants","followers_url":"https://api.github.com/users/ants/followers","following_url":"https://api.github.com/users/ants/following{/other_user}","gists_url":"https://api.github.com/users/ants/gists{/gist_id}","starred_url":"https://api.github.com/users/ants/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ants/subscriptions","organizations_url":"https://api.github.com/users/ants/orgs","repos_url":"https://api.github.com/users/ants/repos","events_url":"https://api.github.com/users/ants/events{/privacy}","received_events_url":"https://api.github.com/users/ants/received_events","type":"User","site_admin":false},"repo":{"id":65907385,"name":"patroni","full_name":"ants/patroni","owner":{"login":"ants","id":64938,"avatar_url":"https://avatars.githubusercontent.com/u/64938?v=3","gravatar_id":"","url":"https://api.github.com/users/ants","html_url":"https://github.com/ants","followers_url":"https://api.github.com/users/ants/followers","following_url":"https://api.github.com/users/ants/following{/other_user}","gists_url":"https://api.github.com/users/ants/gists{/gist_id}","starred_url":"https://api.github.com/users/ants/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ants/subscriptions","organizations_url":"https://api.github.com/users/ants/orgs","repos_url":"https://api.github.com/users/ants/repos","events_url":"https://api.github.com/users/ants/events{/privacy}","received_events_url":"https://api.github.com/users/ants/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ants/patroni","description":"A template for PostgreSQL High Availability with ZooKeeper, etcd or Consul","fork":true,"url":"https://api.github.com/repos/ants/patroni","forks_url":"https://api.github.com/repos/ants/patroni/forks","keys_url":"https://api.github.com/repos/ants/patroni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ants/patroni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ants/patroni/teams","hooks_url":"https://api.github.com/repos/ants/patroni/hooks","issue_events_url":"https://api.github.com/repos/ants/patroni/issues/events{/number}","events_url":"https://api.github.com/repos/ants/patroni/events","assignees_url":"https://api.github.com/repos/ants/patroni/assignees{/user}","branches_url":"https://api.github.com/repos/ants/patroni/branches{/branch}","tags_url":"https://api.github.com/repos/ants/patroni/tags","blobs_url":"https://api.github.com/repos/ants/patroni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ants/patroni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ants/patroni/git/refs{/sha}","trees_url":"https://api.github.com/repos/ants/patroni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ants/patroni/statuses/{sha}","languages_url":"https://api.github.com/repos/ants/patroni/languages","stargazers_url":"https://api.github.com/repos/ants/patroni/stargazers","contributors_url":"https://api.github.com/repos/ants/patroni/contributors","subscribers_url":"https://api.github.com/repos/ants/patroni/subscribers","subscription_url":"https://api.github.com/repos/ants/patroni/subscription","commits_url":"https://api.github.com/repos/ants/patroni/commits{/sha}","git_commits_url":"https://api.github.com/repos/ants/patroni/git/commits{/sha}","comments_url":"https://api.github.com/repos/ants/patroni/comments{/number}","issue_comment_url":"https://api.github.com/repos/ants/patroni/issues/comments{/number}","contents_url":"https://api.github.com/repos/ants/patroni/contents/{+path}","compare_url":"https://api.github.com/repos/ants/patroni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ants/patroni/merges","archive_url":"https://api.github.com/repos/ants/patroni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ants/patroni/downloads","issues_url":"https://api.github.com/repos/ants/patroni/issues{/number}","pulls_url":"https://api.github.com/repos/ants/patroni/pulls{/number}","milestones_url":"https://api.github.com/repos/ants/patroni/milestones{/number}","notifications_url":"https://api.github.com/repos/ants/patroni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ants/patroni/labels{/name}","releases_url":"https://api.github.com/repos/ants/patroni/releases{/id}","deployments_url":"https://api.github.com/repos/ants/patroni/deployments","created_at":"2016-08-17T12:53:28Z","updated_at":"2016-08-17T12:53:29Z","pushed_at":"2016-10-31T13:40:07Z","git_url":"git://github.com/ants/patroni.git","ssh_url":"git@github.com:ants/patroni.git","clone_url":"https://github.com/ants/patroni.git","svn_url":"https://github.com/ants/patroni","homepage":"","size":2044,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ants/patroni/pulls/4"},"html":{"href":"https://github.com/ants/patroni/pull/4"},"issue":{"href":"https://api.github.com/repos/ants/patroni/issues/4"},"comments":{"href":"https://api.github.com/repos/ants/patroni/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/ants/patroni/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/ants/patroni/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ants/patroni/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/ants/patroni/statuses/0bbafe763730e1c5f79e2b6ca8f876a28d123523"}}}}
{"actor":{"display_login":"ants"}}