I want to run script on server shutdown. It's a KVM host and I want to shutdown my VMs. How much time will system wait for my script to exit? Indefinitely?


You have as much time as you want as it depends on how you're shutting it down and how you run your script.

You could setup your shutdown process to block on your script, then you have as much time as your want. It won't continue shutting down until your script exits.

Then there is setup's like Knoppix which send a TERM then a KILL to all processes pretty quickly during shutdown. So you'd have almost no time for your script.

  • TERM can be caught and handled. – Dennis Williamson Feb 19 '11 at 19:09
  • Yes, but then it does SIGKILL a second later; I'll update my post. – Steven Feb 19 '11 at 22:03

Depends on the version init programs. For sysvinit(System V style init programs) and upstart(riginally developed for the Ubuntu distribution) no time limit. Sometimes use killall5 to shutdown(shutdown script don't run).

Also, you can set kill timeout(time to wait between sending TERM and KILL signals) in upstart(in /etc/init):

kill timeout 180

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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