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.
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):