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'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.

  1. Create an executable script in /etc/init.d (lets call it /etc/init.d/push-logs)
  2. 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:

  1. Of course - am I understanding correctly?
  2. 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?
  3. 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
share|improve this question

2 Answers 2

up vote 1 down vote accepted
  1. Yes, ut the symlink name should begin with a S - for Start (K for Kill)
  2. The two-digit specifies the order of execution for your script, the lowest numbered being execute first.
  3. Yes, because Linux will execute the equivalent of service push-logs start for the S symlink.
share|improve this answer
    
Thanks - can you answer #2 in full a bit more? Turns out writing the init.d script is a cinch, so that was no issue. –  dtbarne Nov 19 '11 at 2:34
    
Simply, for example: S80mysql would execute before the S85httpd. –  quanta Nov 19 '11 at 16:01

On CentOS you also need the matching file in /var/lock/subsys/

/var/lock/subsys/push-logs

http://unix.stackexchange.com/questions/114274/an-init-script-does-not-get-called-on-shutdown

With that in mind it might be easier to make a fake service which touches that file on start and does nothing on status...

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.