Provide init.d / systemd examples
To ease the demonizing of jmxproxybeat it would be good to add example file for it
jmxproxybeat.initd:
#!/bin/bash
#
# jmxproxybeat jmxproxy shipper
#
# chkconfig: 2345 98 02
# description: Starts and stops a single jmxproxybeat instance on this system
#
### BEGIN INIT INFO
# Provides: jmxproxybeat
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Jmxproxybeat analyzes Tomcat JMX Servlet metrics.
# Description: Jmxproxybeat is a shipper for Tomcat Metrics to ElasticSearch.
# Please see: https://github.com/radoondas/jmxproxybeat
### END INIT INFO
PATH=/usr/bin:/sbin:/bin:/usr/sbin
export PATH
[ -f /etc/sysconfig/jmxproxybeat ] && . /etc/sysconfig/jmxproxybeat
pidfile=${PIDFILE-/var/run/jmxproxybeat.pid}
BIN_NAME="jmxproxybeat"
agent=${BEATS_AGENT-/usr/share/jmxproxybeat/${BIN_NAME}}
args="-c /etc/jmxproxybeat/jmxproxybeat.yml -path.home /usr/share/jmxproxybeat -path.data /var/lib/jmxproxybeat -path.logs /var/log/jmxproxybeat"
test_args="-e -configtest"
RETVAL=0
# Source function library.
. /etc/rc.d/init.d/functions
# Determine if we can use the -p option to daemon, killproc, and status.
# RHEL < 5 can't.
if status | grep -q -- '-p' 2>/dev/null; then
daemonopts="--pidfile $pidfile"
pidopts="-p $pidfile"
fi
test() {
$agent $args $test_args
}
start() {
echo -n $"Starting jmxproxybeat: "
test
if [ $? -ne 0 ]; then
echo
exit 1
fi
daemon $daemonopts "$agent $args &"
RETVAL=$?
[ $RETVAL -eq "0" ] && touch /var/lock/subsys/$BIN_NAME
pid=`ps -A | grep ${BIN_NAME} | cut -d " " -f1`
if [ -n "$pid" ]; then
echo $pid > "$pidfile"
fi
echo
return $RETVAL
}
stop() {
echo -n $"Stopping jmxproxybeat: "
[ -f /var/lock/subsys/$BIN_NAME ] || return 0
killproc $agent
echo
rm -f $pidfile
rm -f /var/lock/subsys/$BIN_NAME
RETVAL=$?
echo
}
restart() {
test
if [ $? -ne 0 ]; then
return 1
fi
stop
start
}
rh_status() {
status $pidopts $agent
RETVAL=$?
return $RETVAL
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
status)
rh_status
;;
configtest)
test
;;
*)
echo $"Usage: $0 {start|stop|status|configtest|restart|condrestart}"
exit 1
esac
exit $RETVAL
jmxproxybeat.systemd:
[Unit]
Description=JMXProxyBeat Service
After=syslog.target network.target
[Service]
Type=simple
Restart=always
RestartSec=3
User=root
PIDFile=/var/run/jmxproxybeat.pid
ExecStart=/usr/share/jmxproxybeat/jmxproxybeat -c /etc/jmxproxybeat/jmxproxybeat.yml -path.home /usr/share/jmxproxybeat -path.data /var/lib/jmxproxybeat -path.logs /var/log/jmxproxybeat
[Install]
WantedBy=multi-user.target
Thanks @robertoschwald. I am sorry for the delay with my response. Thanks for your suggestion. I believe it would be great as documentation page to help people.
Once I finish migration to libbeat v5 I can update also documentation with your example! Again, thanks for your nice example.
Updated the init.d script stop() routine, as it did not reliable stop the beat. Now it detects still running beats and performs a forced stop of all jmxproxybeat instances.
Thanks again @robertoschwald