Skip to content

Commit 0ed83e9

Browse files
committed
freebsd: migrate playbooks
A few things going on here: - move into the new {{id}} strategy where we use hostname - merge parts of the initial digitalocean migration pr - split variables meant for change into jenkins.conf - simplify all the things
1 parent 3a65bc8 commit 0ed83e9

File tree

5 files changed

+86
-53
lines changed

5 files changed

+86
-53
lines changed

setup/freebsd/README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# io.js Build FreeBSD Setup
22

3-
The current FreeBSD lives at Digitalocean.
3+
The current FreeBSD VMs lives at Digitalocean.
4+
5+
You have to install `python` before running ansible. Log in to the VM
6+
and run the following:
7+
```
8+
sudo pkg update && sudo pkg install -y python
9+
```
410

511
To set up hosts, make sure you add them to your ssh config first:
612
```
@@ -13,14 +19,12 @@ Host test-digitalocean-freebsd10-x64-2
1319
User freebsd
1420
```
1521

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.
22+
Note that these hostnames are also used in the ansible-inventory file.
23+
The IP addresses will need to be updated each time
24+
the servers are reprovisioned.
1725

1826
To set up a host, run:
1927

2028
```text
2129
$ ansible-playbook -i ../ansible-inventory ansible-playbook.yaml
2230
```
23-
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.

setup/freebsd/ansible-playbook.yaml

+34-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
- hosts: iojs-freebsd10
32

43
remote_user: freebsd
@@ -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

@@ -49,22 +48,36 @@
4948
command: curl -sL https://ci.nodejs.org/jnlpJars/slave.jar -o /home/{{ server_user }}/slave.jar
5049
tags: jenkins
5150

52-
- name: Jenkins | Copy init script
53-
copy: src=./resources/jenkins dest={{ init_script_path }} owner={{ server_user }} group={{ server_user }} mode=0755
54-
tags: jenkins
55-
56-
- name: Jenkins | Copy secret into init script
57-
replace: dest={{ init_script_path }} regexp="\{\{secret\}\}" replace="{{ server_secret }}"
58-
tags: jenkins
59-
60-
- name: Jenkins | Copy server id into init script
61-
replace: dest={{ init_script_path }} regexp="\{\{id\}\}" replace="{{ server_id }}"
62-
tags: jenkins
63-
64-
- name: Jenkins | Enable init script at startup
65-
lineinfile: dest=/etc/rc.conf line="jenkins_enable=YES"
66-
tags: jenkins
67-
68-
- name: Jenkins | Start service
69-
command: service jenkins start
70-
tags: jenkins
51+
- name: Assures that {{ init_base }}/{rc.d, rc.conf.d} directories exists
52+
file: path={{ init_base }}/{{ item }} state=directory
53+
with_items:
54+
- rc.d
55+
- rc.conf.d
56+
tags: init
57+
58+
- name: Init | Copy init script
59+
copy: src=./resources/jenkins dest={{ init_base }}/rc.d/jenkins owner={{ server_user }} group={{ server_user }} mode=0755
60+
tags: init
61+
62+
- name: Init | Copy config template
63+
copy: src=./resources/jenkins.conf dest={{ init_base }}/rc.conf.d/jenkins owner={{ server_user }} group={{ server_user }} mode=0600
64+
tags: init
65+
66+
- name: Init | Copy secret to config`
67+
replace: dest={{ init_base }}/rc.conf.d/jenkins regexp="\{\{secret\}\}" replace="{{ server_secret }}"
68+
tags: init
69+
70+
- name: Init | Copy user/group to config`
71+
replace: dest={{ init_base }}/rc.conf.d/jenkins regexp="\{\{{{item}}\}\}" replace="{{ server_user }}"
72+
with_items:
73+
- user
74+
- group
75+
tags: init
76+
77+
- name: Init | Copy id to config
78+
replace: dest={{ init_base }}/rc.conf.d/jenkins regexp="\{\{id\}\}" replace="{{ inventory_hostname }}"
79+
tags: init
80+
81+
- name: Init | Add to boot and start service
82+
service: name=jenkins state=started enabled=yes
83+
tags: init

setup/freebsd/ansible-vars.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
22
server_user: iojs
3-
init_script_path: /usr/local/etc/rc.d/jenkins
3+
init_base: /usr/local/etc/
44
ssh_users:
55
- rvagg
66
- jbergstroem
7+
- joaocgreis
78
packages:
8-
- openjdk-jre
9+
- openjdk
910
- git
1011
- gmake
1112
- ccache

setup/freebsd/resources/jenkins

+35-24
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
#!/bin/sh
22

3-
# $FreeBSD: $
43
#
5-
# Based on the jenkins init script
6-
#
7-
# PROVIDE: jenkins-iojs
4+
# PROVIDE: jenkins
85
# REQUIRE: LOGIN
96
# KEYWORD: shutdown
10-
117
#
128
# Configuration settings for jenkins in /etc/rc.conf:
139
#
@@ -21,40 +17,42 @@
2117
name="jenkins"
2218
rcvar=jenkins_enable
2319

