python - 求一个uwsgi自动启动的脚本
ringa_lee
ringa_lee 2017-04-17 14:23:46
0
3
329

官方有个介绍在/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的脚本 ?


附测试程序

pythonimport os print 'user: ' + str(os.environ.get('USER')) def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return ['Hello World']
ringa_lee
ringa_lee

ringa_lee

reply all (3)
黄舟

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...

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!