Manually add CentOS self-starting service

Source: Internet
Author: User
1. write a script and modify the execution permission vimmyservice. sh, chmod + xmyservice. sh #! /Bin/bashcase & quot; $1 & quot; instart) echo & quot; S 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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.