写python程序最佳实践_Python后台程序打包最佳实践

我发现帮助处理init.d脚本的最好工具是“start-stop-daemon”。它将运行任何应用程序,监视run/pid文件,在必要时创建它们,提供停止守护进程的方法,设置进程用户/组id,甚至可以设置进程的后台。

例如,这是一个可以启动/停止wsgi服务器的脚本:#! /bin/bash

case "$1" in

start)

echo "Starting server"

# Activate the virtual environment

. /home/ali/wer-gcms/g-env/bin/activate

# Run start-stop-daemon, the $DAEMON variable contains the path to the

# application to run

start-stop-daemon --start --pidfile $WSGI_PIDFILE \

--user www-data --group www-data \

--chuid www-data \

--exec "$DAEMON"

;;

stop)

echo "Stopping WSGI Application"

# Start-stop daemon can also stop the application by sending sig 15

# (configurable) to the process id contained in the run/pid file

start-stop-daemon --stop --pidfile $WSGI_PIDFILE --verbose

;;

*)

# Refuse to do other stuff

echo "Usage: /etc/init.d/wsgi-application.sh {start|stop}"

exit 1

;;

esac

exit 0

您还可以看到一个如何将它与virtualenv一起使用的示例,我将一直推荐这个示例。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值