Terry Burton 2016-05-16 17:43:
On 13 May 2016 at 00:04, Terry Burton wrote:
I have a process (ISC DHCP) that has no reload or soft restart
mechanism. The only way to "reload" it is a stop and start.
I understand systemd's design choice of maintaining a clear
distinction between reload and restart based on whether the service is
interrupted or not, so it's clear that I should use restart.
However, in the event that the user invokes "restart" I would like to
validate the config file before taking the Stop action to avoid loss
of service (as was the case for the reload action of my previous init
scripts.)
We do not however have ExecStopPre and there does not appear to be a
way to interrupt a Stop action based on the result of ExecStop so I'm
not sure where that leaves me? Does anyone have a useful recipe that
accomplishes this?
Perhaps such a config check is considered one of those things that
lives in a support script or user's best practises outside of the init
system... That seems a shame though.
A quick nudge before moving along...
Still learning the ins and outs of systemd myself, so I don't think I
have a solution for you, but I'd also be interested in this. I've run
into a few cases where I expected something to reload/restart and didn't
realize that it hadn't because the output was buried in the journal
somehow.
In the past I might have done something like this in an
/etc/default/dhcpd file (in Debian based distros) knowing that it would
be sourced as a generic shell file by the init script before actually
being run and not just a list of key=value environment variable pairs
like systemd expects:
CONFFILE='/etc/dhcp/dhcpd.conf'
if [ "$1" != "stop" ]; then
if ! dhcpd -t -cf "$CONFFILE" > /dev/null; then
echo "ERROR: '$CONFFILE' failed to lint check. Check the logs for
details." >&2
exit 1
fi
fi
# else, let it pass
I was hoping there was something like a
ConditionReturnsZero=/path/to/some/script that would prevent
start/stop/restart/etc. actions if the script didn't exit 0.
Maybe you could hack around that with something like the following
(totally untested):
/etc/systemd/system/dhcpd-lint-check.service:
[Unit]
Before=dhcpd.service
[Service]
Type=oneshot
ExecStartPre=/bin/rm -f /etc/dhcp/dhcpd-conf-lint-checks-ok
ExecStart=/usr/sbin/dhcpd -t -cf /etc/dhcp/dhcpd.conf
ExecStartPost=/usr/bin/touch /etc/dhcp/dhcpd-conf-lint-checks-ok
RemainAfterExit=false
[Install]
WantedBy=dhcpd.service
/etc/systemd/system/dhcpd.service.d/01-lint-check-condition.conf:
[Unit]
ConditionPathExists=/etc/dhcpd/dhcpd-conf-lint-checks-ok
Basically, add a condition to the dhcpd service for a canary file
existing. That canary file gets managed by a mini oneshot service that
checks the dhcpd.conf file for sanity, but doesn't remain, so I think
that it should be attempted to be started before the dhcpd.service is.
Probably I'm missing some ordering/dependency races though. Maybe the
ExecStartPost needs to be combined with ExecStart in a shell && style
combo. Not sure offhand.
Anyways, let us know if you do find something that works out for you.
Thanks,
Brian
signature.asc
Description: Digital signature
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel