官方有个介绍在/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']
This is inevitable. Of course, you use your own identity as the environment variable in the terminal.
But the system runs in init. In other words, the USER environment variable does not exist yet at this time.
Recommended to use supervisor
Thank you, I also wrote a script, share it:
http://www.zhaoyanan.cn/uwsgi...