Server-side development often writes scripts that run in the background, which are troublesome when restarting and starting. Often nohup python xxx&, ps -ef|grep xxx and then kill. Use the following shell script to achieve a simple start and stop method to increase development efficiency.
Just modify startcmd and filename:
For example, save it as startup.sh
startcmd="php control.php"
filename="control.php"
op=$1
[ -z "$op" ] && op=start
start(){
nohup $startcmd >> logs/$filename.log 2>&1 &
}
stop(){
pid=`ps -ef|grep $filename|grep -v "grep" |head -n1|awk '{print $2}'`
kill -9 $pid
printf "pid %s is killed.\n" $pid
}
case $op in
start)
echo "Starting Now......"
start
echo "Starting Finished"
;;
stop)
echo "Stopping Now......"
stop
echo "Stopping Finished"
;;
restart)
echo "Restart Now......"
stop
start
echo "Restart Finished"
;;
*)
esac
启动 startup.sh start
停止 startup.sh stop
重启 startup.sh restart
{{o.name}}
{{m.name}}