Skip to content

Commit dd2f493

Browse files
committed
freebsd: refactor init scripts
Improve the daemon monitoring facility by avoiding `su` as part of starting the script. Also, modernise playbooks and update README.md PR-URL: #391 Reviewed-By: Rod Vagg <[email protected]>
1 parent c7e244b commit dd2f493

File tree

10 files changed

+215
-216
lines changed

10 files changed

+215
-216
lines changed

setup/freebsd/README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# io.js Build FreeBSD Setup
22

3-
The current FreeBSD lives at Digitalocean.
3+
## Setting up
44

55
To set up hosts, make sure you add them to your ssh config first:
66
```
@@ -13,14 +13,19 @@ Host test-digitalocean-freebsd10-x64-2
1313
User freebsd
1414
```
1515

16-
Note that these hostnames are also used in the ansible-inventory file. The IP addresses will need to be updated each time the servers are reprovisioned.
17-
18-
To set up a host, run:
16+
You will also have to install python (ansible dependency):
17+
```bash
18+
$ ssh test-digitalocean-freebsd10-x64-1 sudo pkg install -y python
19+
```
1920

20-
```text
21+
Now you're ready to run the playbook:
22+
```bash
2123
$ ansible-playbook -i ../ansible-inventory ansible-playbook.yaml
2224
```
2325

24-
**Users**: The ansible-vars.yaml file contains a list of users who's GitHub public keys are pulled and placed into
25-
authorized_keys for both root and iojs users. This file should be updates when new users are added to the build project
26-
who are able to help maintain the containerized builds.
26+
## Restarting jenkins
27+
28+
If you ever need to restart jenkins:
29+
```bash
30+
$ ssh test-digitalocean-freebsd10-x64-1 sudo service jenkins restart
31+
```

setup/freebsd/ansible-playbook.yaml

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
- ansible_python_interpreter: "/usr/bin/env python"
99

1010
tasks:
11-
1211
- include_vars: ansible-vars.yaml
1312
tags: vars
1413

@@ -17,7 +16,7 @@
1716
tags: general
1817

1918
- name: General | Install required packages
20-
command: pkg install -U -y {{ item }}
19+
command: pkg install -U -y {{ item }}
2120
with_items: packages
2221
tags: general
2322

@@ -26,30 +25,17 @@
2625
tags: user
2726

2827
- name: User | Add {{ server_user }} user
29-
user: name="{{ server_user }}" shell=/bin/sh append=yes groups={{ server_user }}
28+
user: name="{{ server_user }}" append=yes groups={{ server_user }}
3029
tags: user
3130

32-
3331
- name: Jenkins | Download Jenkins' slave.jar
34-
command: curl -sL https://ci.nodejs.org/jnlpJars/slave.jar -o /home/{{ server_user }}/slave.jar
35-
tags: jenkins
36-
37-
- name: Jenkins | Copy init script
38-
copy: src=./resources/jenkins dest={{ init_script_path }} owner={{ server_user }} group={{ server_user }} mode=0755
39-
tags: jenkins
40-
41-
- name: Jenkins | Copy secret into init script
42-
replace: dest={{ init_script_path }} regexp="\{\{secret\}\}" replace="{{ server_secret }}"
32+
get_url: url=https://ci.nodejs.org/jnlpJars/slave.jar dest=/home/{{ server_user }}
4333
tags: jenkins
4434

45-
- name: Jenkins | Copy server id into init script
46-
replace: dest={{ init_script_path }} regexp="\{\{id\}\}" replace="{{ server_id }}"
47-
tags: jenkins
35+
- name: Init | Generate and copy init script
36+
template: src=./resources/jenkins.j2 dest=/usr/local/etc/rc.d
37+
tags: init
4838

49-
- name: Jenkins | Enable init script at startup
50-
lineinfile: dest=/etc/rc.conf line="jenkins_enable=YES"
51-
tags: jenkins
52-
53-
- name: Jenkins | Start service
54-
command: service jenkins start
55-
tags: jenkins
39+
- name: Init | Start Jenkins
40+
service: name=jenkins state=started enabled=yes
41+
tags: init

setup/freebsd/ansible-vars.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
server_user: iojs
3-
init_script_path: /usr/local/etc/rc.d/jenkins
43
packages:
54
- openjdk-jre
65
- git

setup/freebsd/resources/jenkins

Lines changed: 0 additions & 71 deletions
This file was deleted.

setup/freebsd/resources/jenkins.j2

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/sh
2+
3+
#
4+
# PROVIDE: jenkins
5+
# REQUIRE: LOGIN
6+
# KEYWORD: shutdown
7+
#
8+
# Configuration settings for jenkins in /etc/rc.conf:
9+
#
10+
# jenkins_enable (bool):
11+
# Set to "NO" by default.
12+
# Set it to "YES" to enable jenkins
13+
#
14+
15+
. /etc/rc.subr
16+
17+
name="jenkins"
18+
rcvar="jenkins_enable"
19+
load_rc_config ${name}
20+
21+
# generated by ansible
22+
jenkins_jnlpurl="https://ci.nodejs.org/computer/{{ inventory_hostname }}/slave-agent.jnlp"
23+
jenkins_secret="{{ secret }}"
24+
jenkins_user="{{ server_user }}"
25+
jenkins_group="{{ server_user }}"
26+
# end generated by ansible
27+
28+
required_files="${procname} ${jenkins_jar}"
29+
30+
jenkins_env=" \
31+
OSTYPE=freebsd \
32+
NODE_COMMON_PIPE=/home/${jenkins_user}/test.pipe \
33+
PATH=/usr/local/libexec/ccache:/usr/local/bin:${PATH} \
34+
JOBS=$(getconf NPROCESSORS_ONLN) \
35+
CC=cc \
36+
CXX=c++"
37+
38+
jenkins_jar="/home/${jenkins_user}/slave.jar"
39+
jenkins_log_file="/home/${jenkins_user}/${name}_console.log"
40+
jenkins_args="-jar ${jenkins_jar} \
41+
-jnlpUrl ${jenkins_jnlpurl} \
42+
-secret ${jenkins_secret}"
43+
44+
# FreeBSD uses a java wrapper. Without full path pid monitoring won't work
45+
procname=$(cat /usr/local/etc/javavms | cut -d "#" -f 1)
46+
pidfile="/var/run/${name}/${name}.pid"
47+
monitor_pidfile="/var/run/${name}/${name}_monitor.pid"
48+
49+
command="/usr/sbin/daemon"
50+
command_args="-f -r -p ${pidfile} -P ${monitor_pidfile} ${procname} \
51+
${jenkins_args} -slaveLog ${jenkins_log_file}"
52+
53+
start_precmd="${name}_prestart"
54+
stop_cmd="${name}_stop"
55+
56+
jenkins_prestart() {
57+
if [ ! -f "${jenkins_log_file}" ]; then
58+
touch "${jenkins_log_file}"
59+
chown "${jenkins_user}:${jenkins_group}" "${jenkins_log_file}"
60+
chmod 640 "${jenkins_log_file}"
61+
fi
62+
if [ ! -d $(dirname ${pidfile}) ]; then
63+
install -d -o "${jenkins_user}" -g "${jenkins_group}" \
64+
-m 750 $(dirname ${pidfile})
65+
fi
66+
67+
if [ ! ${jenkins_secret} ]; then
68+
err 1 "You need to add a jenkins secret"
69+
fi
70+
}
71+
72+
# Kill monitor, not java since it would respawn
73+
jenkins_stop()
74+
{
75+
if [ ! -f ${pidfile} -a ! -f ${monitor_pidfile} ]; then
76+
echo "${name} isn't running."
77+
else
78+
echo -n "Stopping service: ${name}"
79+
kill `cat ${monitor_pidfile}`
80+
# files are removed on exit, but be extra sure
81+
rm -f ${pidfile} ${monitor_pidfile}
82+
echo .
83+
fi
84+
}
85+
86+
run_rc_command "$1"

setup/linter/README.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# io.js Build Linter Setup
22

3-
These machines (currently just one) are run as part of the jenkins job,
4-
linting any code before passing it on to compile/test.
3+
## Setting up
54

65
To set up hosts, make sure you add them to your ssh config first:
76
```
@@ -12,22 +11,20 @@ Host lint-joyent-freebsd10-x64-1
1211
HostName 72.2.114.23
1312
```
1413

15-
Note that these hostnames are also used in the ansible-inventory file.
16-
The IP addresses will need to be updated each time the servers
17-
are reprovisioned.
18-
19-
Before running ansible you need to install Python (2.x):
14+
You will also have to install python (ansible dependency):
15+
```bash
16+
$ ssh lint-joyent-freebsd10-x64-1 sudo pkg install -y python
2017
```
21-
$ ssh freebsd@iojs-linter1 sudo pkg install -y python
18+
19+
Now you're ready to run the playbook:
20+
```bash
21+
$ ansible-playbook -i ../ansible-inventory ansible-playbook.yaml
2222
```
2323

24-
To set up a host, run:
24+
## Restarting jenkins
2525

26-
```text
27-
$ ansible-playbook -i ../ansible-inventory ansible-playbook.yaml
26+
If you ever need to restart jenkins:
27+
```bash
28+
$ ssh lint-joyent-freebsd10-x64-1 sudo service jenkins restart
2829
```
2930

