3

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

2 Answers 2

2
  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.
2
  • 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, 2011 at 2:34
  • 1
    Simply, for example: S80mysql would execute before the S85httpd.
    – quanta
    Nov 19, 2011 at 16:01
0

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

/var/lock/subsys/push-logs

https://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...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .