/dev/null 2>&1 &echo 'dreamtech service OK'}stop(){serverpid=`ps -aux|grep "$f..._linux 将python文件的启动写入service中">
赞
踩
1.新建dreamtech.sh脚本文件:
#!/bin/bash
filepath="/home/OPERATE/start.pyc"
start(){
nohup python3 $filepath>/dev/null 2>&1 &
echo 'dreamtech service OK'
}
stop(){
serverpid=`ps -aux|grep "$filepath"|grep -v grep|awk '{print $2}'`
kill -9 $serverpid
echo 'dreamtech stop OK'
}
restart(){
stop
echo 'dreamtech stop OK'
start
echo 'dreamtech service OK'
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
start
esac
2.给脚本添加可执行权限:
sudo chmod +x dreamtech.sh
3.将脚本复制到init.d文件夹下,这个目录里放系统脚本文件 :
cp dreamtech.sh /etc/init.d
4.将dreamtech.sh添加到系统服务清单内 :
cp /etc/init.d
update-rc.d dreamtech.sh defaults 90 # 这里90表明一个优先级,越高表示执行的越晚
5. 验证是否添加成功:
sudo service --status-all
输入以上命令查看dreamtech.sh是否在系统服务清单内。
最后重启验证Python脚本是否随系统启动而启动!
6.如果想删除该服务:
sudo update-rc.d dreamtech.sh remove
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。