Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have the following script, how do I run it on shutdown in debian linux? (don't want to use GUI)

#!/bin/bash
vms=$(vmrun list | grep '/');
for vm in ${vms}
do
        echo 'suspending ' $vm
        vmrun suspend $vm soft
done

I tried adding it to /usr/local/bin with chmod +x permissions. Then I created symbolic links to rc0.d (shutdown) and rc6.d (reboot).

I then did update-rc.d shutdown_vms 0 6 .

When I do shutdown -r now, it switches to console mode to restart....at that point I can see a error message stating shutdown_vms has failed.

I this the proper way to install the shutdown script and why is it failing (where do I look in the logs?)

Edit: I used the command update-rc.d -f shutdown_vms start 0 0 6 .

When I look at the start up list for rc0.d (shutdown), i see that both shutdown_vms, vmware, and gdm are all order of 0. I think if gdm fires before shutdown_vms, it will kill the vms. I think this is what's happening because when I log the number of vms running when the script executes, it logs 0.

Can I change the order of gdm/vmware to 1 so that shutdown_vms run first?

share|improve this question

4 Answers 4

This looks like you should put it into a proper init-script as "stop" method. Your current script propably fails, because of an exit-code that is not equal to zero.

Apart from that you should enclose "$()" because your list of vms propably contains white space.

Test your script by sh -x YOURSCRIPT stop.

share|improve this answer
    
Running that outputs: + vmrun list + grep / + vms= + exit 0 –  firebird Dec 30 '11 at 23:52

try adding: exit 0 under done.

so it looks like gdm does this during the shutdown process. maybe a better way is that you let your vms script test if it really is necessary to go through the shutdown procedure. In that case it does nothing to shutdown a non-existent process. This non-existent process probably caused your error message.

share|improve this answer
    
Did that, didn't work. Is there anyway to know whether the script failed (some kind of log stored in var)? I ran the script manually and it runs fine –  firebird Dec 30 '11 at 23:54

Have you named the file starting with a 'K' in the /etc/rc[06].d directories? If you don't then they will not be executed on shutdown.

share|improve this answer
    
I used update-rc.d -f shutdown_vms start 99 0 6 . which automaticaly puts K01shutdown_vms in /etc/rc0.d and /etc/rc6.d, it still doesn't work –  firebird Dec 30 '11 at 23:53
    
I presume it works when you run it NOT in a shutdown scanario but NOT when in /etc/rc.d directories? –  mdpc Jan 3 '12 at 5:42

Hmmmm...It would be nice if the failure output could be shown. This would likely easily clearup some things.

One other thought, try putting in a PATH statement right after #!/bin/sh.

 #! /bin/sh
 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:.....<anything else you need>
 export PATH
 .
 .   (rest of script)
 .
 exit 0

I'm not familiar with vmlist.

share|improve this answer

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.