Example LINUX init Script
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.d these days.
This script is chkconfig compatible, so call it the name of your new service and put it in /etc/init.d
The chkconfig: 235 section indicates the the default runlevels. For instance, if we called this script /etc/init.d/new-service and ran chkconfig new-service on, it would be active in runlevels 2,3 and 5.
The 98 and 55 numbers indicate the order of startup and kill. This means that using this tag, the startup symbolic link would be named S98new-service and the symbolic link to kill the process would be named K55new-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 1
esac
exit 0
#### /SNIP ####
Obviously change all instances of “new-service” to the name of your actual service… Enjoy!
Discuss This Article
Post Tags (user submitted): t (921) - Linux Startup Script (260) - centos init (86) - linux service script (54) - f (48) - startup script Linux (47) - linux script (41) - su examples (36) - chkconfig +init (35) - rhel startup script (35) - su example (35) - linux script example (31) - sample init script (30) - centos startup (26) - script linux (24) - centos startup script (23) - foreach linux (23) - linux boot script (22) - linux init (21) - centos init script (21) - init script example (20) - bash init script (20) - linux script su (20) - rhel init script (19) - centos startup scripts (19) - init script chkconfig (19) - linux script examples (19) - linux su example (18) - linux startup scripts (18) - chkconfig init script (17) - init script tutorial (16) - linux foreach (16) - sample linux script (16) - centos create init script (16) - rhel startup scripts (16) - centos add service (16) - centos startup script (16) - mss (15) - linux init script (15) - linux foreach example (15) - linux start script (15) - linux user startup script (14) - linux startup script howto (14) - init.d tutorial (14) - linux startup script example (14) - linux init script example (14) - start script linux (14) - linux script foreach (13) - RHEL init scripts (13) - linux run script as other user (13) - centos init script template (13) - chkconfig scripts (12) - chkconfig script (12) - chkconfig script example (12) - linux run script (12) - linux execute script (12) - centos init scripts (11) - linux add new service (11) - startup script in linux (11) - chkconfig startup script (11) - init script howto (11) - linux script location (11) - init d script template (11) - init centos (11) - chkconfig init (11) - chkconfig examples (10) - init chkconfig (10) - linux run script as user (10) - example-linux-init-script (10) - linux scripts examples (10) - centos create service (10) - scrip linux (10) - init script linux (10) - named init script (10) - linux script sample (10) - centos init d script (10) - all (9) - linux init scripts (9) - script linux example (9) - linux scrip (9) - bash script examples (9) - sample Linux startup script (9) - run script linux (9) - Linux Scripting examples (9) - linux INIT.D (8) - linux initscript (8) - example init script (8) - foreach linux script (8) - centos create startup script (8) - centos init script howto (8) - startup script centos (8) - bash script example (8) - create chkconfig script (8) - sample linux scripts (8) - startup scripts linux (8) - linux init d (8) - service (7) - chkconfig example (7) - simple linux startup script (7) - linux startup script path (7) - linux runscript (7) - centos add startup script (7) - linux service startup script (7) - linux startup script chkconfig (7) - linux service scripts (7) - create startup script linux (7) - spiralbound net (7) - startup script example (7) - #! script linux centos (7) - execute script linux (7) - linux script comment ## (7) - service script linux (7) - init script template (7) - chkconfig tutorial (6) - chkconfig script howto (6) - how to create a linux startup script (6) - centos run script at boot (6) - bash startup script (6) - create linux service (6) - startup script + chkconfig (6) - bash init scripts (6) - example linux script (6) - rhel init script template (6) - linux script user (6) - foreach linux example (6) - create chkconfig (6) - init d script example (6) - add new service in linux (6) - su linux script (6) - writing init script centOS (6) - chkconfig init scripts (5) - linux creating init script (5) - linux startup script add (5) - linux init path (5) - startup script on linux (5) - foreach example linux (5) - chkconfig --levels 235 (5) - linux restart service script (5) - chkconfig compatible script (5) - bash daemon script (5) - script start service linux (5) - creating a script in linux (5) - "writing" "linux" "startup" "script" (5) - init script user (5) - su linux example (5) - linux add service (5) - "init 6 linux" (5) - run script in linux (5) - init script centos (5) - linux script comments (5) -