Example LINUX Init Script

Source: Internet
Author: User

From time to time, the people want me to the Create LINUX init scripts for them. I usually just take a existing one for another service and the change it up to work for my new application, but the most of them has become so long these days that I end up has to hack out a ton of code just to reduce them down to the very basic s Cript I need. I decided to create this very simple template so I wouldn ' t has to keep trimming down the more complex scripts that one T Ends to find in/etc/init.dThese days.

This waschkconfigcompatible, so call it the name of the your new service and put it in/etc/init.d

Thechkconfig: 235section indicates the default runlevels. For instance, if we called this script/etc/init.d/new-serviceand ranchkconfig new-service on, it would is active in runlevels 2,3 and 5.

The98and55Numbers indicate the order of startup and kill. This means. Using this tag, the startup symbolic Link would is namedS98new-serviceAnd the symbolic link to kill the process would be namedK55new-service.

# # # # SNIP # #

#! /bin/sh# Basic support for IRIX style chkconfig#### chkconfig:235 98 55# description:manages the Services is contro Lling with the Chkconfig command## #case "$" in  start)        echo-n "Starting New-service" &NB Sp       #To run it as root:        /path/to/command/to/start/new-service     &NB Sp   #Or to run it as some other user:        /BIN/SU-USERNAME-C/path/to/command/to/start/new-ser Vice        echo "."        ;;  stop)        echo-n "stopping New-service"         #To run it as root: &nbsp ;      /path/to/command/to/stop/new-service         #Or to run it as some other user: &nbs P      /BIN/SU-USERNAME-C/path/to/command/to/stop/new-service        echo "."        ;;  *)        echo "Usage:/sbin/service new-service {start|stop}"        exit 1esacexit 0 


This article is from the "Little Bird Your Mother" blog, please make sure to keep this source http://xiaoxiaoniao.blog.51cto.com/8727225/1409567

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.