Example LINUX init Script

來源:互聯網
上載者:User

標籤:existing   complex   another   service   decided   

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

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

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

The98and55numbers indicate the order of startup and kill. This means that using this tag, the startup symbolic link would be 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 you are controlling with the chkconfig command###case "$1" in  start)        echo -n "Starting new-service"        #To run it as root:        /path/to/command/to/start/new-service        #Or to run it as some other user:        /bin/su - username -c /path/to/command/to/start/new-service        echo "."        ;;  stop)        echo -n "Stopping new-service"        #To run it as root:        /path/to/command/to/stop/new-service        #Or to run it as some other user:        /bin/su - username -c /path/to/command/to/stop/new-service        echo "."        ;;  *)        echo "Usage: /sbin/service new-service {start|stop}"        exit 1esacexit 0


本文出自 “小小鳥你媽” 部落格,請務必保留此出處http://xiaoxiaoniao.blog.51cto.com/8727225/1409567

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.