{"action":"created","issue":{"url":"https://api.github.com/repos/joyent/containerpilot/issues/229","repository_url":"https://api.github.com/repos/joyent/containerpilot","labels_url":"https://api.github.com/repos/joyent/containerpilot/issues/229/labels{/name}","comments_url":"https://api.github.com/repos/joyent/containerpilot/issues/229/comments","events_url":"https://api.github.com/repos/joyent/containerpilot/issues/229/events","html_url":"https://github.com/joyent/containerpilot/issues/229","id":182637311,"number":229,"title":"CONTAINERPILOT_* environment variables for hook scripts","user":{"login":"jasonpincin","id":1831096,"avatar_url":"https://avatars.githubusercontent.com/u/1831096?v=3","gravatar_id":"","url":"https://api.github.com/users/jasonpincin","html_url":"https://github.com/jasonpincin","followers_url":"https://api.github.com/users/jasonpincin/followers","following_url":"https://api.github.com/users/jasonpincin/following{/other_user}","gists_url":"https://api.github.com/users/jasonpincin/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonpincin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonpincin/subscriptions","organizations_url":"https://api.github.com/users/jasonpincin/orgs","repos_url":"https://api.github.com/users/jasonpincin/repos","events_url":"https://api.github.com/users/jasonpincin/events{/privacy}","received_events_url":"https://api.github.com/users/jasonpincin/received_events","type":"User","site_admin":false},"labels":[{"id":483812995,"url":"https://api.github.com/repos/joyent/containerpilot/labels/2.x%20release","name":"2.x release","color":"f9d084","default":false},{"id":276636954,"url":"https://api.github.com/repos/joyent/containerpilot/labels/enhancement","name":"enhancement","color":"71b8c7","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-10-12T21:21:08Z","updated_at":"2016-11-18T18:53:50Z","closed_at":null,"body":"Proposing that ContainerPilot set certain environment variables (prefixed by CONTAINERPILOT_) that are accessible by all hook scripts, tasks, co-processes, and the \"main\" application process.. \n### List of environment variables\n- `CONTAINERPILOT_PID` - The PID of ContainerPilot itself, useful for signaling it to reload it's own config\n- `CONTAINERPILOT_APP_PID` - The PID of the primary application \n\nThat's all I have for now. There may be other valuable pieces of information now or later that can follow the same naming scheme. \n\nSee #232 for a related proposal.\n"},"comment":{"url":"https://api.github.com/repos/joyent/containerpilot/issues/comments/261611228","html_url":"https://github.com/joyent/containerpilot/issues/229#issuecomment-261611228","issue_url":"https://api.github.com/repos/joyent/containerpilot/issues/229","id":261611228,"user":{"login":"tgross","id":1409219,"avatar_url":"https://avatars.githubusercontent.com/u/1409219?v=3","gravatar_id":"","url":"https://api.github.com/users/tgross","html_url":"https://github.com/tgross","followers_url":"https://api.github.com/users/tgross/followers","following_url":"https://api.github.com/users/tgross/following{/other_user}","gists_url":"https://api.github.com/users/tgross/gists{/gist_id}","starred_url":"https://api.github.com/users/tgross/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tgross/subscriptions","organizations_url":"https://api.github.com/users/tgross/orgs","repos_url":"https://api.github.com/users/tgross/repos","events_url":"https://api.github.com/users/tgross/events{/privacy}","received_events_url":"https://api.github.com/users/tgross/received_events","type":"User","site_admin":false},"created_at":"2016-11-18T18:53:50Z","updated_at":"2016-11-18T18:53:50Z","body":"So looking into this a bit, getting the `CONTAINERPILOT_PID` into the environment will be trivial. We can do this right before we load the config via `os.Setenv(\"CONTAINERPILOT_PID\", os.Getpid())`\r\n\r\nGetting the `CONTAINERPILOT_APP_PID` is trickier though. Currently for the main app in `RunAndWait` we do a `exec.Cmd.Run()` which blocks until exit, so we don't have a way of getting at the process PID. We can change this to `exec.Cmd.Start()`, get the PID, and then do `exec.Cmd.Process.Wait()`. We do this in the pollables now, but its racy in terms of getting errors on the PID and Wait if the command exits quickly (i.e. it crashes). This should be less of a problem with the main app.\r\n\r\nWe also use this section for the other hooks that are running exclusively: `preStart`, `preStop`, and `postStop`. We could reduce special casing and also expose a `CONTAINERPILOT_PRESTART_PID`, `CONTAINERPILOT_PRESTOP_PID` and `CONTAINERPILOT_POSTSTOP_PID` variable if we construct the env var name from the name of whatever `Command` struct we're running.\r\n\r\n"}}
{"actor":{"display_login":"tgross"}}