Skip to content

Commit

Permalink
CP-51870: Delegate restarting systemd services order to systemd
Browse files Browse the repository at this point in the history
services configuration

Systemd services has good support for the services depends and
orders in the Unit file, that is the place the restart order
should be stated.
However, the command `systemd stop foo bar ...` will override
the order in the Unit file. As the number of the services grow
up, it is really hard to manage the order in the systemd command

In order to resolve the issue, `toolstack.target` is created to
group and manage the toolstack services.
- toolstack.target: `Wants: foo.service` will start foo.service
when `systemctl start toolstack.target`
- foo.service: `PartOf: toolstack.target` will restart/stop
foo.service when `systemctl stop/restart toolstack.target`
Note: Above two does not have to match, eg. if we do not want to
start a service during `systemctl start toolstack.target`, we can
remove it from the first list.

- Following xenopsd services are no longer valid, just got removed
  * xenopsd
  * xenopsd-xenlight
  * xenopsd-simulator
  * xenopsd-libvirt

Signed-off-by: Lin Liu <[email protected]>
  • Loading branch information
liulinC committed Oct 23, 2024
1 parent f1d892f commit d157db0
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 19 deletions.
1 change: 1 addition & 0 deletions python3/perfmon/perfmon.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=Performance monitoring/alarm generation daemon
After=xapi.service
Wants=xapi.service
PartOf=toolstack.target

[Service]
EnvironmentFile=-/etc/sysconfig/perfmon
Expand Down
3 changes: 3 additions & 0 deletions scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,6 @@ install:
$(IDATA) mail-languages/ja-JP.json $(DESTDIR)/etc/xapi.d/mail-languages
# uefi
mkdir -p $(DESTDIR)/etc/xapi.d/efi-clone

# toolstack.target to manage toolstack services as a group
$(IDATA) toolstack.target $(DESTDIR)/usr/lib/systemd/system/toolstack.target
27 changes: 27 additions & 0 deletions scripts/toolstack.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Unit]
Description=toolstack Target to manage toolstack service restart
# wants to start following services when run `systemctl start toolstack.target`
# Note: `Wants` is used here instead of `Requires`, `Requires` will stop/restart
# whole toolstack.target on any service stop/restart
Wants=xapi.service
Wants=message-switch.service
Wants=forkexecd.service
Wants=perfmon.service
Wants=v6d.service
Wants=xcp-rrdd-iostat.service
Wants=xcp-rrdd-squeezed.service
Wants=xcp-rrdd-netdev.service
Wants=xcp-rrdd-dcmi.service
Wants=xcp-rrdd-cpu.service
Wants=xcp-rrdd-xenpm.service
Wants=xcp-rrdd-gpumon.service
Wants=xcp-rrdd.service
Wants=xcp-networkd.service
Wants=xenopsd-xc.service
Wants=squeezed.service
Wants=xapi-storage-script.service
Wants=xapi-clusterd.service
Wants=varstored-guard.service

[Install]
WantedBy=multi-user.target
3 changes: 2 additions & 1 deletion scripts/varstored-guard.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Description=Varstored XAPI socket deprivileging daemon
Documentation=man:varstored-guard(1)
After=message-switch.service syslog.target
Before=xapi-domains.service xenopsd.service
Before=xapi-domains.service xenopsd-xc.service
Wants=message-switch.service syslog.target
PartOf=toolstack.target

[Service]
Type=simple
Expand Down
1 change: 1 addition & 0 deletions scripts/xapi.service
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ After=xcp-rrdd.service
After=xenopsd-xc.service
After=xenstored.service
After[email protected]
PartOf=toolstack.target

Conflicts=shutdown.target

Expand Down
1 change: 1 addition & 0 deletions scripts/xcp-networkd.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Description=XCP networking daemon
Documentation=man:xcp-networkd(1)
After=forkexecd.service message-switch.service syslog.target
Wants=forkexecd.service message-switch.service syslog.target
PartOf=toolstack.target

[Service]
Type=notify
Expand Down
1 change: 1 addition & 0 deletions scripts/xcp-rrdd-cpu.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=XCP RRD daemon CPU plugin
After=xcp-rrdd.service
Requires=xcp-rrdd.service
PartOf=toolstack.target

