0

有没有办法让主管真正在用户的上下文中启动?

即使我设置了用户,运行进程的环境变量似乎也连接到 root。我继续设置了一些环境变量,但我实际上希望进程像su - username事先运行一样运行。

这是ipynb-cookbook的一部分,旨在自动设置和配置 IPython Notebook(完成配置文件构建)。

这是我正在使用的厨师设置:

# 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

这导致了这个 /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

检查环境变量时,我看到的是:

{'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'}
4

1 回答 1

1

给定用户的环境变量由 shell 配置文件设置,Supervisor 不会为你做这件事。

如果您依赖于设置某些环境变量,请在您的配置中为该进程设置这些变量。

于 2013-08-07T14:58:06.327 回答