2013年12月1日 星期日

Init script

Debian uses a Sys-V like init system for executing shell scripts when the system runlevel changes. How to do?

  • /etc/init.d/xxx (xxx : your init script)
  • update-rc xxx
 
Adding symbolic links to cause the script to be executed when the system goes down, or comes up.

The example of script executed as init.
  • The script is just a  shell script with  'Switch case ' statement.
..................................................................................................................
#! /bin/sh
# /etc/init.d/blah
#

# Some things that run always
touch /var/lock/blah

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script blah "
    echo "Could do more here"
    ;;
  stop)
    echo "Stopping script blah"
    echo "Could do more here"
    ;; 

  restart|reload)
    $0 stop
    sleep 3
    $0 start
  ;;

  *)
    echo "Usage: /etc/init.d/blah {start|stop}"
    exit 1
    ;;
esac

exit 0
................................................................................... 

reference:
  1. http://www.debian-administration.org/articles/28

沒有留言:

張貼留言