24-
load_rc_config "${name}"
25-
20+
load_rc_config ${name}
2621

27-
OSTYPE="freebsd"
28-
NODE_COMMON_PIPE="/home/iojs/test.pipe"
2922
PATH="/usr/local/libexec/ccache:/usr/local/bin:${PATH}"
23+
NODE_COMMON_PIPE="/home/iojs/test.pipe"
3024

31-
jenkins_jnlpurl="https://ci.nodejs.org/computer/{{id}}/slave-agent.jnlp"
32-
jenkins_secret="{{secret}}"
3325
jenkins_jar="/home/iojs/slave.jar"
34-
jenkins_log_file="/home/iojs/jenkins_console.log"
35-
jenkins_args="-jnlpUrl ${jenkins_jnlpurl} -secret ${jenkins_secret}"
36-
jenkins_user="iojs"
37-
jenkins_group="iojs"
26+
jenkins_log_file="/home/${jenkins_user}/${name}_console.log"
27+
jenkins_args="-jar ${jenkins_jar} \
28+
-jnlpUrl ${jenkins_jnlpurl} \
29+
-secret ${jenkins_secret}"
3830
jenkins_jobs="$(getconf NPROCESSORS_ONLN)"
3931

40-
pidfile="/var/run/jenkins/jenkins.pid"
32+
# FreeBSD uses a java wrapper. Without full path pid monitoring won't work
33+
procname=`cat /usr/local/etc/javavms | cut -d "#" -f 1`
34+
pidfile="/var/run/${name}/${name}.pid"
35+
monitor_pidfile="/var/run/${name}/${name}_monitor.pid"
4136
command="/usr/sbin/daemon"
42-
procname="/usr/local/openjdk7-jre/bin/java"
43-
command_args="-r -p ${pidfile} ${procname} -jar ${jenkins_jar} ${jenkins_args} > ${jenkins_log_file} 2>&1"
44-
env="PATH=${PATH} JOBS=${jenkins_jobs} OSTYPE=${OSTYPE} NODE_COMMON_PIPE=${NODE_COMMON_PIPE} CC=cc CXX=c++"
37+
command_args="-r -p ${pidfile} -P ${monitor_pidfile} ${procname} \
38+
${jenkins_args} > ${jenkins_log_file} 2>&1"
39+
env="PATH=${PATH} JOBS=${jenkins_jobs} OSTYPE=${OSTYPE} \
40+
NODE_COMMON_PIPE=${NODE_COMMON_PIPE} CC=cc CXX=c++"
4541
required_files="${procname} ${jenkins_jar}"
4642

47-
start_precmd="jenkins_prestart"
48-
start_cmd="jenkins_start"
43+
start_precmd="${name}_prestart"
44+
start_cmd="${name}_start"
45+
stop_cmd="${name}_stop"
4946

5047
jenkins_prestart() {
5148
if [ ! -f "${jenkins_log_file}" ]; then
5249
touch "${jenkins_log_file}"
5350
chown "${jenkins_user}:${jenkins_group}" "${jenkins_log_file}"
5451
chmod 640 "${jenkins_log_file}"
5552
fi
56-
if [ ! -d "/var/run/jenkins" ]; then
57-
install -d -o "${jenkins_user}" -g "${jenkins_group}" -m 750 "/var/run/jenkins"
53+
if [ ! -d `basename ${pidfile}` ]; then
54+
install -d -o "${jenkins_user}" -g "${jenkins_group}" \
55+
-m 750 `basename ${pidfile}`
5856
fi
5957

6058
if [ ! $jenkins_secret ]; then
@@ -64,8 +62,21 @@ jenkins_prestart() {
6462

6563
jenkins_start()
6664
{
67-
check_startmsgs && echo "Starting ${name}."
65+
check_startmsgs && echo -n "Starting ${name}"
6866
su -l ${jenkins_user} -c "${env} exec ${command} ${command_args}"
67+
echo .
68+
}
69+
70+
jenkins_stop()
71+
{
72+
if [ ! -f ${pidfile} ]; then
73+
echo "${name} isn't running."
74+
else
75+
echo -n "Stopping service: ${name}"
76+
kill `cat ${monitor_pidfile}`
77+
rm ${pidfile} ${monitor_pidfile}
78+
echo .
79+
fi
6980
}
7081

7182
run_rc_command "$1"

setup/freebsd/resources/jenkins.conf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
jenkins_jnlpurl="https://ci.nodejs.org/computer/{{id}}/slave-agent.jnlp"
2+
jenkins_secret="{{secret}}"
3+
jenkins_user="{{user}}"
4+
jenkins_group="{{group}}"

0 commit comments

Comments
 (0)