Skip to content

Commit afb4f98

Browse files
committed
scabot: supervised by runit
logs are in `~scabot/logs/current` simply restart by `su scabot -c 'killall -1 java'` (the scabot user runs only one java process, which will is supervised by runit) push to deploy using git-deploy (see scabot repo)
1 parent 2a84d44 commit afb4f98

File tree

8 files changed

+146
-2
lines changed

8 files changed

+146
-2
lines changed

README.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,26 @@ NOTE: the JSON must not have a field "id"!!!
126126
### Chef user with keypair for jenkins cli access
127127
```
128128
eval "$(chef shell-init zsh)" # use chef's ruby, which has the net/ssh gem
129-
ruby keypair.rb > keypair.json
129+
ruby chef/keypair.rb > ~/Desktop/chef-secrets/config/keypair.json
130+
ruby chef/keypair.rb > ~/Desktop/chef-secrets/config/scabot-keypair.json
131+
132+
# extract private key to ~/Desktop/chef-secrets/config/scabot.pem
130133
131134
knife vault create master scala-jenkins-keypair \
132-
--json keypair.json \
135+
--json ~/Desktop/chef-secrets/config/keypair.json \
133136
--search 'name:jenkins*' \
134137
--admins adriaan
138+
139+
knife vault create master scabot-keypair \
140+
--json ~/Desktop/chef-secrets/config/scabot-keypair.json \
141+
--search 'name:jenkins-master' \
142+
--admins adriaan
143+
144+
knife vault create master scabot \
145+
--json ~/Desktop/chef-secrets/config/scabot.json \
146+
--search 'name:jenkins-master' \
147+
--admins adriaan
148+
135149
```
136150

137151
### For github oauth
@@ -215,6 +229,11 @@ Host jenkins-master
215229
IdentityFile ~/Desktop/chef-secrets/config/chef.pem
216230
User ec2-user
217231
232+
Host scabot
233+
HostName jenkins-master
234+
IdentityFile ~/Desktop/chef-secrets/config/scabot.pem
235+
User scabot
236+
218237
Host jenkins-worker-windows
219238
IdentityFile ~/Desktop/chef-secrets/jenkins-chef
220239
User jenkins

attributes/master.rb

+4
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@
3232
EOH
3333

3434
default['master']['ec2-start-stop']['url'] = 'https://dl.dropboxusercontent.com/u/12862572/ec2-start-stop.hpi'
35+
36+
37+
default['scabot']['jenkins']['user'] = "scala-jenkins"
38+
default['scabot']['github']['repo_user'] = "adriaanm"

metadata.rb

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@
2222
# TODO remove chef-sbt dependency, but not sure sbt-extras supports windows
2323
depends 'chef-sbt'
2424
depends 'sbt-extras'
25+
26+
depends 'runit', '~> 1.5'

recipes/_master-config-scabot.rb

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#
2+
# Cookbook Name:: scala-jenkins-infra
3+
# Recipe:: _master-init-scabot
4+
#
5+
# Copyright 2014, Typesafe, Inc.
6+
#
7+
# All rights reserved - Do Not Redistribute
8+
#
9+
10+
include_recipe "git"
11+
include_recipe "chef-sbt"
12+
13+
scabotHome = "/home/scabot"
14+
scabotCheckout = "/home/scabot/scabot"
15+
scabotUser = "scabot"
16+
17+
user scabotUser
18+
19+
directory scabotHome do
20+
owner scabotUser
21+
mode 00755
22+
action :create
23+
end
24+
25+
directory scabotCheckout do
26+
owner scabotUser
27+
mode 00755
28+
action :create
29+
end
30+
31+
directory "#{scabotHome}/logs" do
32+
owner scabotUser
33+
mode 00755
34+
action :create
35+
end
36+
37+
directory "#{scabotHome}/.ssh" do
38+
owner scabotUser
39+
end
40+
41+
file "#{scabotHome}/.ssh/authorized_keys" do
42+
owner scabotUser
43+
mode '644'
44+
content ChefVault::Item.load("master", "scabot-keypair")['public_key']
45+
end
46+
47+
node.set['scabot']['github']['token'] = ChefVault::Item.load("master", "scabot")['github']['token']
48+
node.set['scabot']['jenkins']['token'] = ChefVault::Item.load("master", "scabot")['jenkins']['token']
49+
50+
git_user scabotUser do
51+
home scabotHome
52+
# owner scabotUser
53+
full_name 'Scabot'
54+
55+
end
56+
57+
# scabotCheckout must be an empty dir
58+
git scabotCheckout do
59+
user scabotUser
60+
repository "https://github.com/adriaanm/scabot.git"
61+
revision "master"
62+
end
63+
64+
template "#{scabotCheckout}/scabot.conf" do
65+
source 'scabot.conf.erb'
66+
user scabotUser
67+
sensitive true
68+
end
69+
70+
bash 'build scabot' do
71+
cwd scabotCheckout
72+
user scabotUser
73+
code "sbt update && sbt stage"
74+
end
75+
76+
# Include runit to setup the service
77+
include_recipe 'runit::default'
78+
79+
# Create runit service
80+
runit_service 'scabot' # see templates/default/sv-scabot-run.erb
81+

recipes/master-config.rb

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
require "chef-vault"
1111

12+
include_recipe 'scala-jenkins-infra::_master-config-scabot'
13+
1214
ruby_block 'set private key' do
1315
block do
1416
node.run_state[:jenkins_private_key] = ChefVault::Item.load("master", "scala-jenkins-keypair")['private_key']

templates/default/scabot.conf.erb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
scala: {
2+
jenkins: {
3+
job: "scala-2.11.x-validate-main"
4+
host: "scala-ci.typesafe.com"
5+
user: "<%=node['scabot']['jenkins']['user']%>"
6+
token: "<%=node['scabot']['jenkins']['token']%>"
7+
}
8+
github: {
9+
user: "<%=node['scabot']['github']['repo_user']%>"
10+
repo: "scala"
11+
host: "api.github.com"
12+
token: "<%=node['scabot']['github']['token']%>"
13+
}
14+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
#
4+
# This file was generated by Chef for <%= node['fqdn'] %>.
5+
# Do NOT modify this file by hand.
6+
#
7+
8+
exec svlogd /home/scabot/logs

templates/default/sv-scabot-run.erb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
#
4+
# This file was generated by Chef for <%= node['fqdn'] %>.
5+
# Do NOT modify this file by hand.
6+
#
7+
8+
9+
exec 2>&1
10+
cd /home/scabot
11+
touch scabot.start
12+
exec chpst -u scabot -U scabot \
13+
env HOME=/home/scabot \
14+
/home/scabot/scabot/target/universal/stage/bin/scabot

0 commit comments

Comments
 (0)