Using heartbeat with systemd

clusterdrbdheartbeatsystemd

I'm using a simple setup with heartbeat handling a shared filesystem implemented with drbd and served via apache.
I'm using /etc/ha.d/haresources to define the ha resource, this way:

server1 drbddisk::myfs \
Filesystem::/dev/drbd/by-res/myfs::/mnt/myfs::ext4::noatime \
IPaddr::10.0.0.254/24/eth0 apache2

This works fine if using the old debian sysvinit, but has a race problem with systemd because stopping apache is done asyncronously, so when heartbeat issue the "/etc/init.d/apache2 stop" scrypt while it returns very quickly, apache2 can still be active and hence the unmount of the FS fails.

I know a lot of workarounds to solve this problem but I would like to know if there is a "clean" way, without having to revert to sysvinit

Best Answer

Systemd itself (on Debian 8) is just using the good old init-scripts.

user@server:~> systemctl status apache2
apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2)
   Active: active (running) since Mon 2015-02-12 13:24:34 CEST; 7 weeks 8 days ago
  Process: 24775 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 9475 ExecReload=/etc/init.d/apache2 reload (code=exited, status=0/SUCCESS)
  Process: 24799 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)

That's not a systemd problem. Systemds 'systemctl' also doesn't work asynchronously by default. That's what the --no-block option is for. You're also probably not using systemd-tools at all when issuing commands like that in heartbeat.