[root@localhost ~]# chkconfig --list sipdev_linux
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
sipdev_linux 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost ~]# service sipdev_linux status
status sipdev_linux is running. Pid is 18242
[root@localhost ~]# service sipdev_linux stop
[root@localhost ~]# service sipdev_linux start
start sipdev_linux start success
[root@localhost ~]# service sipdev_linux restart
start sipdev_linux start success
[root@localhost ~]# service sipdev_linux status
status sipdev_linux is running. Pid is 26782
[root@localhost ~]# systemctl list-unit-files|grep sipdev_linux
sipdev_linux.service enabled
[root@localhost ~]#
[b]service腳本如下:
[Unit]
Description=sipdev_linux
After=sipdev_linux.target
[Service]
Type=forking
ExecStart=/etc/init.d/sipdev_linux start
ExecStop=/etc/init.d/sipdev_linux stop
ExecStartPost=/etc/init.d/sipdev_linux status
ExecReload=/etc/init.d/sipdev_linux restart
PrivateTmp=true
#RemainAfterExit=yes
#想要的多用戶目標
[Install]
WantedBy=multi-user.target
~
~
~
sipdev_linux腳本內容如下:
#!/bin/sh
# chkconfig: 2345 65 66
# description: Self Monitoring and Reporting Technology (SMART) Daemon
# openresty - this script starts and stops the sipdev_linux sipdec_start
#
#開啟sipdev_linux服務
#[ -f /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions
#定義一些用戶變數
APP_HOME=/home/sipdev_new20210302 #程式主目錄
APP_NAME=sipdev_linux #程式(腳本目錄)
LOG_FILE=siplog.txt #輸出日志檔案
#使用說明,用來提示輸入引數
usage() {
echo "Usage: sh sipdev_linux [start|stop|restart|status]"
exit 1
}
#檢查程式是否在運行
is_exist(){
#pid=`pgrep -l -o $APP_NAME|awk '{print $1}'`
#pid=`ps -ef|grep "$APP_NAME"|grep -v grep|awk '{print $2}'`
pid=`ps -x|grep "$APP_NAME"|grep 'sipdev_linux$' |grep -v grep |awk '{print $1}'`
#如果不存在回傳0,存在回傳1
if [ -z "$pid" ]; then
return 0
else
return 1
fi
}
#啟動
start(){
is_exist
if [ $? -eq 1 ]; then
echo "start ${APP_NAME} is already running. pid=${pid} ."
else
cd $APP_HOME;nohup $APP_HOME/$APP_NAME 2>/dev/null &
echo "start ${APP_NAME} start success"
fi
}
#停止
stop(){
is_exist
if [ $? -eq 1 ]; then
kill -9 $pid
else
echo "stop ${APP_NAME} is not running"
fi
}
#輸出運行狀態
status(){
is_exist
if [ $? -eq 1 ]; then
echo "status ${APP_NAME} is running. Pid is ${pid}"
else
echo "status ${APP_NAME} is NOT running."
fi
}
#重啟
restart(){
stop
start
}
#根據輸入引數,選擇執行對應方法,不輸入則顯示使用說明
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/266519.html
標籤:專題技術討論區
