Skip to content
Snippets Groups Projects
Commit 30751377 authored by Valery Sizov's avatar Valery Sizov
Browse files

removed unnecesarry variable from init.d script

parent 4d3a9d13
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -14,92 +14,60 @@ APP_ROOT="/home/gitlab_ci_runner/gitlab-ci-runner"
APP_USER="gitlab_ci_runner"
PID_PATH="$APP_ROOT/tmp/pids"
PROCESS_NAME="ruby ./bin/runner"
RUNNERS_PID="$PID_PATH/runners.pid"
RUNNERS_NUM=1 # number of runners to spawn
RUNNER_PID="$PID_PATH/runners.pid"
START_RUNNER="nohup bundle exec ./bin/runner"
NAME="gitlab-ci-runner"
DESC="GitLab CI runner"
RUNNERS_REGISTERED=0
RUNNERS_RUNNING=0
INIT_LOG="/var/log/gitlab_ci_runner.log"
 
check_pid() {
# Number of registered runners in PID file
[ -f $RUNNERS_PID ] && RUNNERS_REGISTERED=`cat $RUNNERS_PID | wc -l`
# Number of active runner processes
RUNNERS_RUNNING=`ps -ef | grep "$PROCESS_NAME" | grep -v grep | wc -l`
echo "Number of registered runners in PID file=$RUNNERS_REGISTERED"
echo "Number of running runners=$RUNNERS_RUNNING"
PROCESS_ID=0
[ -f $RUNNER_PID ] && PROCESS_ID=`cat $RUNNER_PID`
if [ $PROCESS_ID -ne 0 ]; then
echo "runner is running with PID = $PROCESS_ID"
fi
}
 
execute() {
sudo -u $APP_USER -H bash -l -c "$1"
}
}
 
start() {
cd $APP_ROOT
check_pid
if [ "$RUNNERS_REGISTERED" -ne 0 -o "$RUNNERS_RUNNING" -ne 0 ]; then
if [ $PROCESS_ID -ne 0 ]; then
# Program is running, Exit with error code.
echo "Error! $DESC(s) ($NAME) appear to be running already! Try stopping them first. Exiting."
exit 1
else
if [ `whoami` = root ]; then
[ ! -f $PID_PATH ] && execute "mkdir -p $PID_PATH"
[ -f $RUNNERS_PID ] && execute "rm -f $RUNNERS_PID"
# Spawn runners
for (( i=1; i<=$RUNNERS_NUM; i++ ))
do
# Check log file
if [ ! -f $INIT_LOG ]; then
touch $INIT_LOG
chown $APP_USER $INIT_LOG
fi
echo "Starting runner #$i"
execute "$START_RUNNER >> $INIT_LOG 2>&1 & echo \$! >> $RUNNERS_PID"
done
echo "SUCCESS: Started $RUNNERS_NUM $DESC(s)."
[ -f $RUNNER_PID ] && execute "rm -f $RUNNER_PID"
# Check log file
if [ ! -f $INIT_LOG ]; then
touch $INIT_LOG
chown $APP_USER $INIT_LOG
fi
execute "$START_RUNNER >> $INIT_LOG 2>&1 & echo \$! >> $RUNNER_PID"
check_pid
fi
fi
}
 
stop() {
check_pid
# Exit if there are no runners
if [ $RUNNERS_REGISTERED -eq 0 -a $RUNNERS_RUNNING -eq 0 ]; then
echo "No runners have been found. Exiting."
fi
# Runners found. Check if there are any ghost runners.
KILL_GHOSTS=0;
if [ $RUNNERS_REGISTERED -ne $RUNNERS_RUNNING ]; then
echo "WARNING: Numbers of registered runners don't match number of running runners. Will try to stop them all"
echo "Registered runners=$RUNNERS_REGISTERED"
echo "Running runners=$RUNNERS_RUNNING"
KILL_GHOSTS=1;
fi
echo -n "Trying to stop registered runners..."
if [ $RUNNERS_REGISTERED -gt 0 ]; then
execute "cat $RUNNERS_PID | xargs kill -USR2"
rm -f $RUNNERS_PID
echo -n "Trying to stop registered runner..."
if [ $PROCESS_ID -gt 0 ]; then
execute "cat $RUNNER_PID | xargs kill -USR2"
rm -f $RUNNER_PID
echo "OK"
else
echo "FAILED!"
echo "Couldn't stop registered runners as there is no record of such in $RUNNERS_PID file".
fi
if [ $KILL_GHOSTS -eq 1 ]; then
echo -ne "Trying to kill ghost runners..."
ps -C "$PROCESS_NAME" -o "%p" h | xargs kill -USR2
[ $? -eq 0 ] && echo "OK"
else
echo "No ghost runners have been found.This is good."
echo "Couldn't stop registered runner as there is no record of such in $RUNNER_PID file".
fi
}
 
Loading
Loading
@@ -135,5 +103,3 @@ case "$1" in
esac
 
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment