Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add services for ubuntu, debian, redhat and systemd #10

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
7 changes: 6 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
$watch = undef,
$resources = {},

$enable = $::confd::params::enable,
$init_template = $::confd::params::init_template,
$init_location = $::confd::params::init_location,

) inherits confd::params {

# validate parameters here
Expand Down Expand Up @@ -75,6 +79,7 @@
create_resources('confd::resource', $resources)

class { 'confd::install': } ->
class { 'confd::config': } ->
class { 'confd::config': } ~>
class { 'confd::service': } ->
Confd::Resource <||>
}
7 changes: 6 additions & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# == Class confd::install
#
class confd::install {
include confd
include ::confd

$binary_src = "puppet:///modules/${confd::sitemodule}/confd-${confd::version}"

Expand All @@ -12,4 +12,9 @@
mode => '0750',
source => $binary_src
}

file { $::confd::init_location:
content => template($::confd::init_template),
mode => '0700',
}
}
25 changes: 25 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
$confdir = '/etc/confd'
$version = 'latest'
$user = 'root'
$enable = true
$ensure = 'running'
$sitemodule = 'site_confd'
$nodes = ['127.0.0.1:4001']

Expand All @@ -21,4 +23,27 @@
fail("${::operatingsystem} not supported")
}
}

case $::operatingsystemmajrelease {
7, 8: {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not sure what version of ubuntu moved to systemd but that should be here too. This shoulld work for rhel/centos7 and debian 7 and 8.

$init_template = 'confd/systemd.service.erb'
$init_location = '/etc/systemd/system/confd.service'
}
default: {
case $::osfamily {
'Debian': {
$init_template = 'confd/confd.conf.erb'
$init_location = '/etc/init.d/confd.conf'
}
'Redhat', 'Amazon': {
$init_template = 'confd/initd.erb'
$init_location = '/etc/init.d/confd'
}
default: {
fail("${::operatingsystem} not supported")
}
}
}
}

}
8 changes: 8 additions & 0 deletions manifests/service.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Internal class to start up systemd
class confd::service {
service { 'confd':
ensure => $::confd::ensure,
hasstatus => true,
enable => $::confd::enable,
}
}
36 changes: 34 additions & 2 deletions spec/classes/confd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,44 @@

it { should contain_class('confd::params') }
it { should contain_class('confd::install').that_comes_before('confd::config') }
it { should contain_class('confd::config').that_notifies('confd::service') }
it { should contain_class('confd::config') }


it { should contain_service('confd').with_enable(true) }
it { should contain_service('confd').with_ensure('running') }

it { should contain_file('/etc/confd') }
it { should contain_file('/etc/confd/conf.d') }
it { should contain_file('/etc/confd/confd.toml') }
it { should contain_file('/etc/confd/templates') }
it { should contain_file('/etc/confd/ssl') }

end
end
end

context "on redhat families" do
let(:facts) {{ :osfamily => 'Redhat' }}
it { should contain_file('/usr/bin/confd') }
it { should contain_file('/etc/init.d/confd') }

context "with systemd" do
let(:facts) {{ :osfamily => 'Redhat', :operatingsystemmajrelease => 7 }}
it { should contain_file('/etc/systemd/system/confd.service') }
end
end

context "on debian families" do
let(:facts) {{ :osfamily => 'Debian' }}
it { should contain_file('/usr/local/bin/confd') }
it { should contain_file('/etc/init.d/confd.conf') }

context "with systemd" do
let(:facts) {{ :osfamily => 'Debian', :operatingsystemmajrelease => 7 }}
it { should contain_file('/etc/systemd/system/confd.service') }
end
end

context 'unsupported operating system' do
describe 'confd class without any parameters on Solaris/Nexenta' do
let(:facts) {{
Expand All @@ -29,4 +61,4 @@
it { expect { should contain_package('confd') }.to raise_error(Puppet::Error, /Nexenta not supported/) }
end
end
end
end
18 changes: 18 additions & 0 deletions templates/confd.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Confd Agent (Upstart unit)
description "Confd Agent"
start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [06]

env CONFD=<%= scope.lookupvar('::confd::installdir') %>confd

script
# read settings like GOMAXPROCS from "/etc/default/confd", if available.
[ -e /etc/default/confd ] && . /etc/default/confd

export GOMAXPROCS=${GOMAXPROCS:-2}
exec $CONFD
end script

respawn
respawn limit 10 10
kill timeout 10
130 changes: 130 additions & 0 deletions templates/initd.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash
#
# confd Manage the confd daemon
#
# chkconfig: 2345 95 95
# description: Confd is a tool for templating configuration files
# processname: confd
# config: /etc/confd
# pidfile: /var/run/confd.pid

### BEGIN INIT INFO
# Provides: confd
# Required-Start: $local_fs $network
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage the confd daemon
# Description: Confd is a tool for templating configuration files
### END INIT INFO

# source function library
. /etc/rc.d/init.d/functions

prog="confd"
user="root"
exec="<%= scope.lookupvar('confd::installdir') %>/$prog"
pidfile="/var/run/$prog.pid"
lockfile="/var/lock/subsys/$prog"
logfile="/var/log/$prog"

# pull in sysconfig settings
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

export GOMAXPROCS=${GOMAXPROCS:-2}

start() {
[ -x $exec ] || exit 5

umask 077

touch $logfile $pidfile
chown $user:$user $logfile $pidfile

echo -n $"Starting $prog: "

## holy shell shenanigans, batman!
## daemon can't be backgrounded. we need the pid of the spawned process,
## which is actually done via runuser thanks to --user. you can't do "cmd
## &; action" but you can do "{cmd &}; action".
daemon \
--pidfile=$pidfile \
--user=$user \
" { $exec $CMD_OPTS &>> $logfile & } ; echo \$! >| $pidfile "

RETVAL=$?
echo

[ $RETVAL -eq 0 ] && touch $lockfile

return $RETVAL
}

stop() {
echo -n $"Shutting down $prog: "
## graceful shutdown with SIGINT
killproc -p $pidfile $exec -INT
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
return $RETVAL
}

restart() {
stop
sleep 5
start
}

reload() {
echo -n $"Reloading $prog: "
killproc -p $pidfile $exec -HUP
echo
}

force_reload() {
restart
}

rh_status() {
status -p "$pidfile" -l $prog $exec
}

rh_status_q() {
rh_status >/dev/null 2>&1
}

case "$1" in
start)
rh_status_q && exit 0
start
;;
stop)
rh_status_q || exit 0
stop
;;
restart)
restart
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac

exit $?
10 changes: 10 additions & 0 deletions templates/systemd.service.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=ConfD Service
After=network.target

[Service]
ExecStart=<%= scope.lookupvar('::confd::installdir') %>confd
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target