]>
Commit | Line | Data |
---|---|---|
af21cb3e ER |
1 | #! /bin/bash |
2 | ||
3 | ### BEGIN INIT INFO | |
4 | # Provides: gitlab-ci-multi-runner | |
5 | # Required-Start: $local_fs $remote_fs $network $syslog | |
6 | # Required-Stop: $local_fs $remote_fs $network $syslog | |
7 | # Default-Start: 2 3 4 5 | |
8 | # Default-Stop: 0 1 6 | |
9 | # Short-Description: GitLab CI-Multi Runner init.d script | |
10 | # Description: Enables automatic start of runners at boot time in the background. | |
11 | ### END INIT INFO | |
12 | ||
13 | DESC="GitLab CI-Multi Runner" | |
14 | USER="gitlab_ci_multi_runner" | |
15 | GROUP="gitlab_ci_multi_runner" | |
16 | CHDIR="~$USER" | |
17 | NAME="gitlab-ci-multi-runner" | |
18 | DAEMON="/usr/bin/gitlab-ci-multi-runner" | |
19 | PIDFILE="/var/run/gitlab-ci-multi-runner.pid" | |
20 | LOGFILE="/var/log/gitlab-ci-multi-runner.log" | |
21 | ||
22 | # Exit if the package is not installed | |
23 | if [ ! -x "$DAEMON" ]; then | |
24 | echo "$DAEMON not present or not executable" | |
25 | exit 1 | |
26 | fi | |
27 | ||
28 | # Read configuration variable file if it is present | |
29 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME | |
30 | ||
31 | # Define LSB log_* functions. | |
32 | . /lib/lsb/init-functions | |
33 | ||
34 | ## Check to see if we are running as root first. | |
35 | if [ "$(id -u)" != "0" ]; then | |
36 | echo "This script must be run as root" | |
37 | exit 1 | |
38 | fi | |
39 | ||
40 | eval CHDIR=$CHDIR | |
41 | ||
42 | do_start() { | |
43 | start-stop-daemon --start \ | |
44 | --pidfile "$PIDFILE" \ | |
45 | --chdir "$CHDIR" \ | |
46 | --background \ | |
47 | --make-pidfile \ | |
48 | --chuid "$USER:$GROUP" \ | |
49 | --no-close \ | |
50 | --exec "$DAEMON" -- "run" &>> $LOGFILE | |
51 | } | |
52 | ||
53 | do_stop() { | |
54 | start-stop-daemon --stop --pidfile "$PIDFILE" --user "$USER" --exec "$DAEMON" --quiet | |
55 | } | |
56 | ||
57 | case "$1" in | |
58 | start) | |
59 | log_daemon_msg "Starting $DESC" | |
60 | do_start | |
61 | log_end_msg $? | |
62 | ;; | |
63 | stop) | |
64 | log_daemon_msg "Stopping $DESC" | |
65 | do_stop | |
66 | log_end_msg $? | |
67 | ;; | |
68 | restart) | |
69 | $0 stop | |
70 | $0 start | |
71 | ;; | |
72 | status) | |
73 | status_of_proc -p "$PIDFILE" "$DAEMON" "$DESC" | |
74 | ;; | |
75 | *) | |
76 | echo "Usage: sudo service gitlab-ci-multi-runner {start|stop|restart|status}" >&2 | |
77 | exit 1 | |
78 | ;; | |
79 | esac | |
80 | ||
81 | exit 0 |