To add a service to linux:
1. Write a service script named testService.
Start () {echo "start testService"/usr/local/bin/testService & # executable file path exit 0;} stop () {echo-n "stop testService" if pkill testService then echo "[OK]" else echo "[failed]" fi} case "$1" instart) start; stop) stop; restart) stop start; *) echo "usage: $0 start | stop | restart" exit 0; esac
Second, copy the testService file to the/etc/init. d/directory.
Third, you can execute service testService start (stop, restart) to operate the file.
But today, we have a depressing opinion,
First, check whether the file exists in the/usr/init. d/directory.
Second, execute service testService start and report an error. The service is not recognized,
Third: Check whether the script file is correct. If it is true, it can be executed by other services.
Check the permissions of/usr/init. d/testServic, as follows:
[Root @ ~] # Service testService startuapd: unrecognized service [root @ ~] # Ll/etc/init. d/testService # Check permissions ---------- 1 root 1025 08-30/etc/init. d/testService # file permissions [root @ ~] # [Root @ ~] # Chmod 033/etc/init. d/testService # Set file permissions [root @ ~] # Service uapd startstart testService [OK] [root @ ~] #
Solution:
1. Check the permissions of the file. Even if the file is in the/etc/init. d/testService directory, the service is still unavailable.
2. After the File Permission is set, the service can recognize it normally.