File: upsd.in

package info (click to toggle)
nut 2.2.2-6.5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,240 kB
  • ctags: 4,918
  • sloc: ansic: 42,528; sh: 10,284; makefile: 860
file content (110 lines) | stat: -rw-r--r-- 2,456 bytes parent folder | download | duplicates (10)
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
#!/bin/sh
#
# chkconfig: 2345 30 90
#
# 2003-01-31 Antonino Albanese <al.an@monkeysweb.net>
#  Removed all old statements
#  start programs as user nut
#  new style starting and stopping upsd
#  added reload option
#  use of /etc/sysconfig/ups for POWERDOWNFLAG variable retrieving
#
# 2002-02-07 Nigel Metheringham <Nigel.Metheringham@InTechnology.co.uk>
#  made ups.conf pre-eminant, added new upsdrvctl functions, targeted for RH7.2, should
#  work OK on RH 6.x, 7.x
# 2001-10-24 Peter Bieringer <pb@bieringer.de>
#  enhancements for new style drivers and controls, tested on a RHL 7.1.93 system
#
# description: NUT upsd and its drivers directly monitor a ups and \
#	make information from it available to other programs
# processname: upsd
# config: @sysconfdir@/upsd.conf
# config: @sysconfdir@/ups.conf

PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH

# Source function library.
. /etc/rc.d/init.d/functions

# POWERDOWNFLAG *must* match that in upsmon.conf
# Loading POWERDOWNFLAG from /etc/sysconfig/ups
DRIVERPATH=@DRVPATH@
if [ -f /etc/sysconfig/ups ]; then
  . /etc/sysconfig/ups
else
  POWERDOWNFLAG=/etc/killpower
  NUTUSER=nutmon
fi
UPSDCONF=@sysconfdir@/upsd.conf
UPSCONF=@sysconfdir@/ups.conf

# if there are no config file, bail out
[ -f $UPSDCONF ] && [ -f $UPSCONF ] || exit 0

runcmd() {
   echo -n "$1 "
   shift
   if [ "$BOOTUP" = "color" ]; then
      $* && echo_success || echo_failure
   else
      $*
   fi
   echo
}

# See how we are called.
case "$1" in
  start)
	# new style drivers uses 'upsdrvctl'
	echo -n "NUT Starting UPS model drivers: "
	# starting ase nut user
	daemon --user $NUTUSER `which upsdrvctl` start
	echo
	if [ $? -eq 0 ]; then
		echo -n "NUT Starting UPS daemon: "
		# starting ase nut user
		daemon upsd -u $NUTUSER
		echo
		touch /var/lock/subsys/upsd
	fi
	;;

  stop)
	# new style upsd stop
	action "NUT Stopping UPS daemon" \
	upsd -c stop
	# new style drivers uses 'upsdrvctl'
	action "NUT Stopping UPS model drivers" \
	upsdrvctl stop

	rm -f /var/lock/subsys/upsd
	;;

  powerdown)
	# new style drivers
	runcmd "NUT powerdown of attached UPS(es)" upsdrvctl shutdown
	;;

  restart)
	$0 stop
	$0 start
	;;

  reload)
	# reloading upsd config files
	action "NUT Reloading config files" \
	upsd -c reload
	;;

  status)
	# new style drivers
	action "NUT: checking UPS model drivers" upsdrvctl status

	status upsd
	;;
  *)
	echo "Usage: upsd {start|stop|powerdown|restart|reload|status}"
	exit 1
esac