I have several debian 8 servers shipped with a default configuration.
They have on board apache2 and i want to add monit ( https://mmonit.com/monit/ ) for extra availability.
To manage operator-driven stops and starts of apache, i would love to add monit monitor and unmonitor actions to the apache systemd unit. I thought about shipping this drop-in file in the systemd apache configuration (/etc/systemd/system/apache2.service.d/ folder):
[Service]
ExecStartPost=-/usr/bin/monit monitor apache2
ExecStop=-/usr/bin/monit unmonitor apache2
The ExecStartPost command works great.
Unfortunately I have some problems with the ExecStop command because it is executed after the actual stop of the service.
I figured out that there is another ExecStop defined in /run/systemd/generator.late/apache2.service (a file automatically generated by systemd-sysv-generator). Of course there is no problem in having multiple ExecStop commands, the problem here is about order:
root@debianjessie:~# systemctl show apache2 | grep ^ExecStop
ExecStop={ path=/etc/init.d/apache2 ; argv[]=/etc/init.d/apache2 stop ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
ExecStop={ path=/usr/bin/monit ; argv[]=/usr/bin/monit unmonitor apache2 ; ignore_errors=yes ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
I found a workaround redefining all the ExecStop sequence in my drop-in file:
[Service]
ExecStartPost=-/usr/bin/monit monitor apache2
ExecStop=
ExecStop=-/usr/bin/monit unmonitor apache2
ExecStop=/etc/init.d/apache2 stop
but i think it's not a very "clean" solution in my opinion.
Reading here the drop-ins in /etc/ should be the ones with the highest priority, so i don't get why my drop-in ExecStop action is executed last.
Am I missing anything?
Thanks in advance. S.