summaryrefslogtreecommitdiff
path: root/python-status-exporter/python-status-exporter.init-script
blob: 7f2c661a2c47e1fee7587ef49cf03c17adfaf22b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/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 $?