Skip to content

Commit 49f61fc

Browse files
authored
Packaging: Cherry-pick changes to runners.sh from st2-packages (#6302)
2 parents d2d41b0 + 8c21b51 commit 49f61fc

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ Added
114114
* Copy systemd files from st2-packages.git for future packaging via pants. #6303
115115
Cherry-picked by @cognifloyd
116116

117+
* Cherry-pick changes to runners.sh from st2-packages git repo. #6302
118+
Cherry-picked by @cognifloyd
119+
117120
3.8.1 - December 13, 2023
118121
-------------------------
119122
Fixed

st2actions/bin/runners.sh

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
11
#!/bin/sh
22

3-
LSB_RELEASE=$(which lsb_release)
4-
SYSTEMDCTL=/bin/systemctl
5-
UPSTARTCTL=/sbin/initctl
6-
SPAWNSVC=st2actionrunner
7-
WORKERSVC=st2actionrunner-worker
3+
# Default number of workers
4+
WORKERS="${WORKERS:-10}"
85

9-
# Set default number of workers
10-
if [ -z "$WORKERS" ]; then
11-
WORKERS=$(/usr/bin/nproc 2>/dev/null)
12-
WORKERS="${WORKERS:-4}"
13-
fi
6+
# Choose init system to perform actions with a service.
7+
choose_sysinit() {
8+
local service="$1" svinit="unknown"
9+
if [ -d /run/systemd/system ]; then
10+
svinit=systemd
11+
else
12+
>&2 echo "Supported init systems: ONLY systemd"
13+
exit 99
14+
fi
15+
echo $svinit
16+
}
17+
18+
# Perform service action over the given number of workers.
19+
spawn_workers() {
20+
local action=$1 init= seq=
21+
seq=$(bash -c "printf '%g\\n' {1..$WORKERS}")
22+
23+
# Choose init system and exit if it's not supported.
24+
init=$(choose_sysinit st2actionrunner)
25+
[ $? -gt 0 ] && exit $?
1426

15-
# 1. Choose init type
16-
if [ -z "$sv" -a -x $SYSTEMDCTL ]; then
17-
sv=systemd
18-
svbin=$SYSTEMDCTL
19-
elif [ -z "$sv" ] && ( /sbin/start 2>&1 | grep -q "missing job name" ); then
20-
sv=upstart
21-
svbin=$UPSTARTCTL
22-
else
23-
>&2 echo "Unknown platform, we support ONLY upstart and systemd!"
27+
case $init in
28+
systemd)
29+
echo "$seq" | xargs -I{} /bin/systemctl $action \
30+
st2actionrunner@{}
31+
;;
32+
esac
33+
# return 1 in case if xargs failed any invoked commands.
34+
retval=$?; [ $retval -ge 123 ] && return 1 || return $retval
35+
}
36+
37+
# Perform service action on all actionrunners
38+
if [ -z "$1" ]; then
39+
echo >&2 "Usage: $0 action"
2440
exit 99
2541
fi
2642

27-
# 2. Spwan workers
28-
action="$1"; shift;
29-
rs=0
30-
i=1
31-
while [ $i -le $WORKERS ]; do
32-
if [ $sv = systemd ]; then
33-
$svbin $action $SPAWNSVC@$i
34-
elif [ $sv = upstart ]; then
35-
$svbin $action $WORKERSVC WORKERID=$i
36-
fi
37-
cmdrs=$?
38-
[ $cmdrs -gt 0 ] && rs=$cmdrs
39-
i=`expr $i + 1`
40-
done
41-
42-
exit $rs
43+
spawn_workers $1

0 commit comments

Comments
 (0)