Manually add CentOS self-starting service
1. write scripts and modify execution permissions.
Vim myservice. sh, chmod + x myservice. sh
#! /Bin/bash
Case "$1" in
Start)
Echo "Starting myservice ...";;
Stop)
Echo "Shutting down myservice ...";;
Restart)
Echo "Shutting down myservice ..."
Echo "Starting myservice ...";;
*)
Echo "Usage: #0 {start | stop | restart }";;
Esac
2. Put the script (remove the. sh suffix) in the/etc/init. d/directory.
Cp/tmp/myservice. sh/etc/init. d/myservice
3. Run the/etc/init. d/myservice service.
/Etc/init. d/myservice start | stop | restart
4. Use chkconfig -- add to add the service to be started. No myservice is found.
Chkconfig -- add myservice
System prompt: service myservice does not support chkconfig
5. View help, man chkconfig,/example
The script format of the service is as follows:
# Chkconfig: startup level startup sequence SXX close sequence KXX
# Description: description
Vim/etc/init. d/myservice, add the Code:
# Chkconfig: 35 24 25
# Description: this is a test
6. Add the system boot Auto Start Service
Chkconfig -- add myservice
Chkconfig -- list myservice
Myservice 0: off 1: off 2: off 3: on 4: off 5: on 6: off
Start myservice when the startup level is 3 or 5.
7. view the added Service
Ls/etc/rc. d/rc *. d/* myservice, you can see:
/Etc/rc. d/rc0.d/K25myservice/etc/rc. d/rc4.d/K25myservice
/Etc/rc. d/rc1.d/K25myservice/etc/rc. d/rc5.d/S24myservice
/Etc/rc. d/rc2.d/K25myservice/etc/rc. d/rc6.d/K25myservice
/Etc/rc. d/rc3.d/S24myservice