#!/bin/bash # # python-status-exporter Python Status Exporter # # chkconfig: 2345 90 10 # description: python-status-exporter exports statused for promethius # ### BEGIN INIT INFO # Provides: python-status-exporter # Required-Start: $local_fs $network $remote_fs # Required-Stop: $local_fs $network $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start and stop python-status-exporter # Description: python-status-exporter exports statused for promethius ### END INIT INFO # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network RETVAL=0 exec_file="/opt/python-status-exporter/python-status-exporter.py" work_dir="$(dirname $exec_file)" prog_name="python-status-exporter.py" py3="/usr/bin/python3" pidfile="/var/run/${prog_name}.pid" logfile="/var/log/${prog_name}.log" loglevel="debug" conf_check() { [ -x $exec_file ] || exit 5 } start() { [ ${NETWORKING} = "no" ] && exit 1 conf_check if [ -f "$pidfile" ]; then if [ -d "/proc/$(cat $pidfile)" ]; then if [ "$(readlink -- \"/proc/$pidfile/cwd\")" = $work_dir ]; then echo "$prog_name seems to be running already." exit -1 fi fi fi # Start daemons. cd $work_dir || exit 6 echo -n $"Starting $proc_name: " $exec_file -p 9095 -m nginx_vod --pid-file $pidfile --fork -l $logfile -L $loglevel RETVAL=$? echo return $RETVAL } stop() { # Stop daemons. echo -n $"Shutting down $proc_name: " [ -f "$pidfile" ] || echo "No pidfile found at $pidfile, unable to stop $proc_name" && exit 6 kill $(cat $pidfile) sleep 1 && test -f "$pidfile" && RETVAL=7 || RETVAL=0 echo return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) stop ;; *) echo $"Usage: $0 {start|stop}" exit 2 esac exit $?