Configure and run apache on top of hound

Creates a service user and runs hound and apache. The config.json can
optionally be unmanaged but is otherwise taken from a file.

Co-Authored-By: Monty Taylor <mordred@inaugust.com>
Change-Id: I4042594421989ab60d1134fbfcfc8b0c73839faa
This commit is contained in:
Emma Barber 2015-08-07 19:43:47 -07:00
parent 84742e753b
commit 6ce0881b6a
5 changed files with 220 additions and 0 deletions

9
files/config.json Normal file
View File

@ -0,0 +1,9 @@
{
"max-concurrent-indexers" : 2,
"dbpath" : "data",
"repos" : {
"hound" : {
"url" : "https://www.github.com/Etsy/hound.git"
}
}
}

71
files/hound.init Normal file
View File

@ -0,0 +1,71 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: hound
# Required-Start: $network $local_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Hound Source Code Indexer
#### END INIT INFO
NAME=hound
USER=hound
GROUP=hound
HOUND_HOME="/home/hound"
CMD_DIR="$HOUND_HOME/bin"
CMD="houndd"
CMD_ARGS=""
LOG_FILE=/var/log/hound.log
########## Common
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:$PATH
SSD=start-stop-daemon
PID=/var/run/${NAME}.pid
start () {
echo -n "Start $NAME"
$SSD --start --pidfile $PID --make-pidfile -u $USER -g $GROUP \
-d $HOUND_HOME --background \
--startas /bin/bash -- -c "exec $CMD_DIR/$CMD >$LOG_FILE 2>&1"
RETVAL=$?
echo
return $RETVAL
}
stop () {
echo -n "Stop $NAME"
$SSD --stop --oknodo --pidfile $PID --signal INT
RETVAL=$?
echo
return $RETVAL
}
restart () {
stop
sleep 1
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
echo "not supported"
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $RETVAL

119
manifests/init.pp Normal file
View File

@ -0,0 +1,119 @@
# Class to configure hound
#
# == Class: hound
class hound (
$manage_config = true,
$config_json = 'hound/config.json',
$vhost_name = $::fqdn,
$datadir = '/home/hound/data',
$serveradmin = "webmaster@${::fqdn}",
) {
package { 'golang':
ensure => present,
}
user { 'hound':
ensure => present,
home => '/home/hound',
shell => '/bin/bash',
gid => 'hound',
managehome => true,
require => Group['hound'],
}
group { 'hound':
ensure => present,
}
file {'/home/hound':
ensure => directory,
owner => 'hound',
group => 'hound',
mode => '0755',
require => User['hound'],
}
file { $datadir:
ensure => 'directory',
owner => 'hound',
group => 'hound',
require => User['hound'],
}
if $manage_config {
file { '/home/hound/config.json':
ensure => 'present',
owner => 'hound',
group => 'hound',
content => file($config_json),
require => User['hound'],
}
}
vcsrepo { '/home/hound/src/github.com/etsy/hound':
ensure => latest,
provider => git,
source => 'git://github.com/etsy/Hound.git',
notify => Exec['build_hound'],
}
exec { 'build_hound':
command => 'go install github.com/etsy/hound/cmds/...',
path => '/bin:/usr/bin:/usr/local/bin',
environment => 'GOPATH=/home/hound',
cwd => '/home/hound',
creates => '/home/hound/bin/houndd',
user => 'hound',
timeout => 600,
require => [
User['hound'],
Package['golang'],
]
}
service { 'hound':
ensure => running,
hasrestart => true,
require => [
File['/etc/init.d/hound'],
Exec['build_hound'],
],
subscribe => File['/home/hound/config.json'],
}
file { '/etc/init.d/hound':
ensure => file,
owner => root,
group => root,
mode => '0755',
source => 'puppet:///modules/hound/hound.init',
notify => Service['hound'],
before => Service['hound'],
}
include ::httpd
httpd_mod { 'rewrite':
ensure => present,
before => Service['hound'],
}
httpd_mod { 'proxy':
ensure => present,
before => Service['hound'],
}
httpd_mod { 'proxy_http':
ensure => present,
before => Service['hound'],
}
httpd::vhost { $vhost_name:
port => 80,
docroot => 'MEANINGLESS ARGUMENT',
priority => '50',
template => 'hound/hound.vhost.erb',
}
}

View File

@ -8,5 +8,7 @@
"project_page": "http://docs.openstack.org/infra/system-config/",
"issues_url": "https://storyboard.openstack.org/#!/project/819",
"dependencies": [
{ "name": "openstackinfra/httpd" },
{ "name": "puppetlabs/vcsrepo" }
]
}

19
templates/hound.vhost.erb Normal file
View File

@ -0,0 +1,19 @@
<VirtualHost *:80>
ServerName <%= @vhost_name %>
ServerAdmin <%= @serveradmin %>
ErrorLog ${APACHE_LOG_DIR}/<%= @vhost_name %>-error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/<%= @vhost_name %>-access.log combined
<IfModule mod_proxy.c>
RewriteEngine on
RewriteRule ^/(.*)$ http://localhost:6080/$1 [P]
ProxyPassReverse / http://localhost:6080/
</IfModule>
</VirtualHost>