Subject: Re: ups-nut rc.d scripts
To: Johnny Lam <jlam@jgrind.org>
From: Luke Mewburn <lukem@wasabisystems.com>
List: tech-pkg
Date: 11/21/2001 12:38:24
--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Tue, Nov 20, 2001 at 10:02:55AM -0800, Johnny Lam wrote:
> I'm trying to improve the ups-nut rc.d scripts to the point that
> they may be automatically copied into /etc/rc.d without any harmful effects.
> That means that they must respect any rc.conf settings so that they don't
> automatically start unless the proper variables are set to YES. I've
> included two scripts below. Could someone with a UPS system please check to
> see if the scripts work correctly? Note that they may need to be customized
> for your setup if the ups-nut configuration directory isn't in /usr/pkg/etc.
I've actually got a bunch of scripts I'm using for ups-nut which I
think do a better job (at least for me).
I have separate scripts for each service, with separate rc.conf vars
for each, as well as an `/etc/rc.d/ups' script which doesn't get
invoked by /etc/rc (because it has a `nostart' keyword), but is
provide solely to allow easy startup and shutdown of all of the ups
programs at once. It requires a -current rc.subr for the
`reverse_list' function, but that is trivial to replace with the 4
lines of shell to implement that, for non-current users.
Here's the relevant bits of my /etc/rc.conf, and the 5 scripts.
Luke.
--- /etc/rc.conf snippet ---
upsdriver=YES
upsdriver_type="newapc"
upsdriver_flags="-a smartups"
upsd=YES
upsmon=YES
upsmon_flags="localhost"
upslog=YES
upslog_flags="smartups@localhost /var/log/ups 60"
--- end of /etc/rc.conf snippet ---
--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=ups
#!/bin/sh
#
# $Id: ups,v 1.1 2001/11/19 03:20:28 lukem Exp $
# PROVIDE: ups
# KEYWORD: nostart
. /etc/rc.subr
# NOTE: run_rc_command sets $_arg
#
ups_commands()
{
for file in $UPS_COMMANDS; do
/etc/rc.d/$file $_arg
done
}
ups_reversecommands()
{
for file in `reverse_list $UPS_COMMANDS`; do
/etc/rc.d/$file $_arg
done
}
UPS_COMMANDS="upsdriver upsd upsmon upslog"
name="ups"
start_cmd="ups_commands"
stop_cmd="ups_reversecommands"
status_cmd="ups_commands"
extra_commands="status"
run_rc_command "$1"
--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=upsdriver
#!/bin/sh
#
# $Id: upsdriver,v 1.1 2001/11/19 02:42:30 lukem Exp $
# PROVIDE: upsdriver
# REQUIRE: NETWORK syslogd mountcritremote
. /etc/rc.subr
#
# XXX need a way to easily determine the pidfile, which is of the form
# /var/db/nut/${updriver_type}-${tty}.pid
#
name="upsdriver"
rcvar=$name
load_rc_config $name
command="/usr/pkg/bin/${upsdriver_type}"
run_rc_command "$1"
--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=upsd
#!/bin/sh
#
# $Id: upsd,v 1.4 2001/11/19 02:42:15 lukem Exp $
# PROVIDE: upsd
# REQUIRE: upsdriver
. /etc/rc.subr
name="upsd"
rcvar=$name
load_rc_config $name
command="/usr/pkg/sbin/${name}"
pidfile="/var/db/nut/${name}.pid"
run_rc_command "$1"
--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=upsmon
#!/bin/sh
#
# $Id: upsmon,v 1.1 2001/11/19 02:43:01 lukem Exp $
# PROVIDE: upsmon
# REQUIRE: upsd
. /etc/rc.subr
name="upsmon"
rcvar=$name
load_rc_config $name
command="/usr/pkg/sbin/${name}"
pidfile="/var/run/${name}.pid"
run_rc_command "$1"
--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=upslog
#!/bin/sh
#
# $Id: upslog,v 1.2 2001/11/19 02:42:48 lukem Exp $
# PROVIDE: upslog
# REQUIRE: upsd
. /etc/rc.subr
name="upslog"
rcvar=$name
load_rc_config $name
command="/usr/pkg/bin/${name}"
pidfile="/var/run/${name}.pid"
run_rc_command "$1"
--SUOF0GtieIMvvwua--