0

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.

Sandro B.
  • 66
  • 6

1 Answers1

0

Why not turning it around (without modifying any systemd units!) by using monit to start/stop your apache?

If you use /bin/systemctl start apache2.service as start program in monitrc and the same for stop, you can simply use monit with monit stop apache to do it "all inclusive" ;)

boppy
  • 476
  • 2
  • 5
  • That works in general @boppy, and i like the approach. Unfortunately, that means i have to change the procedure that a lot of operators already know for stopping/starting apache2 (and for a few other services, not mentioned here, as for them the drop-in works pretty great) Thank you though! – Sandro B. Nov 08 '19 at 16:46