Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Which is the best way to run a script upon server restart and when server is up again?

e.g. When services will be unavailable:

irc_notify "Server is going down"

when all services are available:

irc_notify "Server is up again"

Server shutdown may be triggered by various scripts, so I don't want to use shutdown command with parameters.

share|improve this question
up vote 1 down vote accepted

Create a script in /etc/init.d, make it executable, then check how to execute it on the different runlevels


You probably are interested in runlevel 0 (shutdown) and 3 or 5 (normal runlevel after the startup)

share|improve this answer

Create the following script /etc/init.d/irc_notify

# Provides:          irc_notifications
# Required-Start:    $network
# Required-Stop:
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: IRC Notifications
# Description:       Simple script to send notifications to IRC
case "$1" in
       irc_notify "Server is up again"
       irc_notify "Server is going down"

Once that is done run (for CentOS/RHEL) chkconfig add irc_notify && chkconfig irc_notify on or (for debian/ubuntu) update-rc.d irc_notify start 3 5 stop 0 1 2 6

share|improve this answer
looks like the right command for Ubuntu needs dots: update-rc.d irc_notify start 3 5 . stop 0 1 2 6 ., but I still get the warnings and the messages do not show. – takeshin Sep 29 '10 at 12:39

Initscript for various runlevels, not crontab

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.