File: cronchk.sh

package info (click to toggle)
dircproxy 1.0.5-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 1,120 kB
  • ctags: 740
  • sloc: ansic: 9,466; sh: 2,946; makefile: 113; perl: 70
file content (44 lines) | stat: -rwxr-xr-x 1,056 bytes parent folder | download | duplicates (9)
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
#!/bin/sh
# Script to run from crontab to check whether dircproxy is still running,
# and if not, restart it
# 
# You will need to set the 'pid_file' option in your .dircproxyrc
# 
# To use, set the following in crontab
#   */10 * * * *   cronchk.sh
#  or
#   */10 * * * *   cronchk.sh /path/to/dircproxyrc

# command to run dircproxy
DIRCPROXY=dircproxy

# config file can be specified as the first argument
CONFFILE=$HOME/.dircproxyrc
if test -n "$1"; then
	CONFFILE=$1
fi

# look for the pid_file directive
PIDFILE=`grep ^pid_file $CONFFILE | sed 's/^pid_file[ 	"]*//' | sed 's/"*$//'`
PIDFILE=`eval echo \`echo $PIDFILE | sed 's/^~/$HOME/'\``
if test -n "$PIDFILE" -a "$PIDFILE" != "none"; then
	RUNNING=no

	if test -r "$PIDFILE"; then
		if kill -0 `cat $PIDFILE` > /dev/null 2>&1; then
			RUNNING=yes
		else
			echo "PID file, but no dircproxy. :("
		fi
	else
		echo "No PID file"
	fi

	if test "$RUNNING" = "no"; then
		echo "Restarting dircproxy"
		$DIRCPROXY
	fi
else
	echo "Couldn't locate pid_file directive in config file $CONFFILE"
	exit 1
fi