Skip to content

Commit

Permalink
freebsd: migrate playbooks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jbergstroem committed Nov 24, 2015
1 parent 3a65bc8 commit 0ed83e9
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 53 deletions.
16 changes: 10 additions & 6 deletions setup/freebsd/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# io.js Build FreeBSD Setup

The current FreeBSD lives at Digitalocean.
The current FreeBSD VMs lives at Digitalocean.

You have to install `python` before running ansible. Log in to the VM
and run the following:
```
sudo pkg update && sudo pkg install -y python
```

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

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.
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.

To set up a host, run:

```text
$ ansible-playbook -i ../ansible-inventory ansible-playbook.yaml
```

**Users**: The ansible-vars.yaml file contains a list of users who's GitHub public keys are pulled and placed into
authorized_keys for both root and iojs users. This file should be updates when new users are added to the build project
who are able to help maintain the containerized builds.
55 changes: 34 additions & 21 deletions setup/freebsd/ansible-playbook.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
- hosts: iojs-freebsd10

remote_user: freebsd
Expand All @@ -17,7 +16,7 @@
tags: general

- name: General | Install required packages
command: pkg install -U -y {{ item }}
command: pkg install -U -y {{ item }}
with_items: packages
tags: general

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

- name: Jenkins | Copy init script
copy: src=./resources/jenkins dest={{ init_script_path }} owner={{ server_user }} group={{ server_user }} mode=0755
tags: jenkins

- name: Jenkins | Copy secret into init script
replace: dest={{ init_script_path }} regexp="\{\{secret\}\}" replace="{{ server_secret }}"
tags: jenkins

- name: Jenkins | Copy server id into init script
replace: dest={{ init_script_path }} regexp="\{\{id\}\}" replace="{{ server_id }}"
tags: jenkins

- name: Jenkins | Enable init script at startup
lineinfile: dest=/etc/rc.conf line="jenkins_enable=YES"
tags: jenkins

- name: Jenkins | Start service
command: service jenkins start
tags: jenkins
- name: Assures that {{ init_base }}/{rc.d, rc.conf.d} directories exists
file: path={{ init_base }}/{{ item }} state=directory
with_items:
- rc.d
- rc.conf.d
tags: init

- name: Init | Copy init script
copy: src=./resources/jenkins dest={{ init_base }}/rc.d/jenkins owner={{ server_user }} group={{ server_user }} mode=0755
tags: init

- name: Init | Copy config template
copy: src=./resources/jenkins.conf dest={{ init_base }}/rc.conf.d/jenkins owner={{ server_user }} group={{ server_user }} mode=0600
tags: init

- name: Init | Copy secret to config`
replace: dest={{ init_base }}/rc.conf.d/jenkins regexp="\{\{secret\}\}" replace="{{ server_secret }}"
tags: init

- name: Init | Copy user/group to config`
replace: dest={{ init_base }}/rc.conf.d/jenkins regexp="\{\{{{item}}\}\}" replace="{{ server_user }}"
with_items:
- user
- group
tags: init

- name: Init | Copy id to config
replace: dest={{ init_base }}/rc.conf.d/jenkins regexp="\{\{id\}\}" replace="{{ inventory_hostname }}"
tags: init

- name: Init | Add to boot and start service
service: name=jenkins state=started enabled=yes
tags: init
5 changes: 3 additions & 2 deletions setup/freebsd/ansible-vars.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
server_user: iojs
init_script_path: /usr/local/etc/rc.d/jenkins
init_base: /usr/local/etc/
ssh_users:
- rvagg
- jbergstroem
- joaocgreis
packages:
- openjdk-jre
- openjdk
- git
- gmake
- ccache
59 changes: 35 additions & 24 deletions setup/freebsd/resources/jenkins
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#!/bin/sh

# $FreeBSD: $
#
# Based on the jenkins init script
#
# PROVIDE: jenkins-iojs
# PROVIDE: jenkins
# REQUIRE: LOGIN
# KEYWORD: shutdown

