Run script before shutdown/restart
        Posted  
        
            by 
                dtbarne
            
        on Server Fault
        
        See other posts from Server Fault
        
            or by dtbarne
        
        
        
        Published on 2011-11-19T00:21:19Z
        Indexed on 
            2011/11/19
            1:54 UTC
        
        
        Read the original article
        Hit count: 632
        
I'd like to run a PHP script when an instance is told to shutdown, but of course before it actually finishes shutting down. My particular script is just looking to push some log files from the local partition to a another server.
I've got the gist of how this process works, but I need some clarification.
How I understand it. Please correct me if I'm wrong.
- Create an executable script in /etc/init.d (lets call it /etc/init.d/push-logs)
 - Create a symlink to /etc/init.d/push-logs from /etc/rc0.d (shutdown) and /etc/rc6.d (reboot). The name should be KXXpush-logs
 
Here's my questions:
- Of course - am I understanding correctly?
 - For #2 above - it sounds like the lower the XX the better - is there too low a number I can use? Does it matter if it shares a number with another script?
 - Does the script in /etc/init.d/push-logs HAVE to follow the standard init.d template (supporting start/stop, etc. commands)? This doesn't really apply to my use case. If possible I just want the script to be the following:
 
#!/bin/sh # # Run PHP file prior to shutdown # /usr/bin/php /path/to/php_file.php
© Server Fault or respective owner