{"action":"created","comment":{"url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls/comments/39795937","id":39795937,"diff_hunk":"@@ -0,0 +1,179 @@\n+\"\"\"\n+The worker \n+\"\"\"\n+from __future__ import print_function, absolute_import, unicode_literals\n+\n+from contextlib import contextmanager\n+import logging\n+import os\n+import time\n+import io\n+from binstar_build_client.utils.rm import rm_rf\n+from binstar_client import errors\n+import psutil\n+import requests\n+import yaml\n+import json\n+import pickle\n+import shutil\n+from tempfile import NamedTemporaryFile\n+from .utils.buffered_io import BufferedPopen\n+from .utils.build_log import BuildLog\n+from .utils.script_generator import gen_build_script, \\\n+    EXIT_CODE_OK, EXIT_CODE_ERROR, EXIT_CODE_FAILED\n+from .worker import Worker\n+import inspect\n+from binstar_client.utils import get_config\n+\n+log = logging.getLogger('binstar.build')\n+\n+def get_my_procs():\n+\n+    this_proc = psutil.Process()\n+\n+    if os.name == 'nt':\n+        myusername = this_proc.username()\n+        def ismyproc(proc):\n+            try:\n+                return proc.username() == myusername\n+            except psutil.AccessDenied:\n+                return False\n+    else:\n+        def ismyproc(proc):\n+            if inspect.isroutine(this_proc.uids):\n+                # psutil >= 2\n+                return proc.uids().real == this_proc.uids().real\n+            else:\n+                # psutil < 2\n+                return proc.uids.real == this_proc.uids.real\n+\n+\n+    return {proc.pid for proc in psutil.process_iter() if ismyproc(proc)}\n+\n+@contextmanager\n+def remove_files_after(files):\n+    try:\n+        yield\n+    finally:\n+        for filename in files:\n+            if os.path.isfile(filename):\n+                os.unlink(filename)\n+\n+\n+\n+class SuWorker(Worker):\n+    \"\"\"\n+    \n+    \"\"\"\n+    STATE_FILE = 'worker.yaml'\n+    JOURNAL_FILE = 'journal.csv'\n+    SLEEP_TIME = 10\n+    source_env = \"export PATH=/opt/anaconda/bin:${PATH} \"+ \\\n+                \"&& source activate anaconda.org \"\n+        \n+    def __init__(self, bs, args, build_users):\n+        self.bs = bs\n+        self.args = args\n+        self.build_users = build_users\n+        self.busy = {key:False for key in self.build_users}\n+        \n+    def _handle_job(self, job_data):","path":"binstar_build_client/worker/su_worker.py","position":80,"original_position":80,"commit_id":"bd2791ac73b1ce03e7e46619a869331a6e57ab7b","original_commit_id":"bd2791ac73b1ce03e7e46619a869331a6e57ab7b","user":{"login":"PeterDSteinberg","id":1445602,"avatar_url":"https://avatars.githubusercontent.com/u/1445602?v=3","gravatar_id":"","url":"https://api.github.com/users/PeterDSteinberg","html_url":"https://github.com/PeterDSteinberg","followers_url":"https://api.github.com/users/PeterDSteinberg/followers","following_url":"https://api.github.com/users/PeterDSteinberg/following{/other_user}","gists_url":"https://api.github.com/users/PeterDSteinberg/gists{/gist_id}","starred_url":"https://api.github.com/users/PeterDSteinberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PeterDSteinberg/subscriptions","organizations_url":"https://api.github.com/users/PeterDSteinberg/orgs","repos_url":"https://api.github.com/users/PeterDSteinberg/repos","events_url":"https://api.github.com/users/PeterDSteinberg/events{/privacy}","received_events_url":"https://api.github.com/users/PeterDSteinberg/received_events","type":"User","site_admin":false},"body":"The <code>self.bs</code> and <code>self.args</code> lines are the same as the parent, but a new argument build_users is added.  The final line <code>self.busy</code> sets up a dictionary for tracking which build users are occupied.","created_at":"2015-09-17T20:39:29Z","updated_at":"2015-09-17T20:39:29Z","html_url":"https://github.com/Anaconda-Server/anaconda-build/pull/88#discussion_r39795937","pull_request_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls/88","_links":{"self":{"href":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls/comments/39795937"},"html":{"href":"https://github.com/Anaconda-Server/anaconda-build/pull/88#discussion_r39795937"},"pull_request":{"href":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls/88"}}},"pull_request":{"url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls/88","id":45221887,"html_url":"https://github.com/Anaconda-Server/anaconda-build/pull/88","diff_url":"https://github.com/Anaconda-Server/anaconda-build/pull/88.diff","patch_url":"https://github.com/Anaconda-Server/anaconda-build/pull/88.patch","issue_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/issues/88","number":88,"state":"open","locked":false,"title":"Feature/su build users","user":{"login":"PeterDSteinberg","id":1445602,"avatar_url":"https://avatars.githubusercontent.com/u/1445602?v=3","gravatar_id":"","url":"https://api.github.com/users/PeterDSteinberg","html_url":"https://github.com/PeterDSteinberg","followers_url":"https://api.github.com/users/PeterDSteinberg/followers","following_url":"https://api.github.com/users/PeterDSteinberg/following{/other_user}","gists_url":"https://api.github.com/users/PeterDSteinberg/gists{/gist_id}","starred_url":"https://api.github.com/users/PeterDSteinberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PeterDSteinberg/subscriptions","organizations_url":"https://api.github.com/users/PeterDSteinberg/orgs","repos_url":"https://api.github.com/users/PeterDSteinberg/repos","events_url":"https://api.github.com/users/PeterDSteinberg/events{/privacy}","received_events_url":"https://api.github.com/users/PeterDSteinberg/received_events","type":"User","site_admin":false},"body":"Working to isolate build workers by running build jobs as su - some_user. The main worker processes needs to run as root and have a root anaconda install accessible to root and build users.  The main worker starts individual builds as a build user and then destroys all processes and deletes build worker's home directory.  At build start the home directory is replaced with /etc/worker-skel.  Documentation on installs need to be updated and there is a new argument  to anaconda build worker. ","created_at":"2015-09-16T20:45:24Z","updated_at":"2015-09-17T20:39:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"58981eaea5cb65d45b085ecde39396d091282f09","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls/88/commits","review_comments_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls/88/comments","review_comment_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/issues/88/comments","statuses_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/statuses/bd2791ac73b1ce03e7e46619a869331a6e57ab7b","head":{"label":"Anaconda-Server:feature/su_build_users","ref":"feature/su_build_users","sha":"bd2791ac73b1ce03e7e46619a869331a6e57ab7b","user":{"login":"Anaconda-Server","id":3571983,"avatar_url":"https://avatars.githubusercontent.com/u/3571983?v=3","gravatar_id":"","url":"https://api.github.com/users/Anaconda-Server","html_url":"https://github.com/Anaconda-Server","followers_url":"https://api.github.com/users/Anaconda-Server/followers","following_url":"https://api.github.com/users/Anaconda-Server/following{/other_user}","gists_url":"https://api.github.com/users/Anaconda-Server/gists{/gist_id}","starred_url":"https://api.github.com/users/Anaconda-Server/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Anaconda-Server/subscriptions","organizations_url":"https://api.github.com/users/Anaconda-Server/orgs","repos_url":"https://api.github.com/users/Anaconda-Server/repos","events_url":"https://api.github.com/users/Anaconda-Server/events{/privacy}","received_events_url":"https://api.github.com/users/Anaconda-Server/received_events","type":"Organization","site_admin":false},"repo":{"id":19550310,"name":"anaconda-build","full_name":"Anaconda-Server/anaconda-build","owner":{"login":"Anaconda-Server","id":3571983,"avatar_url":"https://avatars.githubusercontent.com/u/3571983?v=3","gravatar_id":"","url":"https://api.github.com/users/Anaconda-Server","html_url":"https://github.com/Anaconda-Server","followers_url":"https://api.github.com/users/Anaconda-Server/followers","following_url":"https://api.github.com/users/Anaconda-Server/following{/other_user}","gists_url":"https://api.github.com/users/Anaconda-Server/gists{/gist_id}","starred_url":"https://api.github.com/users/Anaconda-Server/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Anaconda-Server/subscriptions","organizations_url":"https://api.github.com/users/Anaconda-Server/orgs","repos_url":"https://api.github.com/users/Anaconda-Server/repos","events_url":"https://api.github.com/users/Anaconda-Server/events{/privacy}","received_events_url":"https://api.github.com/users/Anaconda-Server/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Anaconda-Server/anaconda-build","description":"Conda server build","fork":false,"url":"https://api.github.com/repos/Anaconda-Server/anaconda-build","forks_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/forks","keys_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/teams","hooks_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/hooks","issue_events_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/issues/events{/number}","events_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/events","assignees_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/assignees{/user}","branches_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/branches{/branch}","tags_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/tags","blobs_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/git/refs{/sha}","trees_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/statuses/{sha}","languages_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/languages","stargazers_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/stargazers","contributors_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/contributors","subscribers_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/subscribers","subscription_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/subscription","commits_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/commits{/sha}","git_commits_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/git/commits{/sha}","comments_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/comments{/number}","issue_comment_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/issues/comments{/number}","contents_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/contents/{+path}","compare_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/merges","archive_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/downloads","issues_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/issues{/number}","pulls_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls{/number}","milestones_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/milestones{/number}","notifications_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/labels{/name}","releases_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/releases{/id}","created_at":"2014-05-07T21:04:29Z","updated_at":"2015-09-10T20:13:19Z","pushed_at":"2015-09-17T20:30:40Z","git_url":"git://github.com/Anaconda-Server/anaconda-build.git","ssh_url":"git@github.com:Anaconda-Server/anaconda-build.git","clone_url":"https://github.com/Anaconda-Server/anaconda-build.git","svn_url":"https://github.com/Anaconda-Server/anaconda-build","homepage":"","size":1334,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":45,"forks":9,"open_issues":45,"watchers":3,"default_branch":"develop"}},"base":{"label":"Anaconda-Server:develop","ref":"develop","sha":"92e55c70c5c111001ce26329ca2aa9d9bd66ea0d","user":{"login":"Anaconda-Server","id":3571983,"avatar_url":"https://avatars.githubusercontent.com/u/3571983?v=3","gravatar_id":"","url":"https://api.github.com/users/Anaconda-Server","html_url":"https://github.com/Anaconda-Server","followers_url":"https://api.github.com/users/Anaconda-Server/followers","following_url":"https://api.github.com/users/Anaconda-Server/following{/other_user}","gists_url":"https://api.github.com/users/Anaconda-Server/gists{/gist_id}","starred_url":"https://api.github.com/users/Anaconda-Server/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Anaconda-Server/subscriptions","organizations_url":"https://api.github.com/users/Anaconda-Server/orgs","repos_url":"https://api.github.com/users/Anaconda-Server/repos","events_url":"https://api.github.com/users/Anaconda-Server/events{/privacy}","received_events_url":"https://api.github.com/users/Anaconda-Server/received_events","type":"Organization","site_admin":false},"repo":{"id":19550310,"name":"anaconda-build","full_name":"Anaconda-Server/anaconda-build","owner":{"login":"Anaconda-Server","id":3571983,"avatar_url":"https://avatars.githubusercontent.com/u/3571983?v=3","gravatar_id":"","url":"https://api.github.com/users/Anaconda-Server","html_url":"https://github.com/Anaconda-Server","followers_url":"https://api.github.com/users/Anaconda-Server/followers","following_url":"https://api.github.com/users/Anaconda-Server/following{/other_user}","gists_url":"https://api.github.com/users/Anaconda-Server/gists{/gist_id}","starred_url":"https://api.github.com/users/Anaconda-Server/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Anaconda-Server/subscriptions","organizations_url":"https://api.github.com/users/Anaconda-Server/orgs","repos_url":"https://api.github.com/users/Anaconda-Server/repos","events_url":"https://api.github.com/users/Anaconda-Server/events{/privacy}","received_events_url":"https://api.github.com/users/Anaconda-Server/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Anaconda-Server/anaconda-build","description":"Conda server build","fork":false,"url":"https://api.github.com/repos/Anaconda-Server/anaconda-build","forks_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/forks","keys_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/teams","hooks_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/hooks","issue_events_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/issues/events{/number}","events_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/events","assignees_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/assignees{/user}","branches_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/branches{/branch}","tags_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/tags","blobs_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/git/refs{/sha}","trees_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/statuses/{sha}","languages_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/languages","stargazers_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/stargazers","contributors_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/contributors","subscribers_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/subscribers","subscription_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/subscription","commits_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/commits{/sha}","git_commits_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/git/commits{/sha}","comments_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/comments{/number}","issue_comment_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/issues/comments{/number}","contents_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/contents/{+path}","compare_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/merges","archive_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/downloads","issues_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/issues{/number}","pulls_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls{/number}","milestones_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/milestones{/number}","notifications_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/labels{/name}","releases_url":"https://api.github.com/repos/Anaconda-Server/anaconda-build/releases{/id}","created_at":"2014-05-07T21:04:29Z","updated_at":"2015-09-10T20:13:19Z","pushed_at":"2015-09-17T20:30:40Z","git_url":"git://github.com/Anaconda-Server/anaconda-build.git","ssh_url":"git@github.com:Anaconda-Server/anaconda-build.git","clone_url":"https://github.com/Anaconda-Server/anaconda-build.git","svn_url":"https://github.com/Anaconda-Server/anaconda-build","homepage":"","size":1334,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":45,"forks":9,"open_issues":45,"watchers":3,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls/88"},"html":{"href":"https://github.com/Anaconda-Server/anaconda-build/pull/88"},"issue":{"href":"https://api.github.com/repos/Anaconda-Server/anaconda-build/issues/88"},"comments":{"href":"https://api.github.com/repos/Anaconda-Server/anaconda-build/issues/88/comments"},"review_comments":{"href":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls/88/comments"},"review_comment":{"href":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Anaconda-Server/anaconda-build/pulls/88/commits"},"statuses":{"href":"https://api.github.com/repos/Anaconda-Server/anaconda-build/statuses/bd2791ac73b1ce03e7e46619a869331a6e57ab7b"}}}}