summaryrefslogtreecommitdiff
path: root/net-mgmt/devmon/files/devmon.in
blob: 137c66686c092c145ed81ca116bb9408cbfcb5aa (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
#!/bin/sh

# PROVIDE: devmon
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name=devmon
rcvar=devmon_enable
load_rc_config ${name}

: ${devmon_enable:=NO}
: ${devmon_config="%%PREFIX%%/devmon/devmon.cfg"}
: ${devmon_db="%%PREFIX%%/devmon/hosts.db"}
: ${devmon_pid=/var/run/devmon/devmon.pid}
: ${devmon_user="%%USERS%%"}
: ${devmon_group="%%GROUPS%%"}

command="%%PREFIX%%/devmon/devmon"
command_args="-c ${devmon_config} -d ${devmon_db}"
command_interpreter="%%PREFIX%%/bin/perl"
pidfile=${devmon_pid}

start_precmd=devmon_startprecmd
status_cmd=devmon_statuscmd
stop_cmd=devmon_stopcmd

devmon_startprecmd()
{
	if [ ! -e ${devmon_config} ];
		then
		echo "Error: ${devmon_config} does not exist."
	exit 1;
	fi

	TEMPLATESDIR=%%PREFIX%%/devmon/templates
	if [ ! -e ${TEMPLATESDIR} ]; then
		echo ""
		echo "  ERROR: no templates exist. Please install device templates"
		echo "  to: ${TEMPLATESDIR}"
		echo "  They are available on the devmon SourceForge page via SVN."
		echo "  Note, the older template tarballs do not work reliably."
		echo ""
		echo "  # svn co svn://svn.code.sf.net/p/devmon/code/trunk/templates ${TEMPLATESDIR}"
		echo ""
		exit 1;
	fi

	DEVMONLOG=$(grep "^LOGFILE=" ${devmon_config} | awk -F '=' '{print $2}')
	if [ ! -e ${DEVMONLOG} ]; then
		install -o devmon -g devmon /dev/null ${DEVMONLOG}
	fi

	if [ ! -d /var/run/devmon ]; then
		install -o devmon -g devmon /dev/null /var/run/devmon
	fi
}

devmon_statuscmd()
{
	if [ ! -e ${pidfile} ]; then
		echo "pidfile does not exist. ${name} is not running?";
		exit 1;
	fi

	if pgrep -F ${pidfile} >/dev/null; then
		echo "${name} is running.";
	else
		echo "${name} is not running.";
		exit 1;
	fi
}

devmon_stopcmd()
{
	if pgrep -F ${pidfile} >/dev/null; then
		mypid=`cat ${pidfile}`;
		kill ${sig_stop} ${mypid};
		wait_for_pids ${mypid};
	else
		echo "${name} is not running.";
		exit 1;
	fi
}

run_rc_command "$1"