With that Upstart config you will get the same results because you didn't put in a dependency. Also your runlevels line is wrong. Your config will do your backup at system start and shutdown. (0 is shutdown, 6 is reboot, 2345 is more what you want).
That is, you would need to make the mysql config dependent on your backup config so that it doesn't shutdown until your backup is done. But probably easier for you is to simply modify (make backup copy first) the /etc/init/mysql.conf config.
On my server it doesn't currently have a pre-stop script and that's what you would want. Add a pre-stop script that calls your backup. It will run before mysql stop trigger happens. It already has a pre-start and post-start but those get triggered when mysql is started.
Alternately you could add a dependency but that's something I've not tried myself. If you look at that mysql.conf you'll see it has a start dependency like this,
Code:
start on (net-device-up
and local-filesystems
and runlevel [2345])
This makes mysql dependent on those 3 conditions being met. You could alter the "stop on" conditions to make it only stop when your backup is completed. Then you set your backup conf to only start on runlevel 0 (shutdown). mysql wouldn't shutdown until both runlevel 016 and your backup is done. I'm not sure if the kernel will wait on mysql though. That would require more reading on whether upstart requires all jobs to complete or whether after some timeout it just kills everything.
Anyway, I think the condition would be something like this,
Code:
stop on (runlevel [016]
and backup stopped)
Where backup is the name of your backup job started by backup.conf
---
All of this seems rather tricky. Looking briefly at the apcupsd docs I see that when your ups detects a problem and when it goes onto battery there is a call made each time to /etc/apcupsd/apccontrol with an argument. You would likely find it better and much easier to trigger your backup from the "powerout" message. According to my reading (I don't have one) there is no default action for these messages but you could simply start your backup by adding a section like this to the /etc/apcupsd/apccontrol script.
Code:
if [ "$1" = "powerout" ]; then
dobackup
fi
As long as your UPS gives you enough time between detecting the power out, to going onto battery and then to shutdown.
Bookmarks