#
# Configuration settings for jenkins in /etc/rc.conf:
#
Expand All @@ -21,40 +17,42 @@
name="jenkins"
rcvar=jenkins_enable

load_rc_config "${name}"

load_rc_config ${name}

OSTYPE="freebsd"
NODE_COMMON_PIPE="/home/iojs/test.pipe"
PATH="/usr/local/libexec/ccache:/usr/local/bin:${PATH}"
NODE_COMMON_PIPE="/home/iojs/test.pipe"

jenkins_jnlpurl="https://ci.nodejs.org/computer/{{id}}/slave-agent.jnlp"
jenkins_secret="{{secret}}"
jenkins_jar="/home/iojs/slave.jar"
jenkins_log_file="/home/iojs/jenkins_console.log"
jenkins_args="-jnlpUrl ${jenkins_jnlpurl} -secret ${jenkins_secret}"
jenkins_user="iojs"
jenkins_group="iojs"
jenkins_log_file="/home/${jenkins_user}/${name}_console.log"
jenkins_args="-jar ${jenkins_jar} \
-jnlpUrl ${jenkins_jnlpurl} \
-secret ${jenkins_secret}"
jenkins_jobs="$(getconf NPROCESSORS_ONLN)"

pidfile="/var/run/jenkins/jenkins.pid"
# 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"
command="/usr/sbin/daemon"
procname="/usr/local/openjdk7-jre/bin/java"
command_args="-r -p ${pidfile} ${procname} -jar ${jenkins_jar} ${jenkins_args} > ${jenkins_log_file} 2>&1"
env="PATH=${PATH} JOBS=${jenkins_jobs} OSTYPE=${OSTYPE} NODE_COMMON_PIPE=${NODE_COMMON_PIPE} CC=cc CXX=c++"
command_args="-r -p ${pidfile} -P ${monitor_pidfile} ${procname} \
${jenkins_args} > ${jenkins_log_file} 2>&1"
env="PATH=${PATH} JOBS=${jenkins_jobs} OSTYPE=${OSTYPE} \
NODE_COMMON_PIPE=${NODE_COMMON_PIPE} CC=cc CXX=c++"
required_files="${procname} ${jenkins_jar}"

start_precmd="jenkins_prestart"
start_cmd="jenkins_start"
start_precmd="${name}_prestart"
start_cmd="${name}_start"
stop_cmd="${name}_stop"

jenkins_prestart() {
if [ ! -f "${jenkins_log_file}" ]; then
touch "${jenkins_log_file}"
chown "${jenkins_user}:${jenkins_group}" "${jenkins_log_file}"
chmod 640 "${jenkins_log_file}"
fi
if [ ! -d "/var/run/jenkins" ]; then
install -d -o "${jenkins_user}" -g "${jenkins_group}" -m 750 "/var/run/jenkins"
if [ ! -d `basename ${pidfile}` ]; then
install -d -o "${jenkins_user}" -g "${jenkins_group}" \
-m 750 `basename ${pidfile}`
fi

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

jenkins_start()
{
check_startmsgs && echo "Starting ${name}."
check_startmsgs && echo -n "Starting ${name}"
su -l ${jenkins_user} -c "${env} exec ${command} ${command_args}"
echo .
}

jenkins_stop()
{
if [ ! -f ${pidfile} ]; then
echo "${name} isn't running."
else
echo -n "Stopping service: ${name}"
kill `cat ${monitor_pidfile}`
rm ${pidfile} ${monitor_pidfile}
echo .
fi
}

run_rc_command "$1"
4 changes: 4 additions & 0 deletions setup/freebsd/resources/jenkins.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jenkins_jnlpurl="https://ci.nodejs.org/computer/{{id}}/slave-agent.jnlp"
jenkins_secret="{{secret}}"
jenkins_user="{{user}}"
jenkins_group="{{group}}"

0 comments on commit 0ed83e9

Please sign in to comment.