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: `Requires 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 22, 2024
1 parent f1d892f commit bd70235
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 22 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: 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
22 changes: 1 addition & 21 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,7 @@ 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

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

set -e

systemctl start ${TO_RESTART}
systemctl start xapi
systemctl restart $MPATHALERT toolstack.target

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

0 comments on commit bd70235

Please sign in to comment.