From 79c02bccb3cc710b00d46f879ab7092d81346c6a Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Thu, 2 Jan 2025 22:17:34 -0600 Subject: [PATCH 1/9] Revert "Remove sysv" (st2actions/bin/runners.sh) This partially reverts commit 0f58e6a9032504a0aec22b3f1b179814e2cb25bd. This should make it easier to apply changes from st2-packages repo. --- st2actions/bin/runners.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/st2actions/bin/runners.sh b/st2actions/bin/runners.sh index 916c05d820..4c5ec3692a 100755 --- a/st2actions/bin/runners.sh +++ b/st2actions/bin/runners.sh @@ -12,7 +12,15 @@ if [ -z "$WORKERS" ]; then WORKERS="${WORKERS:-4}" fi -# 1. Choose init type +# 1. Choose init type on Debian containers use sysv +if [ -x "$LSB_RELEASE" ]; then + if [ -f /.dockerenv ] && [ $($LSB_RELEASE -is) = Debian ]; then + sv=sysv + svbin=/etc/init.d/$WORKERSVC + fi +fi + +# 2. Second criteria if [ -z "$sv" -a -x $SYSTEMDCTL ]; then sv=systemd svbin=$SYSTEMDCTL @@ -20,8 +28,14 @@ elif [ -z "$sv" ] && ( /sbin/start 2>&1 | grep -q "missing job name" ); then sv=upstart svbin=$UPSTARTCTL else - >&2 echo "Unknown platform, we support ONLY upstart and systemd!" - exit 99 + # Old debians, amazon etc + sv=sysv + svbin=/etc/init.d/$WORKERSVC + if [ ! -x $svbin ]; then + >&2 echo "Init file not found: $svbin" + >&2 echo "Unknown platform, we support ONLY debian, systemd and sysv!" + exit 99 + fi fi # 2. Spwan workers @@ -33,6 +47,8 @@ while [ $i -le $WORKERS ]; do $svbin $action $SPAWNSVC@$i elif [ $sv = upstart ]; then $svbin $action $WORKERSVC WORKERID=$i + elif [ $sv = sysv ]; then + WORKERID=$i $svbin $action fi cmdrs=$? [ $cmdrs -gt 0 ] && rs=$cmdrs From 5a0e1f96fc0eb2762cc55ac77a1cdc16a3149cfa Mon Sep 17 00:00:00 2001 From: Denis Baryshev Date: Sat, 26 Dec 2015 19:59:43 +0700 Subject: [PATCH 2/9] improved init detection mechanism in runners.sh wrapper Cherry-picked from StackStorm/st2-packages@048ab5ff1ac43fde59c109802d4d483480b36b39 --- st2actions/bin/runners.sh | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/st2actions/bin/runners.sh b/st2actions/bin/runners.sh index 4c5ec3692a..5985fbc0a6 100755 --- a/st2actions/bin/runners.sh +++ b/st2actions/bin/runners.sh @@ -1,6 +1,6 @@ #!/bin/sh -LSB_RELEASE=$(which lsb_release) +INITCOMM=$(cat /proc/1/comm) SYSTEMDCTL=/bin/systemctl UPSTARTCTL=/sbin/initctl SPAWNSVC=st2actionrunner @@ -12,23 +12,19 @@ if [ -z "$WORKERS" ]; then WORKERS="${WORKERS:-4}" fi -# 1. Choose init type on Debian containers use sysv -if [ -x "$LSB_RELEASE" ]; then - if [ -f /.dockerenv ] && [ $($LSB_RELEASE -is) = Debian ]; then - sv=sysv - svbin=/etc/init.d/$WORKERSVC - fi -fi - -# 2. Second criteria -if [ -z "$sv" -a -x $SYSTEMDCTL ]; then +## Use running init system detection criterias +# +if [ -d /run/systemd/system ]; then + # systemd is running sv=systemd svbin=$SYSTEMDCTL -elif [ -z "$sv" ] && ( /sbin/start 2>&1 | grep -q "missing job name" ); then +elif [ "$INITCOMM" = init ] && ($UPSTARTCTL version 2>&1); then + # init is running and upstart has been detected sv=upstart svbin=$UPSTARTCTL else - # Old debians, amazon etc + # In all other cases which may apply to older debians, redhats and + # centos, amazon etc. sv=sysv svbin=/etc/init.d/$WORKERSVC if [ ! -x $svbin ]; then @@ -38,7 +34,8 @@ else fi fi -# 2. Spwan workers +## Spwan workers +# action="$1"; shift; rs=0 i=1 From 384464ea0ad7215d8694c2f4f94302e3bdce0210 Mon Sep 17 00:00:00 2001 From: Denis Baryshev Date: Fri, 22 Jan 2016 01:34:36 +0700 Subject: [PATCH 3/9] fixing upstart false positive on centos 6.6 (since we don't ship upstart jobs for rhels) Cherry-picked from StackStorm/st2-packages@8fc208efe755c08a79510864e8eaf42bba8a7809 --- st2actions/bin/runners.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/st2actions/bin/runners.sh b/st2actions/bin/runners.sh index 5985fbc0a6..ceeaa0136b 100755 --- a/st2actions/bin/runners.sh +++ b/st2actions/bin/runners.sh @@ -18,7 +18,8 @@ if [ -d /run/systemd/system ]; then # systemd is running sv=systemd svbin=$SYSTEMDCTL -elif [ "$INITCOMM" = init ] && ($UPSTARTCTL version 2>&1); then +elif [ "$INITCOMM" = init ] && ($UPSTARTCTL version 2>&1) && + [ -f /etc/init/$WORKERSVC.conf ]; then # init is running and upstart has been detected sv=upstart svbin=$UPSTARTCTL From 297edb1f8a3a872d93e51f52be5012d62964b0be Mon Sep 17 00:00:00 2001 From: Denis Baryshev Date: Thu, 28 Jan 2016 02:33:16 +0700 Subject: [PATCH 4/9] default number of actionrunner workers is set to 10 Cherry-picked from StackStorm/st2-packages@3f0f3dc4514a2fb88b3b9867a43bdf2deddf72bb --- st2actions/bin/runners.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/st2actions/bin/runners.sh b/st2actions/bin/runners.sh index ceeaa0136b..bea4e98b43 100755 --- a/st2actions/bin/runners.sh +++ b/st2actions/bin/runners.sh @@ -5,12 +5,8 @@ SYSTEMDCTL=/bin/systemctl UPSTARTCTL=/sbin/initctl SPAWNSVC=st2actionrunner WORKERSVC=st2actionrunner-worker - # Set default number of workers -if [ -z "$WORKERS" ]; then - WORKERS=$(/usr/bin/nproc 2>/dev/null) - WORKERS="${WORKERS:-4}" -fi +WORKERS="${WORKERS:-10}" ## Use running init system detection criterias # From 61b8506b4ac9fa1609c7c0fcb78754825be3fbec Mon Sep 17 00:00:00 2001 From: Denis Baryshev Date: Fri, 4 Mar 2016 23:08:25 +0700 Subject: [PATCH 5/9] beautify runners.sh Cherry-picked from StackStorm/st2-packages@7661c69cf64768dfcd9cf5a1e089e0484bf003a1 --- st2actions/bin/runners.sh | 95 ++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/st2actions/bin/runners.sh b/st2actions/bin/runners.sh index bea4e98b43..1a186bec4e 100755 --- a/st2actions/bin/runners.sh +++ b/st2actions/bin/runners.sh @@ -1,52 +1,57 @@ #!/bin/sh -INITCOMM=$(cat /proc/1/comm) -SYSTEMDCTL=/bin/systemctl -UPSTARTCTL=/sbin/initctl -SPAWNSVC=st2actionrunner -WORKERSVC=st2actionrunner-worker -# Set default number of workers +# Default number of workers WORKERS="${WORKERS:-10}" -## Use running init system detection criterias -# -if [ -d /run/systemd/system ]; then - # systemd is running - sv=systemd - svbin=$SYSTEMDCTL -elif [ "$INITCOMM" = init ] && ($UPSTARTCTL version 2>&1) && - [ -f /etc/init/$WORKERSVC.conf ]; then - # init is running and upstart has been detected - sv=upstart - svbin=$UPSTARTCTL -else - # In all other cases which may apply to older debians, redhats and - # centos, amazon etc. - sv=sysv - svbin=/etc/init.d/$WORKERSVC - if [ ! -x $svbin ]; then - >&2 echo "Init file not found: $svbin" - >&2 echo "Unknown platform, we support ONLY debian, systemd and sysv!" - exit 99 +# Choose init system to perform actions with a service. +choose_sysinit() { + local service="$1" svinit="sysv" + if [ -d /run/systemd/system ]; then + svinit=systemd + elif [ "$(cat /proc/1/comm)" = init ] && [ -f /etc/init/${service}.conf ] && + (/sbin/initctl version 2>&1 | grep -q upstart); then + svinit=upstart + else + if [ ! -x /etc/init.d/${service} ]; then + >&2 echo "Supported init systems: systemd, upstart and sysv" + >&2 echo "/etc/init.d/${service} not found or disabled" + exit 99 + fi fi -fi + echo $svinit +} -## Spwan workers -# -action="$1"; shift; -rs=0 -i=1 -while [ $i -le $WORKERS ]; do - if [ $sv = systemd ]; then - $svbin $action $SPAWNSVC@$i - elif [ $sv = upstart ]; then - $svbin $action $WORKERSVC WORKERID=$i - elif [ $sv = sysv ]; then - WORKERID=$i $svbin $action - fi - cmdrs=$? - [ $cmdrs -gt 0 ] && rs=$cmdrs - i=`expr $i + 1` -done +# Perform service action over the given number of workers. +spawn_workers() { + local action=$1 + local init= seq=$(eval printf '%g\\n' {1..$WORKERS}) + + # Choose init system and exit if it's not supported. + init=$(choose_sysinit st2actionrunner) + [ $? -gt 0 ] && exit $? + + case $init in + systemd) + echo "$seq" | xargs -I{} /bin/systemctl $action \ + st2actionrunner@{} + ;; + upstart) + echo "$seq" | xargs -I{} /sbin/initctl $action \ + st2actionrunner-worker WORKERID={} + ;; + sysv) + echo "$seq" | xargs -I{} /bin/sh -c \ + "WORKERID={} /etc/init.d/st2actionrunner-worker $action" + ;; + esac + # return 1 in case if xargs failed any invoked commands. + [ $? -ge 123 ] && return 1 || return $? +} + +# Perform service action on all actionrunners +if [ -z "$1" ]; then + echo >&2 "Usage: $0 action" + exit 99 +fi -exit $rs +spawn_workers $1 From 16bd4cf84c9f1ceafd8cdc53adbc6f7d22308146 Mon Sep 17 00:00:00 2001 From: Denis Baryshev Date: Mon, 7 Mar 2016 19:17:55 +0700 Subject: [PATCH 6/9] runners.sh fix xargs return code Cherry-picked from StackStorm/st2-packages@0792494b5762f91aa3bfc1aeb8f4a91c1c3934e5 --- st2actions/bin/runners.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/st2actions/bin/runners.sh b/st2actions/bin/runners.sh index 1a186bec4e..8445935376 100755 --- a/st2actions/bin/runners.sh +++ b/st2actions/bin/runners.sh @@ -23,8 +23,8 @@ choose_sysinit() { # Perform service action over the given number of workers. spawn_workers() { - local action=$1 - local init= seq=$(eval printf '%g\\n' {1..$WORKERS}) + local action=$1 init= seq= + seq=$(bash -c "printf '%g\\n' {1..$WORKERS}") # Choose init system and exit if it's not supported. init=$(choose_sysinit st2actionrunner) @@ -45,7 +45,7 @@ spawn_workers() { ;; esac # return 1 in case if xargs failed any invoked commands. - [ $? -ge 123 ] && return 1 || return $? + retval=$?; [ $retval -ge 123 ] && return 1 || return $retval } # Perform service action on all actionrunners From df672afcdeb0d28845b4375cb76e5a2807e9c296 Mon Sep 17 00:00:00 2001 From: armab Date: Thu, 18 Jun 2020 00:07:20 +0100 Subject: [PATCH 7/9] Remove more upstart logic artifacts Cherry-picked from StackStorm/st2-packages@93aa7569440aaefd6c04278945c20d7c66097376 --- st2actions/bin/runners.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/st2actions/bin/runners.sh b/st2actions/bin/runners.sh index 8445935376..17a12cf849 100755 --- a/st2actions/bin/runners.sh +++ b/st2actions/bin/runners.sh @@ -8,12 +8,9 @@ choose_sysinit() { local service="$1" svinit="sysv" if [ -d /run/systemd/system ]; then svinit=systemd - elif [ "$(cat /proc/1/comm)" = init ] && [ -f /etc/init/${service}.conf ] && - (/sbin/initctl version 2>&1 | grep -q upstart); then - svinit=upstart else if [ ! -x /etc/init.d/${service} ]; then - >&2 echo "Supported init systems: systemd, upstart and sysv" + >&2 echo "Supported init systems: systemd and sysv" >&2 echo "/etc/init.d/${service} not found or disabled" exit 99 fi @@ -35,10 +32,6 @@ spawn_workers() { echo "$seq" | xargs -I{} /bin/systemctl $action \ st2actionrunner@{} ;; - upstart) - echo "$seq" | xargs -I{} /sbin/initctl $action \ - st2actionrunner-worker WORKERID={} - ;; sysv) echo "$seq" | xargs -I{} /bin/sh -c \ "WORKERID={} /etc/init.d/st2actionrunner-worker $action" From edeb91e46f729da20c53cda59ad6d8e70f0cb4fd Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Thu, 2 Jan 2025 23:16:24 -0600 Subject: [PATCH 8/9] Reapply "Remove sysv" (st2actions/bin/runners.sh) Originally added in 0f58e6a9032504a0aec22b3f1b179814e2cb25bd Reverted in a04e59428380bca2a33b4e31c48ea8fc43e89bff Now reapplying after cherry-picking changes from st2-packages repo. --- st2actions/bin/runners.sh | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/st2actions/bin/runners.sh b/st2actions/bin/runners.sh index 17a12cf849..730d2342c7 100755 --- a/st2actions/bin/runners.sh +++ b/st2actions/bin/runners.sh @@ -5,15 +5,12 @@ WORKERS="${WORKERS:-10}" # Choose init system to perform actions with a service. choose_sysinit() { - local service="$1" svinit="sysv" + local service="$1" svinit="unknown" if [ -d /run/systemd/system ]; then svinit=systemd else - if [ ! -x /etc/init.d/${service} ]; then - >&2 echo "Supported init systems: systemd and sysv" - >&2 echo "/etc/init.d/${service} not found or disabled" - exit 99 - fi + >&2 echo "Supported init systems: ONLY systemd" + exit 99 fi echo $svinit } @@ -32,10 +29,6 @@ spawn_workers() { echo "$seq" | xargs -I{} /bin/systemctl $action \ st2actionrunner@{} ;; - sysv) - echo "$seq" | xargs -I{} /bin/sh -c \ - "WORKERID={} /etc/init.d/st2actionrunner-worker $action" - ;; esac # return 1 in case if xargs failed any invoked commands. retval=$?; [ $retval -ge 123 ] && return 1 || return $retval From 244fe8dcc7a3202aa9cfd510504f2519bb10d17f Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 14 Feb 2025 10:48:44 -0600 Subject: [PATCH 9/9] add changelog entry --- CHANGELOG.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b23c33ac83..fb38874107 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -108,6 +108,9 @@ Added * Add python 3.10 and 3.11 to the GitHub Actions test matrix. Contributed by @nzlosh, @guzzijones12, and @cognifloyd +* Cherry-pick changes to runners.sh from st2-packages git repo. #6302 + Cherry-picked by @cognifloyd + 3.8.1 - December 13, 2023 ------------------------- Fixed