Question

Is there a way to get supervisor to really launch in the context of a user?

The environment variables for the running process seem connected to root, even though I set the user. I went ahead and set some of the environment variables, but I effectively want the process to run as if I ran su - username beforehand.

This is part of the ipynb-cookbook, an effort to setup and configure the IPython Notebook in automation (complete with profile buildout).

This is the chef setup I'm using:

# Setup an IPython notebook service
supervisor_service node[:ipynb][:service_name] do
    user node[:ipynb][:linux_user]
    directory node[:ipynb][:home_dir]

    # IPython notebook should have access to the shell
    environment "HOME" => node[:ipynb][:home_dir],
                "SHELL" => "/bin/bash",
                "USER" => node[:ipynb][:linux_user],
                "PATH" => "#{node[:ipynb][:virtenv]}/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games",
                "VIRTUAL_ENV" => "#{node[:ipynb][:virtenv]}"

    # Make the path for the service be the virtualenvironment
    #environment "PATH" => (File.join(node[:ipynb][:virtenv], "bin") + ":$PATH")
    action :enable
    autostart true
    autorestart true

    # Start up the IPython notebook as a service
    command "#{node[:ipynb][:virtenv]}/bin/ipython notebook --profile=#{node[:ipynb][:profile_name]}"
    stopsignal "QUIT"
end

Which results in this /etc/supervisor.d/ipynb.conf

[program:ipynb]
command=/home/ipynb/ipyvirt/bin/ipython notebook --profile=cooked
process_name=%(program_name)s
numprocs=1
numprocs_start=0
autostart=true
autorestart=true
startsecs=1
startretries=3
exitcodes=0,2
stopsignal=QUIT
stopwaitsecs=10
user=ipynb
redirect_stderr=false
stdout_logfile=AUTO
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
stdout_capture_maxbytes=0
stdout_events_enabled=false
stderr_logfile=AUTO
stderr_logfile_maxbytes=50MB
stderr_logfile_backups=10
stderr_capture_maxbytes=0
stderr_events_enabled=false
environment=HOME="/home/ipynb",SHELL="/bin/bash",USER="ipynb",PATH="/home/ipynb/ipyvirt/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games",VIRTUAL_ENV="/home/ipynb/ipyvirt"
directory=/home/ipynb
serverurl=AUTO

When inspecting the environment variables, this is what I see:

{'CLICOLOR': '1',
 'GIT_PAGER': 'cat',
 'HOME': '/home/ipynb',
 'LANG': 'en_US.UTF-8',
 'LANGUAGE': 'en_US:',
 'LC_ALL': 'C',
 'LOGNAME': 'root',
 'MAIL': '/var/mail/root',
 'PAGER': 'cat',
 'PATH': '/home/ipynb/ipyvirt/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games',
 'PWD': '/',
 'SHELL': '/bin/bash',
 'SHLVL': '1',
 'SUDO_COMMAND': '/bin/bash -l',
 'SUDO_GID': '900',
 'SUDO_UID': '900',
 'SUDO_USER': 'vagrant',
 'SUPERVISOR_ENABLED': '1',
 'SUPERVISOR_GROUP_NAME': 'ipynb',
 'SUPERVISOR_PROCESS_NAME': 'ipynb',
 'SUPERVISOR_SERVER_URL': 'unix:///var/run/supervisor.sock',
 'TERM': 'xterm-color',
 'USER': 'ipynb',
 'USERNAME': 'root',
 'VIRTUAL_ENV': '/home/ipynb/ipyvirt',
 '_': '/usr/bin/chef-solo'}
Was it helpful?

Solution

Environment variables for a given user are set by shell configuration files, something that Supervisor will not do for you.

If you rely on certain environment variables to be set, set those in your configuration for that process instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top