Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to run a script file when the system is called for shutdown/ reboot from 'reboot' and 'shutdown' commands. And if possible, also hard shutdowns like 'init 0' or 'poweroff'. How would I go about doing that? A config file or command would be nice. I use systemd instead of initscripts.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Just copy / link the script into your /etc/init.d/rc0.d (HALT) and /etc/init.d/rc6.d (reboot) directories, and make sure it's name is prefixed with: "K20"

FYI: http://www.linux.com/news/enterprise/systems-management/8116-an-introduction-to-services-runlevels-and-rcd-scripts

share|improve this answer
    
I use systemd instead of initscripts. Know a different way to do that without using initscripts? Sorry that wasnt in my post –  wolfo9999 Jan 18 '13 at 16:42
    
The How Do I Convert A SysV Init Script Into A systemd Service File? page explains the basics, just add the appropriate WantedBy= targets to your service file e.g. [Install] WantedBy=final.target / halt.target / shutdown.target –  arober11 Jan 19 '13 at 7:18
    
For examples see: archlinux - systemd/Services –  arober11 Jan 19 '13 at 7:25
    
Thanks! That guide helped alot! –  wolfo9999 Jan 19 '13 at 16:15
add comment

Your Answer

 
discard

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.