Home > OS >  To join centos7 service service in the boot from the script, use command to see no problem but canno
To join centos7 service service in the boot from the script, use command to see no problem but canno

Time:03-06

/root @ localhost ~ # the chkconfig -- list sipdev_linux

Note: This output shows SysV services only and does not include native
Systemd services. SysV configuration data took a be overridden by native
Systemd configuration.

If you want to list systemd services use 'systemctl list - unit - files'.
To see the services enabled on particular target use
'systemctl list - dependencies (target)'.

Sipdev_linux 0: off 1:2: off on 3: on 4: on 5: on 6: off
/root @ localhost ~ # service sipdev_linux status
The status sipdev_linux is running. The 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
The status sipdev_linux is running. The Pid is 26782
/root @ localhost ~ # systemctl list - unit - files | grep sipdev_linux
Sipdev_linux. Service enabled
/root @ localhost ~ #

[b] the service script is as follows:

[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
# want more user goals
[Install]
WantedBy=multi - user. Target
~
~
~

Sipdev_linux script content is as follows:
#!/bin/sh
# the chkconfig: 2345 65 66
# description: Self Monitoring and Reporting Technology (SMART) Daemon
# openresty - this script starts and stops the sipdev_linux sipdec_start
#
# open sipdev_linux service


# [-f/etc/rc. D/init. D/functions provides] & amp; & ./etc/rc. D/init. D/functions provides
# define some user variable
APP_HOME=/home/home directory sipdev_new20210302 # program
APP_NAME=sipdev_linux # program (scripts directory)
# LOG_FILE=siplog. TXT output log file

# instructions, used to prompt the input parameter
The usage () {
Echo "Usage: sh sipdev_linux [start | stop | restart | status]"
The exit 1
}

# to check whether the program is running
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} '`
# if there is no return 0, existence return 1
If [-z "$pid"]; Then
Return 0
The else
Return 1
Fi
}

# start
Start () {
Is_exist
If [$? - eq 1); Then
Echo "start at ${APP_NAME} is already running. The pid=${pid}."
The else
CD $APP_HOME; Nohup $$APP_NAME APP_HOME/2 & gt;/dev/null & amp;
Start success "echo" start at ${APP_NAME}
Fi
}

# stop
Stop () {
Is_exist
If [$? - eq 1); Then
Kill 9 $pid
The else
Echo "stop ${APP_NAME} is not running"
Fi
}

# the running state of the output
The status () {
Is_exist
If [$? - eq 1); Then
Echo "${APP_NAME} is running status. The Pid is ${Pid}"
The else
Echo "${APP_NAME} is NOT running status."
Fi
}

# restart
Restart () {
Stop
Start
}

# according to the input parameters, choose to perform the corresponding methods, no input, according to the instructions
Case "$1" in
"Start")
Start
;;
"Stop")
Stop
;;
"Status")
The status
;;
"Restart")
Restart
;;
*)
The usage
;;
Esac