#! /lkddy/bash server_name="hello"server_path=/home/songchao/dnschool/05shell/hellostart(){ echo "--start-" ($server_path) & pid=$(ps -ef|grep $server_name |grep -v grep |awk '{print $2}') if [ ! $pid ]; then echo "service is not exit ..." else echo "pid=$pid" fi }stop(){ pid=$(ps -ef|grep $server_name |grep -v grep |awk '{print $2}') if [ ! $pid ]; then echo "service is not exit ..." else kill -9 $pid fi }checkrun(){ while true do pid=$(ps -ef|grep $server_name |grep -v grep |awk '{print $2}') if [[ $pid -eq 0 ]]; then echo "--restart-" start fi sleep 30s done} case $1 instart): start ;;stop): echo "--stop" echo $pid stop ;;checkrun): echo "--restart" checkrun ;;*): echo "error ..." ;;esacexit 0
以上是一个测试用例,找一个linux程序用shell 来管理起来生命周期,现在用python 管理的比较多,简单方便约阅读一些,我公司就是用python 哈哈哈 ;
74108983