版权声明:这里将不定期发布一些技术上分享,如对文章有任何意见或者建议,欢迎评论,转载请注明出处。 https://blog.csdn.net/goal_ff/article/details/89874393
说明:以程序名yf_station_service为例编写。
1.启动
#!/bin/sh
BIN_DIR=/home/gitlab/yf_station_service/bin
$(BIN_DIR)/yf_station_service &
SERV_PID=`ps -ef |grep yf_station_service |grep -v grep |awk '{print $2}'`
if [ ! -n "$SERV_PID" ]; then
echo "service start failed !"
else
echo "service start success !"
fi
2.停止
#!/bin/sh
SERV_PID=`ps -ef |grep yf_station_service |grep -v grep |awk '{print $2}'`
if [ ! -n "$SERV_PID" ]; then
echo "service not exists !"
else
kill -9 ${SERV_PID} > /dev/null 2>&1
SERV_PID=`ps -ef |grep yf_station_service |grep -v grep |awk '{print $2}'`
if [ ! -n "$SERV_PID" ]; then
echo "service have stoped !"
else
echo "cannot stop service !"
fi
fi
3.查看状态
#!/bin/sh
SERV_PID=`ps -ef |grep yf_station_service |grep -v grep |awk '{print $2}'`
if [ ! -n "$SERV_PID" ]; then
echo "service not exist !"
else
echo "service is running !"
fi