[Service]
ExecStart=/opt/xensource/libexec/xcp-rrdd-plugins/xcp-rrdd-cpu
Expand Down
1 change: 1 addition & 0 deletions scripts/xcp-rrdd-dcmi.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=XCP RRD daemon IPMI DCMI power plugin
After=xcp-rrdd.service
Requires=xcp-rrdd.service
PartOf=toolstack.target

[Service]
ExecStart=/opt/xensource/libexec/xcp-rrdd-plugins/xcp-rrdd-dcmi
Expand Down
1 change: 1 addition & 0 deletions scripts/xcp-rrdd-iostat.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=XCP RRD daemon iostat plugin
After=xcp-rrdd.service
Requires=xcp-rrdd.service
PartOf=toolstack.target

[Service]
ExecStart=/opt/xensource/libexec/xcp-rrdd-plugins/xcp-rrdd-iostat
Expand Down
1 change: 1 addition & 0 deletions scripts/xcp-rrdd-netdev.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=XCP RRD daemon network plugin
After=xcp-rrdd.service
Requires=xcp-rrdd.service
PartOf=toolstack.target

[Service]
ExecStart=/opt/xensource/libexec/xcp-rrdd-plugins/xcp-rrdd-netdev
Expand Down
1 change: 1 addition & 0 deletions scripts/xcp-rrdd-squeezed.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=XCP RRD daemon squeezed plugin
After=xcp-rrdd.service
Requires=xcp-rrdd.service
PartOf=toolstack.target

[Service]
ExecStart=/opt/xensource/libexec/xcp-rrdd-plugins/xcp-rrdd-squeezed
Expand Down
1 change: 1 addition & 0 deletions scripts/xcp-rrdd-xenpm.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=XCP RRD daemon xenpm plugin
After=xcp-rrdd.service
Requires=xcp-rrdd.service
PartOf=toolstack.target

[Service]
ExecStart=/opt/xensource/libexec/xcp-rrdd-plugins/xcp-rrdd-xenpm
Expand Down
1 change: 1 addition & 0 deletions scripts/xcp-rrdd.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=XCP RRD daemon
After=forkexecd.service xenstored.service message-switch.service syslog.target
Wants=forkexecd.service xenstored.service message-switch.service syslog.target
PartOf=toolstack.target

[Service]
Type=notify
Expand Down
32 changes: 14 additions & 18 deletions scripts/xe-toolstack-restart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ echo "Executing $FILENAME"

POOLCONF=`cat @ETCXENDIR@/pool.conf`
if [ $POOLCONF == "master" ]; then MPATHALERT="mpathalert"; else MPATHALERT=""; fi
SERVICES="message-switch perfmon v6d xenopsd xenopsd-xc xenopsd-xenlight
xenopsd-simulator xenopsd-libvirt xcp-rrdd-iostat xcp-rrdd-squeezed
xcp-rrdd-netdev xcp-rrdd-cpu
xcp-rrdd-xenpm xcp-rrdd-gpumon xcp-rrdd xcp-networkd squeezed forkexecd
$MPATHALERT xapi-storage-script xapi-clusterd varstored-guard"

tmp_file=$(mktemp --suffix="xe-toolstack-restart")
systemctl stop stunnel@xapi > $tmp_file 2>&1
Expand All @@ -43,22 +38,23 @@ if [[ $kill_stunnel_exit_code != 0 ]]; then
fi
rm -f $tmp_file

TO_RESTART=""
for svc in $SERVICES ; do
# restart services only if systemd said they were enabled
systemctl is-enabled $svc >/dev/null 2>&1
set -e

if [ $? -eq 0 ] ; then
TO_RESTART="$svc $TO_RESTART"
fi
done
systemctl stop xapi
systemctl stop ${TO_RESTART}
systemctl restart $MPATHALERT toolstack.target

set -e
# Check the status of toolstack services
for service in $(systemctl list-dependencies --plain --no-pager toolstack.target); do
# During system bootup, xcp-rrdd-dcmi.service often fail as
# `ipmitool dcmi discover` discover nothing, just ignore it for now
if [ "$service" == "xcp-rrdd-dcmi.service" ]; then
continue
fi

systemctl start ${TO_RESTART}
systemctl start xapi
if ! systemctl is-active --quiet "$service"; then
echo "$service failed to restart, $(systemctl status $service)"
exit 1
fi
done

rm -f $LOCKFILE
echo "done."
Expand Down

0 comments on commit d157db0

Please sign in to comment.