Init.d script for puppet-dashboard
In the #puppet IRC channel on freenode a user was asking if anyone knew of a init.d script for redhat/fedora for puppet-dashboard. I have a blog post about installing puppet-dashboard on Redhat/CentOS and I don’t think there is any init.d script out there. So time to write one
The first thing you will create is the following file
/etc/sysconfig/puppet-dashboard
This is a simple file with the following in it
#
# path to where you installed puppet dashboard
#
DASHBOARD_HOME=/opt/puppet-dashboard
You probably need to change the DASHBOARD_HOME variable to match what you have. Its the root of the project.
Now for the init.d script. Create the file called
/etc/init.d/puppet-dashboard
With the following contents in it.
#!/bin/bash
#
# Init script for puppet-dashboard
#
# chkconfig: - 85 15
# description: Init script for puppet-dashboard
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/puppet-dashboard ]; then
. /etc/sysconfig/puppet-dashboard
fi
prog=puppet-dashboard
RETVAL=0
start() {
echo -n $"Starting $prog: "
/usr/bin/ruby ${DASHBOARD_HOME}/script/server >/dev/null 2>&1 &
RETVAL=$?
if [ $RETVAL = 0 ]
then
echo $! > /var/run/puppet-dashboard.pid
echo_success
else
echo_failure
fi
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc puppet-dashboard
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/run/puppet-dashboard.pid
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart}"
exit 1
esac
exit $RETVAL
This might not be perfect but it works nicely
Hi, I’m the guy who asked for the init script. We want to give you a token of appreciation. Please email me at the email address I provided for the blog post.
Thanks.
This is some fantastic work. Hopefully Kanies & Co will be able to leverage your efforts once this project gets mature enough to package!
Thanks.
Glad you got some use out of it
One addition.. status!
Disclaimer: I stole this from /etc/init.d/puppet, with some minor tweaks.
1. After the stop function, add the following function (around line 43):
rh_status() {
status | grep -q — ‘-p’ 2>/dev/null && statusopts=”-p $pidfile”
status $statusopts puppet-dashboard
RETVAL=$?
return $RETVAL
}
2. Add a variable at the top called pidfile, i.e.:
pidfile=/var/run/puppet-dashboard.pid
3. Replace other occurences of /var/run/puppet-dashboard.pid with ${pidfile}
4. Inside the case statement add a status option (around line 58):
status)
rh_status
;;
5. Update the Usage string (around line 66):
echo $”Usage: $prog {start|stop|status|restart}”
6. Save, close, test:
$ /etc/init.d/puppet-dashboard status
puppet-dashboard (pid 16407) is running…