summaryrefslogtreecommitdiffstats
path: root/server/parser/rteval-parserd.init
blob: a7da9dbc8d1248c5d2672f502ec3e949e829b0e3 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
#
# rteval-parserd  rteval report parser daemon
#
# Author:      David Sommerseth <davids@redhat.com>
#
# Copyright 2009 Red Hat, Inc. and/or its affiliates.
# Released under the GPL
#
# chkconfig: - 20 80
# description: The rteval-parserd waits for rteval summary reports and parses them on arrival
# config: /etc/sysconfig/rteval-parserd
#
### BEGIN INIT INFO
# Provides: rteval-parserd
# Required-Start: postgresql
# Required-Stop: -
# Default-Stop: 0 1 6
# Short-Description: start and stop rteval-parserd
# Description: The rteval-parserd waits for rteval summary reports and parses them on arrival
### END INIT INFO

. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/rteval-parserd ]; then
    . /etc/sysconfig/rteval-parserd
fi

prog=rteval-parserd
RETVAL=0

if [ -z $PIDFILE ]; then
    PIDFILE=/var/run/$prog.pid
fi

start() {
    # Check if we have a pid file, if we do check that it is correct
    if [ -f $PIDFILE ]; then
	filepid=$(cat $PIDFILE)
	chkpid=$(pidof $prog)
	if [ $? = 0 ]; then
	    if [ "$chkpid" != "$filepid" ] ; then
		# We have a pid file which is not correct, fix it
		echo $chkpid > $PIDFILE
		filepid=$chkpid
	    fi
	    echo "$prog is already started (pid $filepid)"
	    return 0
	else
	    # No process really exists, clean up!
	    rm -f $PIDFILE
	fi
    fi

    # Start a new daemon
    args="--daemon"
    if [ -z "$NUM_THREADS" ]; then
	# If NUM_THREADS is not set, use number of cores found.
	NUM_THREADS=$(find /sys/devices/system/cpu/cpu? -maxdepth 0 -type d | wc -l)
    fi
    args="$args --threads $NUM_THREADS"

    if [ ! -z "$LOG" ]; then
	args="$args --log $LOG"
    fi

    if [ ! -z "$LOGLEVEL" ]; then
	args="$args --log-level $LOGLEVEL"
    fi

    if [ ! -z "$CONFIGFILE" ]; then
	args="$args --config $CONFIGFILE"
    fi
    echo -n $"Starting $prog ($NUM_THREADS threads): "
    $prog $args
    pidof $prog > $PIDFILE
    RETVAL=$?
    [ $RETVAL = 0 ] && success $"$prog startup" || failure $"$prog startup"
    [ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
    echo
    return $RETVAL
}

stop() {
    echo -n $"Stopping $prog: "
    if [ ! -f $PIDFILE ]; then
	chkpid=$(pidof $prog)
	if [ $? = 0 ]; then
	    PID=$chkpid
	fi
    else
	PID=$(cat $PIDFILE)
    fi
    kill -TERM $PID
    RETVAL=$?
    [ $RETVAL = 0 ] && success $"$prog shutdown" || failure $"$prog (pid $PID) shutdown"
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
    echo
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
        status $prog
	;;
  restart)
	stop
	start
	;;
  reload)
	stop
	start
	;;
  condrestart)
        ;;
  *)
	echo $"Usage: $prog {start|stop|restart|reload|status|help}"
	RETVAL=3
esac

exit $RETVAL