官方有个介绍在 /etc/init/
目录下创建一个配置文件可以自动启动:
-bash-4.1# cat /etc/init/uwsgi.conf
description "uWSGI"
start on runlevel [2345]
stop on runlevel [06]
exec uwsgi --emperor /etc/uwsgi/vassals
但我发现,启动我Python的 os.environ 获取不到环境变量。但在终端手动启动是可以的:
-bash-4.1# uwsgi --emperor /etc/uwsgi/vassals
是不是 /etc/init/
里面的脚本启动的时候还没加载环境变量 ?
怎么写 /etc/init.d/
的启动uwsgi的脚本 ?
附测试程序
python
import os print 'user: ' + str(os.environ.get('USER')) def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return ['Hello World']
这个是必然的, 你在终端里当然是以你自己的身份为环境变量。
但是在init中是系统运行。 也就是说这个时候USER这个环境变量暂时还没有。