Skip to content

Commit 1900a69

Browse files
committed
Consolidate script
1 parent bee5bbf commit 1900a69

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

manage-ghar

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ PID_FILE="runner.pid"
66
LOG_FILE="runner.log"
77
STATE_DIRNAME="state"
88

9-
# directory of the script, see https://stackoverflow.com/a/4774063/19422971
10-
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
11-
129
# check if runner is running based on the existence of a state file and based
1310
# on a valid PID
1411
is_running () {
@@ -20,10 +17,11 @@ is_running () {
2017
return 1
2118
fi
2219

23-
local pid=$(cat $state_path/$PID_FILE)
20+
local pid
21+
pid=$(cat "$state_path/$PID_FILE")
2422

2523
# check PID exists
26-
if ps -p $pid >/dev/null
24+
if ps -p "$pid" >/dev/null
2725
then
2826
return 0
2927
else
@@ -59,13 +57,13 @@ start () {
5957
fi
6058

6159
echo "Starting runner"
62-
echo "Starting runner on $(hostname)" >>$state_path/$LOG_FILE
60+
echo "Starting runner on $(hostname)" >>"$state_path/$LOG_FILE"
6361
cd "$runner_path"
64-
$command >>$state_path/$LOG_FILE 2>&1 &
62+
$command >>"$state_path/$LOG_FILE" 2>&1 &
6563

6664
# create pid file
6765
echo "Creating pid file"
68-
echo $! >$state_path/$PID_FILE
66+
echo $! >"$state_path/$PID_FILE"
6967
}
7068

7169
stop () {
@@ -74,18 +72,19 @@ stop () {
7472
# check if the runner is running
7573
if is_running "$state_path"
7674
then
77-
local pid=$(cat $state_path/$PID_FILE)
75+
local pid
76+
pid=$(cat "$state_path/$PID_FILE")
7877

7978
echo "Stopping runner"
80-
echo "Stopping runner on $(hostname)" >>$state_path/$LOG_FILE
81-
kill -SIGTERM $pid
79+
echo "Stopping runner on $(hostname)" >>"$state_path/$LOG_FILE"
80+
kill -SIGTERM "$pid"
8281
else
8382
echo "Runner already stopped"
84-
echo "Runner already stopped on $(hostname)" >>$state_path/$LOG_FILE
83+
echo "Runner already stopped on $(hostname)" >>"$state_path/$LOG_FILE"
8584
fi
8685

8786
echo "Removing PID file"
88-
rm --force $state_path/$PID_FILE
87+
rm --force "$state_path/$PID_FILE"
8988
}
9089

9190
status () {
@@ -172,7 +171,8 @@ main () {
172171
fi
173172

174173
local cmd="$1"
175-
local runner_path="$(realpath "$2")"
174+
local runner_path
175+
runner_path="$(realpath "$2")"
176176

177177
if [[ -z $state_path ]]
178178
then

0 commit comments

Comments
 (0)