Linux registry service
Like mysql, ssh, we can use commands like service mysqld start to start, close, etc., so how do we manage our own programs in this way?
1. Enter /etc/init.d, and create a file xxxd whose content is as follows:
#!/bin/bash # chkconfig: - 90 10 # description: test service # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network RETVAL=0 # The logic executed when calling service xxxd start, generally here we call the startup script of our program with some necessary parameters to start our process, and then write the pid to the corresponding file start() { echo "started" } #Execute the logic executed when service xxxd stop, generally here we find the corresponding pid file, and then kill the corresponding process stop() { echo "stopped" } # See how we were called. case "$1" in start) start ;; stop) stop ;; restart|reload) stop start RETVAL=$? ;; condrestart|try-restart|force-reload) if [ -f /var/lock/subsys/$prog ]; then stop start RETVAL=$? be ;; status) echo "status" RETVAL=1 ;; *) echo $"Usage: $0 {start|stop|restart|try-restart|force-reload|status}" exit 1 esac exit $RETVAL
2. Execute the following commands in sequence
3. Available now
etc. command management service
Common usage of chkconfig: