Skip to content
This repository was archived by the owner on May 12, 2018. It is now read-only.

Commit 65a0e1c

Browse files
committed
Merge branch 'master' of dev.gitlab.org:gitlab/gitlab-ci-runner
2 parents 7e02158 + 264fadc commit 65a0e1c

File tree

2 files changed

+26
-60
lines changed

2 files changed

+26
-60
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ a) Linux
4646

4747
```bash
4848
mkdir /tmp/ruby && cd /tmp/ruby
49-
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
50-
cd ruby-2.0.0-p353
49+
curl --progress http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz | tar xz
50+
cd ruby-2.1.5
5151
./configure --disable-install-rdoc
5252
make
5353
sudo make install

lib/support/init.d/gitlab_ci_runner

Lines changed: 24 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,92 +14,60 @@ APP_ROOT="/home/gitlab_ci_runner/gitlab-ci-runner"
1414
APP_USER="gitlab_ci_runner"
1515
PID_PATH="$APP_ROOT/tmp/pids"
1616
PROCESS_NAME="ruby ./bin/runner"
17-
RUNNERS_PID="$PID_PATH/runners.pid"
18-
RUNNERS_NUM=1 # number of runners to spawn
17+
RUNNER_PID="$PID_PATH/runners.pid"
1918
START_RUNNER="nohup bundle exec ./bin/runner"
2019
NAME="gitlab-ci-runner"
2120
DESC="GitLab CI runner"
2221
RUNNERS_REGISTERED=0
23-
RUNNERS_RUNNING=0
2422
INIT_LOG="/var/log/gitlab_ci_runner.log"
2523

2624
check_pid() {
27-
# Number of registered runners in PID file
28-
[ -f $RUNNERS_PID ] && RUNNERS_REGISTERED=`cat $RUNNERS_PID | wc -l`
29-
30-
# Number of active runner processes
31-
RUNNERS_RUNNING=`ps -ef | grep "$PROCESS_NAME" | grep -v grep | wc -l`
32-
33-
34-
echo "Number of registered runners in PID file=$RUNNERS_REGISTERED"
35-
echo "Number of running runners=$RUNNERS_RUNNING"
25+
PROCESS_ID=0
26+
[ -f $RUNNER_PID ] && PROCESS_ID=`cat $RUNNER_PID`
27+
if [ $PROCESS_ID -ne 0 ]; then
28+
echo "runner is running with PID = $PROCESS_ID"
29+
fi
3630
}
3731

3832
execute() {
3933
sudo -u $APP_USER -H bash -l -c "$1"
40-
}
34+
}
4135

4236
start() {
4337
cd $APP_ROOT
4438
check_pid
45-
if [ "$RUNNERS_REGISTERED" -ne 0 -o "$RUNNERS_RUNNING" -ne 0 ]; then
39+
if [ $PROCESS_ID -ne 0 ]; then
4640
# Program is running, Exit with error code.
4741
echo "Error! $DESC(s) ($NAME) appear to be running already! Try stopping them first. Exiting."
4842
exit 1
4943
else
5044
if [ `whoami` = root ]; then
5145
[ ! -f $PID_PATH ] && execute "mkdir -p $PID_PATH"
52-
[ -f $RUNNERS_PID ] && execute "rm -f $RUNNERS_PID"
53-
54-
# Spawn runners
55-
for (( i=1; i<=$RUNNERS_NUM; i++ ))
56-
do
57-
# Check log file
58-
if [ ! -f $INIT_LOG ]; then
59-
touch $INIT_LOG
60-
chown $APP_USER $INIT_LOG
61-
fi
62-
echo "Starting runner #$i"
63-
execute "$START_RUNNER >> $INIT_LOG 2>&1 & echo \$! >> $RUNNERS_PID"
64-
done
65-
echo "SUCCESS: Started $RUNNERS_NUM $DESC(s)."
46+
[ -f $RUNNER_PID ] && execute "rm -f $RUNNER_PID"
47+
48+
49+
# Check log file
50+
if [ ! -f $INIT_LOG ]; then
51+
touch $INIT_LOG
52+
chown $APP_USER $INIT_LOG
53+
fi
54+
execute "$START_RUNNER >> $INIT_LOG 2>&1 & echo \$! >> $RUNNER_PID"
55+
check_pid
6656
fi
67-
6857
fi
6958
}
7059

7160
stop() {
7261
check_pid
73-
# Exit if there are no runners
74-
if [ $RUNNERS_REGISTERED -eq 0 -a $RUNNERS_RUNNING -eq 0 ]; then
75-
echo "No runners have been found. Exiting."
76-
fi
77-
78-
# Runners found. Check if there are any ghost runners.
79-
KILL_GHOSTS=0;
80-
if [ $RUNNERS_REGISTERED -ne $RUNNERS_RUNNING ]; then
81-
echo "WARNING: Numbers of registered runners don't match number of running runners. Will try to stop them all"
82-
echo "Registered runners=$RUNNERS_REGISTERED"
83-
echo "Running runners=$RUNNERS_RUNNING"
84-
KILL_GHOSTS=1;
85-
fi
86-
87-
echo -n "Trying to stop registered runners..."
88-
if [ $RUNNERS_REGISTERED -gt 0 ]; then
89-
execute "cat $RUNNERS_PID | xargs kill -USR2"
90-
rm -f $RUNNERS_PID
62+
echo -n "Trying to stop registered runner..."
63+
64+
if [ $PROCESS_ID -gt 0 ]; then
65+
execute "cat $RUNNER_PID | xargs kill -USR2"
66+
rm -f $RUNNER_PID
9167
echo "OK"
9268
else
9369
echo "FAILED!"
94-
echo "Couldn't stop registered runners as there is no record of such in $RUNNERS_PID file".
95-
fi
96-
97-
if [ $KILL_GHOSTS -eq 1 ]; then
98-
echo -ne "Trying to kill ghost runners..."
99-
ps -C "$PROCESS_NAME" -o "%p" h | xargs kill -USR2
100-
[ $? -eq 0 ] && echo "OK"
101-
else
102-
echo "No ghost runners have been found.This is good."
70+
echo "Couldn't stop registered runner as there is no record of such in $RUNNER_PID file".
10371
fi
10472
}
10573

@@ -135,5 +103,3 @@ case "$1" in
135103
esac
136104

137105
exit 0
138-
139-

0 commit comments

Comments
 (0)