I've an OpenERP server running on one of my servers. It's started by a traditional /etc/init.d/
script. It uses a PostgreSQL database and needs a manual restart every time PostgreSQL is restarted.
Every time Ubuntu releases a security update for PostgreSQL, my OpenERP server becomes non-functional until I ssh to the server and manually run sudo /etc/init.d/my-openerp restart
. I usually forget to do that after I do the sudo apt-get upgrade
.
Can I configure upstart to do that for me, every time postgresql is restarted by apt?
Since the postgresql server is still using deprecated System-V init script there are two options:
In both cases you can use
start on started-postgresql
andstop on stopping-postgresql
in your job. As mentioned in the comment my-openerp will start/stop always on started/stopped postgresql and not only after upgrade.If you opt for emitting events from the existing System-V init script you will need to add in /etc/init.d/postgresql:
For details see Helpful Tips in Writing Services section on Ubuntu Boot up Howto page.
In case that you opt for creating Upstart job the simplest configuration might look like this:
More elaborated Upstart config can be found here.
I would play around and instead of starting postgresql on runlevel [2345] perhaps say
or
You might also consider adding kill timeout stanza
To elaborate on schkovich's first option, here's a simple modification to the System V
/etc/init.d/postgresql
script.So whenever postgres is sent "start/restart"/"reload"/"force-restart", I send the "starting-postgresql" event before the command is issued, and the "started-postgresql" after its finished. Similarly, with "stop", I send the "stopping-postgresql" event before the command and "stopped-postgresql" after its issued.
I'm only showing the final case block (
case "$1" in [...] esac
at the bottom of the script. To make the changes clearer (in case future versions of postgres modify the system-V script, I've highlighted the lines that need to be inserted by putting them between#### BEGIN emit-upstart-event
and#### END emit-upstart-event
.If you want to handle restarting with all the proper signals (by splitting restart into a stop and start commands) you can do:
I wrote s a script in which I made a -system-update function, which stops openerp, updates the system by apt-get upgrade, then starts openerp, then restart web-client in case of version < 6.1. Problem is that it requires you use the script to update your server. I didn't use an alias.