Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions st2common/bin/st2ctl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

COMPONENTS="st2actionrunner st2api st2stream st2auth st2garbagecollector st2notifier st2rulesengine st2sensorcontainer st2chatops st2timersengine st2workflowengine st2scheduler"
ST2_CONF="/etc/st2/st2.conf"
SYSTEMD_RELOADED=""

# Ensure global environment is sourced if exists
# Does not happen consistently with all OSes we support.
Expand Down Expand Up @@ -108,6 +109,11 @@ function service_manager() {
local svcname=$1 action=$2
if [ -d /run/systemd/system ]; then
# systemd is running
if [ -z $SYSTEMD_RELOADED ]; then
#Reload systemd to regenerate socket files from st2.conf
systemctl daemon-reload
SYSTEMD_RELOADED="yes"
Comment on lines +112 to +115
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering SYSTEMD_RELOADED state is not saved in any file storage or passed externally, what's the idea here?

Will it run the systemctl daemon-reload on every new st2ctl run?

From that point, is the daemon-reload that triggers system-generator then?

Copy link
Contributor Author

@nzlosh nzlosh Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you've understood the logic correctly. The SYSTEMD_RELOADED is to guard against reloading systemd for every daemon process st2ctl will restart in a single invocation. The systemctl daemon-reload triggers the execution of the generators. This way the socket files are regenerated with each st2ctl restart.

While this may seem inefficient, because the likelihood of st2.conf being changed on each restart is low, the logic required to test st2.conf last modified time and compare it with the age the daemon process being restarted would have added unnecessary complexity. The daemon-reload is ~200ms on my dev machine which is insignificant compare with the time it takes to restart all st2 daemon (12.848s on my dev machine).

For the sake of science, here's the time it takes to restart each of the concerned daemons:

root@u1804:~# time systemctl restart st2api
real    0m4.014s
user    0m0.004s
sys     0m0.003s

root@u1804:~# time systemctl restart st2auth
real    0m1.879s
user    0m0.007s
sys     0m0.000s

root@u1804:~# time systemctl restart st2stream
real    0m1.483s
user    0m0.003s
sys     0m0.004s

fi
systemctl $action $svcname
elif [ $(cat /proc/1/comm) = init ] && (/sbin/initctl version 2>/dev/null | grep -q upstart) &&
[ -f /etc/init/${svcname}.conf ]; then
Expand Down