3

I'm executing a script on Ubuntu 14.04.1 LTS when the server is stopping But I would like to execute it only on shutdown behavior, not whendoing a reboot.

I tried to get the value with $1but for reboot or shutdown, but it always sending a stop message

The script I'm currently running:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          shutdown
# Required-Start:    
# Required-Stop:     sendsigs
# Default-Start:
# Default-Stop:      0 6
# Short-Description: shutdown
# Description: 
### END INIT INFO

shutdown_script.sh

exit 0

And run by sudo update-rc.d shutdown_job start 19 0 6 .

leo
  • 33

1 Answers1

3

Try putting the script in different runlevels.

/etc/rc0.d - While system shuts down.

/etc/rcS.d - While system boots

/etc/rc1.d - Working as singel user (user specific on login)

/etc/rc2.d - Working as multiple users

/etc/rc3.d bis /etc/rc5.d - not used in ubuntu

/etc/rc6.d - While system restarts
FRED99
  • 109
  • How to distinguish between shutdown and shutdown + reboot? – A.B. Jul 24 '15 at 15:55
  • shutdown -h will be runlevel 0. shutdown -r will be runlevel 6. There's no "shutdown + reboot"; a shutdown ends with the system halted, a restart results in the system rebooting. – roadmr Jul 24 '15 at 17:46
  • 1
    Thank you for your detailed explication! It works perfectly only in rc0.d

    sudo update-rc.d -f shutdown_job remove sudo update-rc.d shutdown_job start 19 0 .

    – leo Jul 28 '15 at 00:26