30-
**Users**: The ansible-vars.yaml file contains a list of users whose GitHub
31-
public keys are pulled and placed into authorized_keys for both root and
32-
iojs users. This file should be updates when new users are added to the
33-
build project who are able to help maintain the containerized builds.

setup/linter/ansible-playbook.yaml

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
- ansible_python_interpreter: "/usr/bin/env python"
99

1010
tasks:
11-
1211
- include_vars: ansible-vars.yaml
1312
tags: vars
1413

@@ -17,7 +16,7 @@
1716
tags: general
1817

1918
- name: General | Install required packages
20-
command: pkg install -U -y {{ item }}
19+
command: pkg install -U -y {{ item }}
2120
with_items: packages
2221
tags: general
2322

@@ -26,33 +25,17 @@
2625
tags: user
2726

2827
- name: User | Add {{ server_user }} user
29-
user: name="{{ server_user }}" shell=/bin/sh append=yes groups={{ server_user }}
28+
user: name="{{ server_user }}" append=yes groups={{ server_user }}
3029
tags: user
3130

32-
- name: General | Keep iojs up to date
33-
cron: name="update iojs" minute="0" hour="0" day="*/7" job="pkg update -q && pkg upgrade -yq iojs >/dev/null 2>&1"
34-
tags: cron
35-
3631
- name: Jenkins | Download Jenkins' slave.jar
37-
command: curl -sL https://ci.nodejs.org/jnlpJars/slave.jar -o /home/{{ server_user }}/slave.jar
38-
tags: jenkins
39-
40-
- name: Jenkins | Copy init script
41-
copy: src=./resources/jenkins dest={{ init_script_path }} owner={{ server_user }} group={{ server_user }} mode=0755
42-
tags: jenkins
43-
44-
- name: Jenkins | Copy secret into init script
45-
replace: dest={{ init_script_path }} regexp="\{\{secret\}\}" replace="{{ server_secret }}"
32+
get_url: url=https://ci.nodejs.org/jnlpJars/slave.jar dest=/home/{{ server_user }}
4633
tags: jenkins
4734

48-
- name: Jenkins | Copy server id into init script
49-
replace: dest={{ init_script_path }} regexp="\{\{id\}\}" replace="{{ server_id }}"
50-
tags: jenkins
35+
- name: Init | Generate and copy init script
36+
template: src=./resources/jenkins.j2 dest=/usr/local/etc/rc.d
37+
tags: init
5138

52-
- name: Jenkins | Enable init script at startup
53-
lineinfile: dest=/etc/rc.conf line="jenkins_enable=YES"
54-
tags: jenkins
55-
56-
- name: Jenkins | Start service
57-
command: service jenkins start
58-
tags: jenkins
39+
- name: Init | Start Jenkins
40+
service: name=jenkins state=started enabled=yes
41+
tags: init

setup/linter/ansible-vars.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
22
server_user: iojs
3-
init_script_path: /usr/local/etc/rc.d/jenkins
43
packages:
54
- openjdk
65
- git
76
- gmake
87
- ccache
98
- node
10-
- llvm-devel

0 commit comments

Comments
 (0)