让python的程序在ubuntu下以服务运行

在/etc/init.d/下创建一个脚本.

在/etc/init.d/下创建一个脚本snsserver.sh,内容如下:


#! /bin/sh
do_start()
{
python /home/nick/workspace/snsApp/src/run.py
}
do_stop()
{
killall python
}

case "$1" in
start)
do_start
;;
stop)
do_stop
;;
*)
echo "useage:snsserver {start|stop}"
exit 1
;;
esac

exit 0

然后sudo update-rc.d snsserver.sh defaults

这样就设置好新增的服务程序了,以后只要sudo /etc/init.d/snsserver.sh start|stop 就可以了

以上只是最简单的例子,实际使用要根据具体情况修改了。