-
-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathfreebsd.initd.j2
More file actions
89 lines (74 loc) · 2.37 KB
/
freebsd.initd.j2
File metadata and controls
89 lines (74 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
#
# PROVIDE: jenkins
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Configuration settings for jenkins in /etc/rc.conf:
#
# jenkins_enable (bool):
# Set to "NO" by default.
# Set it to "YES" to enable jenkins
#
. /etc/rc.subr
name="jenkins"
rcvar="jenkins_enable"
load_rc_config ${name}
: ${jenkins_enable:=NO}
jenkins_env=" \
HOME=/usr/home/{{ server_user }} \
OSTYPE=freebsd \
NODE_COMMON_PIPE=/home/{{ server_user }}/test.pipe \
NODE_TEST_DIR=/home/{{ server_user }}/tmp \
PATH=/usr/local/libexec/ccache:/usr/local/bin:${PATH} \
JOBS={{ jobs_env|default('2') }} \
CC=cc \
CXX=c++"
jenkins_jar="/home/{{ server_user }}/agent.jar"
jenkins_log_file="/home/{{ server_user }}/${name}_console.log"
jenkins_args="-Xmx{{ server_ram|default('128m') }} -jar ${jenkins_jar} \
-url {{ jenkins_url }} -name {{ inventory_hostname }} \
-secret {{ secret }}"
jenkins_user="{{ server_user }}"
jenkins_group="{{ server_user }}"
# FreeBSD uses a java wrapper. Without full path pid monitoring won't work
procname=$(cat /usr/local/etc/javavms | cut -d "#" -f 1)
pidfile="/var/run/${name}/${name}.pid"
monitor_pidfile="/var/run/${name}/${name}_monitor.pid"
required_files="${procname} ${jenkins_jar}"
command="/usr/sbin/daemon"
command_args="-f -r -p ${pidfile} -P ${monitor_pidfile} -o ${jenkins_log_file} \
${procname} ${jenkins_args}"
start_precmd="jenkins_prestart"
start_cmd="jenkins_start"
stop_cmd="jenkins_stop"
jenkins_prestart() {
if [ ! -f "${jenkins_log_file}" ]; then
touch "${jenkins_log_file}"
chown "{{ server_user }}:{{ server_user }}" "${jenkins_log_file}"
chmod 640 "${jenkins_log_file}"
fi
if [ ! -d $(dirname ${pidfile}) ]; then
install -d -o "{{ server_user }}" -g "{{ server_user }}" \
-m 755 $(dirname ${pidfile})
fi
}
# need to override _start since it doesn't seem to pass env in FreeBSD 11
jenkins_start() {
echo "Starting service: ${name}."
su -l ${jenkins_user} -c "exec env ${jenkins_env} \
${command} ${command_args}"
}
# Kill monitor, not java since it would respawn
jenkins_stop() {
if [ ! -f ${pidfile} -a ! -f ${monitor_pidfile} ]; then
echo "${name} isn't running."
else
echo -n "Stopping service: ${name}"
kill `cat ${monitor_pidfile}`
# files are removed on exit, but be extra sure
rm -f ${pidfile} ${monitor_pidfile}
echo .
fi
}
run_rc_command "$1"