Re: How to shut down

2003-09-17 Thread lrnobs
Thanks to everyone who responded.

Larry Nobs


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: How to shut down

2003-09-17 Thread Matthew Seaman
On Wed, Sep 17, 2003 at 08:19:49AM -0500, Charles Howse wrote:
> > I am a new user learning about Unix.
> > 
> > I found the shutdown command and have been using "shutdown 
> > now" to shut down
> > before powering off.
> > 
> > When the pc boots up it complains that it was incorrectly shut down.
> > 
> > Am I following an incorrect procedure?
> 
> 'shutdown now' will take you to single user mode.
> This is not what you want if you're ready to power off.
> Use 'shutdown -h now' and wait for the 'press any key to reboot' prompt
> before you power off.
> To reboot, use 'shutdown -r now'.

If you do forget the flags to shutdown, and end up in single user
mode, then you can just type 'halt' to take the machine all the way
down to a state where you can hit the power button. 'halt -p' will
attempt to power down the machine as well, but that depends on what
sort of motherboard you have and whether you've compiled appropriate
support into your kernel.

The error you see is due to the filesystems not being correctly
dismounted.  Since you're taking the system down to single user mode
before pulling the power, you've vastly reduced the probability of
filesystem damage, but still, better safe than sorry.

Cheers,

Matthew


-- 
Dr Matthew J Seaman MA, D.Phil.   26 The Paddocks
  Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey Marlow
Tel: +44 1628 476614  Bucks., SL7 1TH UK


pgp0.pgp
Description: PGP signature


Re: How to shut down

2003-09-17 Thread Jon Mercer
'shutdown -p now' will switch off the computer if the PC supports APM or 
ACPI.

Charles Howse wrote:
I am a new user learning about Unix.

I found the shutdown command and have been using "shutdown 
now" to shut down
before powering off.

When the pc boots up it complains that it was incorrectly shut down.

Am I following an incorrect procedure?


'shutdown now' will take you to single user mode.
This is not what you want if you're ready to power off.
Use 'shutdown -h now' and wait for the 'press any key to reboot' prompt
before you power off.
To reboot, use 'shutdown -r now'.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"
--
++
| ___  ___   |
|/   ||  /   |
|   / /| |/ /|
|  / / | | _ / /     ___ |
| / /__| |/ ___ \   / /__/ __ \/ _  |   |  /__   |
|/   |   / /  /_/  / ___ \  / /_/ /   / / | |   / ___ \  |
|   / /| |  / /   __  / /   \ \ | ___/__ / /  / /  / /   \ \ |
|  / / | |  | |__/ / / // / | \__/ / | |_| |  / // / |
| /__\/___\ \_/ /__|   /__| \_/  \__/|_| /__|   /__| |
||
| www.achean.com |
| == |
| Jon Mercer   [EMAIL PROTECTED] |
||
| Mobile07973 256496 |
||
| Tel.  0117 9561211 |
||
| Fax   0117 9565637 |
++
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: How to shut down

2003-09-17 Thread Greg J.
On Wed, 17 Sep 2003 08:15:59 -0500
"lrnobs" <[EMAIL PROTECTED]> wrote:

> I am a new user learning about Unix.
> 
> I found the shutdown command and have been using "shutdown now" to
> shut down before powering off.
> 
> When the pc boots up it complains that it was incorrectly shut down.
> 
> Am I following an incorrect procedure?
> 
> Thanks,
> 
> Larry Nobs
> 
> 
> ___
> [EMAIL PROTECTED] mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to
> "[EMAIL PROTECTED]"

Type this.. man shutdown

That'll explain everything.

---
FreeBSD 5.1-CURRENT { 0+05:15:31, 51M/1018M }
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


RE: How to shut down

2003-09-17 Thread Charles Howse
> I am a new user learning about Unix.
> 
> I found the shutdown command and have been using "shutdown 
> now" to shut down
> before powering off.
> 
> When the pc boots up it complains that it was incorrectly shut down.
> 
> Am I following an incorrect procedure?

'shutdown now' will take you to single user mode.
This is not what you want if you're ready to power off.
Use 'shutdown -h now' and wait for the 'press any key to reboot' prompt
before you power off.
To reboot, use 'shutdown -r now'.


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: How to shut down cleanly by killing power

2002-09-28 Thread Oliver Fromme

Petri Riihikallio <[EMAIL PROTECTED]> wrote:
 > > "sync" is pretty much useless, it doesn't buy you anything.
 > > Particularly, it won't mark your filesystems clean (so fsck
 > > will still have to run on the next boot), and it does not
 > > guarantee that there's no unwritten data left in memory.
 > 
 > Yes, this I found out by testing. Still many shutdown scripts include
 > "sync ; sync ; sync" as a mantra.

That should not have any effect.  At least on FreeBSD.

Maybe people are used to the sync command if they come
from Linux, where it might be more important because of
the fragile filesystems (ext2 async by default).

 > 'man rc' says just: "The scripts within each directory are executed 
 > in lexicographical order." I know the source IS the doc, but it is so 
 > slow way to find something, when you don't know what your looking for.

The manpage seems to be a bit lacking in that case.
The scripts are indeed executed in _reverse_ lexico-
graphical order during shutdown (which makes sense,
I think).

Another important thing which is not clearly documented
(as far as I know) is the fact that the scripts will NOT
be executed when you use halt(8) or reboot(8).  They
will only be executed when you use shutdown(8) (without
the -o option) or init(8), or when sending a signal to
the running instance of init(8) to bring down the system.

 > > umount -f -A
 > > mount -u -o ro /
 > > mount -o ro /usr
 > 
 > OK. Any need for 'mount -f -u -o ro /' ? (The -f forces the switch to 
 > ro even if files are open for writing)

Yes indeed.  I suggest the following:

mount -u -o ro / || mount -f -u -o ro /

So it will first try to re-mount it normally, and only if
that fails, retry it "the hard way".

 > Is there any reason to signal the system daemon processes (syslog, 
 > sshd, adjkrntz & co)?

Good question.  They will be killed anyway during shutdown.
On the other hand, some daemons might want to do some
clean-up work which requires writing someting somewhere,
so it's probably a good idea to give them a chance to do
that.  This is what init does when terminating multi-user
operation.  Something like this:

trap "" 15
kill -TERM -1
sleep 10# give them some time to finish cleaning up

There is no need to send a SIGKILL (-9) afterwards, because
the processes will die anyway, later in the game.  And since
it is not possible to trap SIGKILL, they cannot bind any
clean-up actions to that signal anyway.

 > The Linux scripts do this with killall5. It sends a signal to all 
 > processes except the processes in its own  session, so  it  won't 
 > kill the shell that is running the script it was called from.

If you put the above at the end of /etc/rc.shutdown, the
"trap" command will protect the shell.  The parent of the
shell is init(8) itself, which is never affected by a kill
of -1, as well as processes which are marked as "system"
processes (e.g. swapper, pagedaemon, vinum).

 > > That's documented in /usr/src/sbin/init/init.c.
 > 
 > :-] "The source IS the doc"
 > 
 > I studied /usr/src/sys/kern/kern_shutdown.c but I couldn't find where 
 > the scripts were called. It is init calling the scripts and then 
 > calling kern_shutdown.

To be more exact:

When init(8) receives a shutdown signal, it runs the
/etc/rc.shutdown script, which in turn executes all the
local start/stop scripts as explained above.  When the
scripts are done (I think up to a maximum of 120 seconds),
init kills all processes -- first with SIGTERM, and if
there are still some left after some time, with SIGKILL.
Afterwards, init(8) either enters single-user mode or
gives control to the reboot(2) system call, depending on
which signal it got in the first place.  At this point,
it does not care anymore if any reluctant processes are
still left, because they will never be scheduled again,
because the kernel will never return from the reboot(2)
system call.  It finally syncs and unmounts all remaining
file systems and brings the hardware down.

Regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"All that we see or seem is just a dream within a dream" (E. A. Poe)

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>  > This way the system reboots, but the reboot is interrupted with
>>  powerdown at early stage. Not ideal, I agree, but a solution still.
>
>And it has the side-benefit of nicely handling the fairly common case of
>where the power comes back on just long enough to get your UPS going
>again, especially if it doesn't have enough power to get you through one
>or more whole reboot-fsck-multi-user-UPS-shutdown cycles.  (It's hard
>to restart a whole mains power grid and it often doesn't work the first
>time, as another poster indicated.)  Of course you could do the
>start-of-rc thing no matter how you handle the shutdown.

Smarter UPSes can be programmed to recharge to some minimum level 
before supplying power, or at least wait some predefined time.

For dumb UPSes I saw somewhere a suggestion to add a snippet like 
this to rc.early:

if [ -f /etc/powerfail ] then
sleep 120
rm -f /etc/powerfail
fi

>And if static linking the UPS software is a problem, you might consider
>having it use /-based copies of their required libraries using the
>LD_LIBRARY_PATH env.var. or maybe (?) using (at start of /etc/rc)
>"/sbin/ldconfig /etc/ld-ups.so.conf".

This shouldn't cause problems.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

Thanks for your reply!

>"sync" is pretty much useless, it doesn't buy you anything.
>Particularly, it won't mark your filesystems clean (so fsck
>will still have to run on the next boot), and it does not
>guarantee that there's no unwritten data left in memory.

Yes, this I found out by testing. Still many shutdown scripts include
"sync ; sync ; sync" as a mantra.

>No.  Upon shutdown, the scripts will be executed in reverse
>ASCII order.  You should rather call it something like
>"%%%whatever".  There's never a guarantee, however, that
>some clever port tries to install a "%%foo" script in
>order to get there first ...

Thanks for pointing that out!

'man rc' says just: "The scripts within each directory are executed 
in lexicographical order." I know the source IS the doc, but it is so 
slow way to find something, when you don't know what your looking for.

>So, maybe the best thing is to add your script at the end
>of /etc/rc.shutdown directly.
>  - - - -
>Yes, exactly.  This should do:
>
>umount -f -A
>mount -u -o ro /
>mount -o ro /usr

OK. Any need for 'mount -f -u -o ro /' ? (The -f forces the switch to 
ro even if files are open for writing)

Is there any reason to signal the system daemon processes (syslog, 
sshd, adjkrntz & co)?

The Linux scripts do this with killall5. It sends a signal to all 
processes except the processes in its own  session, so  it  won't 
kill the shell that is running the script it was called from.

>That's documented in /usr/src/sbin/init/init.c.

:-] "The source IS the doc"

I studied /usr/src/sys/kern/kern_shutdown.c but I couldn't find where 
the scripts were called. It is init calling the scripts and then 
calling kern_shutdown.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Gary W. Swearingen

> This way the system reboots, but the reboot is interrupted with
> powerdown at early stage. Not ideal, I agree, but a solution still.

And it has the side-benefit of nicely handling the fairly common case of
where the power comes back on just long enough to get your UPS going
again, especially if it doesn't have enough power to get you through one
or more whole reboot-fsck-multi-user-UPS-shutdown cycles.  (It's hard
to restart a whole mains power grid and it often doesn't work the first
time, as another poster indicated.)  Of course you could do the
start-of-rc thing no matter how you handle the shutdown.

And if static linking the UPS software is a problem, you might consider
having it use /-based copies of their required libraries using the
LD_LIBRARY_PATH env.var. or maybe (?) using (at start of /etc/rc) 
"/sbin/ldconfig /etc/ld-ups.so.conf".

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Jack L. Stone

At 08:45 PM 9.27.2002 +0300, Petri Riihikallio wrote:
>>I have several SmartUPS (APC 1500s) that run the most critical machines and
>>dictate to the slaves.
>
>I believe the SmartUPS can be programmed to wait before they start to 
>supply power. If I read the apcupsd docs correctly you can check you 
>settings with "apcaccess eeprom".
>
>It should return the UPS settings like this:
>
>>  ConfigCurrent  Permitted
>>Description  Directive ValueValues
>>===
>>Upper transfer voltage   HITRANSFER253  253 264 271 280
>>Lower transfer voltage   LOTRANSFER196  196 188 208 204
>>Return treshold  RETURNCHARGE  000 15 50 90
>>Output voltage on batts  OUTPUTVOLTS   230  230 240 220 225
>>Sensitivity  SENSITIVITY   HH M L L
>>Low battery warning  LOWBATT   202 05 07 10
>>Shutdown grace delay SLEEP 20   020 180 300 600
>>Alarm delay  BEEPSTATE 00 T L N
>>Wakeup delay WAKEUP0000 060 180 300
>>Self test interval   SELFTEST  336  336 168 ON  OFF
>
>You can set the 'Return treshold' to 15% or the 'Wakeup delay' to 180 
>seconds to avoid the problem you described.
>
>>The slaves have dumb UPS, so nothing is cut 'n
>>dried. I don't even know why they send a serial cable with the dumb UPses.
>>I've watched folks waste days trying to make the dumbies communicate just
>>because they got the cable with the new unit.
>
>You can't really communicate with the dumb UPSes. They use the serial 
>port status lines (RTS, CTS, DCD, DTR etc) to signal the basic 
>status: OnLine, OnBattery, BatteryLow etc. You can also signal the 
>UPS to shut down via the control lines.
>
>NUT can use this kind of communication with the genericups driver.
>-- 
>Cheers,
>Petri
>

Thanks for the tips on the settings. On the other subject of the dumb UPS,
all of the machines are running the apcupsd deamons. They are set to either
Masters or slaves. The masters tell the slaves (running dumb UPS) to shut
down according to each one's config file settings on loss of power. So,
none of the serial cables are attached to the "dummies" it is
conforting to get those "self-test" messages on each machine.

Best regards,
Jack L. Stone,
Administrator

SageOne Net
http://www.sage-one.net
[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>I've never tried this and it's not the ideal method, but it's simple,
>so I offer it for your consideration:
>
>Put your UPS software on the root partition.
>
>In the software which initiates the mains-failure shutdown, just do
>"shutdown -r now" or "init 6" or "reboot" or whatever.
>
>At the top of /etc/rc, if your UPS monitor says that the mains have
>failed, have your UPS controller switch off the UPS output.

This way the system reboots, but the reboot is interrupted with 
powerdown at early stage. Not ideal, I agree, but a solution still.

I'll still try to find a true solution. I'll post whatever I come up with.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>I have several SmartUPS (APC 1500s) that run the most critical machines and
>dictate to the slaves.

I believe the SmartUPS can be programmed to wait before they start to 
supply power. If I read the apcupsd docs correctly you can check you 
settings with "apcaccess eeprom".

It should return the UPS settings like this:

>  ConfigCurrent  Permitted
>Description  Directive ValueValues
>===
>Upper transfer voltage   HITRANSFER253  253 264 271 280
>Lower transfer voltage   LOTRANSFER196  196 188 208 204
>Return treshold  RETURNCHARGE  000 15 50 90
>Output voltage on batts  OUTPUTVOLTS   230  230 240 220 225
>Sensitivity  SENSITIVITY   HH M L L
>Low battery warning  LOWBATT   202 05 07 10
>Shutdown grace delay SLEEP 20   020 180 300 600
>Alarm delay  BEEPSTATE 00 T L N
>Wakeup delay WAKEUP0000 060 180 300
>Self test interval   SELFTEST  336  336 168 ON  OFF

You can set the 'Return treshold' to 15% or the 'Wakeup delay' to 180 
seconds to avoid the problem you described.

>The slaves have dumb UPS, so nothing is cut 'n
>dried. I don't even know why they send a serial cable with the dumb UPses.
>I've watched folks waste days trying to make the dumbies communicate just
>because they got the cable with the new unit.

You can't really communicate with the dumb UPSes. They use the serial 
port status lines (RTS, CTS, DCD, DTR etc) to signal the basic 
status: OnLine, OnBattery, BatteryLow etc. You can also signal the 
UPS to shut down via the control lines.

NUT can use this kind of communication with the genericups driver.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Gary W. Swearingen

I've never tried this and it's not the ideal method, but it's simple,
so I offer it for your consideration:

Put your UPS software on the root partition.

In the software which initiates the mains-failure shutdown, just do
"shutdown -r now" or "init 6" or "reboot" or whatever.

At the top of /etc/rc, if your UPS monitor says that the mains have
failed, have your UPS controller switch off the UPS output.


References: init(8), rc(8), shutdown(8), reboot(8)

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Jack L. Stone

At 07:09 PM 9.27.2002 +0300, Petri Riihikallio wrote:
>>In my case where I DON'T want the machines to restart after complete
>>shutdown, was from an expensive learning experience. In our area
>>(summertime subtropics), sometimes the power comes back on but flips right
>>back off -- just as the machine is trying to restart -- this happened THREE
>>times in one day.
>
>You could get a better UPS :-)
>
>The smarter models can be set up to start supplying power when the 
>battery has been recharged to, say 15%, or after 5 minutes of 
>continuous power.
>-- 
>Cheers,
>Petri
>

I have several SmartUPS (APC 1500s) that run the most critical machines and
dictate to the slaves. The slaves have dumb UPS, so nothing is cut 'n
dried. I don't even know why they send a serial cable with the dumb UPses.
I've watched folks waste days trying to make the dumbies communicate just
because they got the cable with the new unit.

Best regards,
Jack L. Stone,
Administrator

SageOne Net
http://www.sage-one.net
[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread David Siebörger

On Fri 2002-09-27 (19:03), Petri Riihikallio wrote:
> You have an APC "smart" model, I have a dumb one. The smart ones have 
> a "shutdown grace period". That is, they don't kill the power 
> immediately after the -k command, but after a delay. That -d 3 should 
> make it 3 seconds, which is kind of short. The default delay is 20 
> seconds. If there are no stuck processes, it should be OK. You could 
> increase the delay to 60 seconds to be sure that the system is 
> lifeless.

Correction: the -d switch sets how long newapc will hang around
waiting for; the length of time that the UPS waits before shutting
down is set using upsct2.  I've used -d 3 so that newapc exits
quickly, the shutdown completes, and the PC powers down.

> You shouldn't have any fear of the deadlock, since the smart APC 
> UPSes obey the killpower command even if the power returns. It is 
> just the dumb ones to worry about.

Hmm... then I'm afraid I'm out of ideas.


-- 
David Siebörger
[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>In my case where I DON'T want the machines to restart after complete
>shutdown, was from an expensive learning experience. In our area
>(summertime subtropics), sometimes the power comes back on but flips right
>back off -- just as the machine is trying to restart -- this happened THREE
>times in one day.

You could get a better UPS :-)

The smarter models can be set up to start supplying power when the 
battery has been recharged to, say 15%, or after 5 minutes of 
continuous power.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>The way I've set it up, upsmon (part of NUT) issues a 'shutdown -p'
>when the battery is low.  A local hack to rc.shutdown then instructs
>the UPS to turn itself off a few seconds later, by running:
>
> /usr/local/libexec/nut/newapc -a su1000 -k -d 3
>
>In the scenario you describe, things would work like this:
>
>  - mains power fails, and the UPS runs on battery power
>  - eventually, the battery runs low
>  - upsmon starts the shutdown process
>  - rc.shutdown tells the UPS to turn itself off
>  - the PC turns itself off
>  - some seconds later, the UPS shuts down as instructed, without
>draining its battery
>  - mains power is restored
>  - the UPS notices that power is restored, powers up again, and the
>PC boots
>
>There is still a short period during which deadlock could occur
>(between the PC shutting down and the UPS shutting down), but this is
>far shorter than the time between the PC shutting down and UPS
>draining its battery.

Darn! You have a better UPS than I! :-(

You have an APC "smart" model, I have a dumb one. The smart ones have 
a "shutdown grace period". That is, they don't kill the power 
immediately after the -k command, but after a delay. That -d 3 should 
make it 3 seconds, which is kind of short. The default delay is 20 
seconds. If there are no stuck processes, it should be OK. You could 
increase the delay to 60 seconds to be sure that the system is 
lifeless.

You shouldn't have any fear of the deadlock, since the smart APC 
UPSes obey the killpower command even if the power returns. It is 
just the dumb ones to worry about.

Using the shutdown grace period is one way to circumvent the problem. 
It is documented in the NUT docs. I don't have that option and that's 
why I am trying to make the system ready to power off.

Beware of the clueless salesmen! The salesperson who sold me the 
UPSes wouldn't understand the problem even if he tried to. And I 
thought I was bright when I cleared the VA, W, Ah, 
stand-by/line-interactive/double-conversion mess!
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Jack L. Stone

At 05:14 PM 9.27.2002 +0200, David Siebörger wrote:
>On Fri 2002-09-27 (14:00), Petri Riihikallio wrote:
>> Have you thought about this situation:
>> 
>> 1. The UPS is almost empty, and the monitoring system issues shutdown -p
>> 2. The system starts the shutdown sequence. It can take well over a 
>> minute. There is no way to stop it now.
>> 3. Power returns before the UPS is completely empty.
>> 
>> Now the system has shut down with the -p flag, but power is 
>> continuously available. The system won't boot automatically, no 
>> matter what you have set up in BIOS, because the power never was down.
>
>The way I've set it up, upsmon (part of NUT) issues a 'shutdown -p'
>when the battery is low.  A local hack to rc.shutdown then instructs
>the UPS to turn itself off a few seconds later, by running:
>
>/usr/local/libexec/nut/newapc -a su1000 -k -d 3
>
>In the scenario you describe, things would work like this:
>
> - mains power fails, and the UPS runs on battery power
> - eventually, the battery runs low
> - upsmon starts the shutdown process
> - rc.shutdown tells the UPS to turn itself off
> - the PC turns itself off
> - some seconds later, the UPS shuts down as instructed, without
>   draining its battery
> - mains power is restored
> - the UPS notices that power is restored, powers up again, and the
>   PC boots
>
>There is still a short period during which deadlock could occur
>(between the PC shutting down and the UPS shutting down), but this is
>far shorter than the time between the PC shutting down and UPS
>draining its battery.
>
>
>-- 
>David Siebörger
>[EMAIL PROTECTED]

In my case where I DON'T want the machines to restart after complete
shutdown, was from an expensive learning experience. In our area
(summertime subtropics), sometimes the power comes back on but flips right
back off -- just as the machine is trying to restart -- this happened THREE
times in one day. One machine did not survive the abuse and it fried the
motherboard and damaged one memory strip beyond reliability. So, no thanks
to the unattended restarts after being in the trenches like this. It only
happens once oe twice in a year, but ONCE is more than enough for me!!
If you don't have this type of problem, then okay. But, how would you
know...???

Best regards,
Jack L. Stone,
Administrator

SageOne Net
http://www.sage-one.net
[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread David Siebörger

On Fri 2002-09-27 (14:00), Petri Riihikallio wrote:
> Have you thought about this situation:
> 
> 1. The UPS is almost empty, and the monitoring system issues shutdown -p
> 2. The system starts the shutdown sequence. It can take well over a 
> minute. There is no way to stop it now.
> 3. Power returns before the UPS is completely empty.
> 
> Now the system has shut down with the -p flag, but power is 
> continuously available. The system won't boot automatically, no 
> matter what you have set up in BIOS, because the power never was down.

The way I've set it up, upsmon (part of NUT) issues a 'shutdown -p'
when the battery is low.  A local hack to rc.shutdown then instructs
the UPS to turn itself off a few seconds later, by running:

/usr/local/libexec/nut/newapc -a su1000 -k -d 3

In the scenario you describe, things would work like this:

 - mains power fails, and the UPS runs on battery power
 - eventually, the battery runs low
 - upsmon starts the shutdown process
 - rc.shutdown tells the UPS to turn itself off
 - the PC turns itself off
 - some seconds later, the UPS shuts down as instructed, without
   draining its battery
 - mains power is restored
 - the UPS notices that power is restored, powers up again, and the
   PC boots

There is still a short period during which deadlock could occur
(between the PC shutting down and the UPS shutting down), but this is
far shorter than the time between the PC shutting down and UPS
draining its battery.


-- 
David Siebörger
[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>I don't *think* that any of those daemons would be harmed by unmounting the
>drives.  After all, you can 'kill -9' them without any permanent bad
>effects.

kern_shutdown.c kills all processes with signals, flushes and syncs 
disks etc. It just seems silly to try to duplicate a kernel function 
with a shell script. Reinventing the wheel with inferior tools, isn't 
it?

>I would think so.  Other people have mentioned the 'shutdown -p' command;
>does it do what you need?

No. It just powers down the system. You need a power-cycle to 
activate BIOS autoboot. If the UPS is still supplying its last drops 
of power when the AC power returns, there won't be any power-cycle 
and therefore no autoboot either.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Jack L. Stone

At 05:55 PM 9.27.2002 +0300, Petri Riihikallio wrote:
>>===> What happens if power returns AFTER this final decision, but BEFORE
>>the system is actually shut down? The time frame can be over a minute.<===
>>
>>Interesting! This is the most I can recall being discussed about UPS for
>>the past year. Glad we are doing it, but I still don't see the problem
>>here. Once the script turns over to the "shutdown -p now", doesn't apcupsd
>>exit (along with the other shutdowns) and stop monitoring..???
>
>Yes, apcupsd gets killed and the system is powered down (-p) or 
>halted (-h). But if the AC power is restored _before_ the UPS is 
>exhausted, there is no power cycle, and the computer won't boot 
>without operator assistance.
>
>This is the situation I am trying to avoid.
>-- 
>Cheers,
>Petri

Okay, I DON'T want my machines to reboot automatically after the power
down so, guess I'm configured okay to suit my intentions. But I'll
remember this if and when I want the machines to boot by themselves

Best regards,
Jack L. Stone,
Administrator

SageOne Net
http://www.sage-one.net
[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>===> What happens if power returns AFTER this final decision, but BEFORE
>the system is actually shut down? The time frame can be over a minute.<===
>
>Interesting! This is the most I can recall being discussed about UPS for
>the past year. Glad we are doing it, but I still don't see the problem
>here. Once the script turns over to the "shutdown -p now", doesn't apcupsd
>exit (along with the other shutdowns) and stop monitoring..???

Yes, apcupsd gets killed and the system is powered down (-p) or 
halted (-h). But if the AC power is restored _before_ the UPS is 
exhausted, there is no power cycle, and the computer won't boot 
without operator assistance.

This is the situation I am trying to avoid.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Jack L. Stone

At 05:11 PM 9.27.2002 +0300, Petri Riihikallio wrote:
>>Have you looked at the script I'm referring to...?? It's the one provided
>>by apccontrol as I recall which contains several "shutdown -h" commands
>>which can be stopped and go back to business if the power returns because
>>apcupsd checks to see if the power is back before it runs the shutdown part
>>of the script.
>
>Yes, I have looked through the apcupsd package. Thank you for 
>pointing it out. It is very similar to NUT, but only for APC devices 
>(as the name implies :-)
>
>Have you looked at apcupsd-3.8.5/distributions/suse/halt.in ? It does 
>to SuSe what I would like to with FreeBSD. The README in 
>distributions directory recommends SuSe as the best implementation.
>
>>The "shutdown -p" is only run as the final decision by apcupsd to shut down
>>the machine.
>
>What happens if power returns AFTER this final decision, but BEFORE 
>the system is actually shut down? The time frame can be over a minute.
>-- 
>Cheers,
>Petri
>

===> What happens if power returns AFTER this final decision, but BEFORE 
the system is actually shut down? The time frame can be over a minute.<===

Interesting! This is the most I can recall being discussed about UPS for
the past year. Glad we are doing it, but I still don't see the problem
here. Once the script turns over to the "shutdown -p now", doesn't apcupsd
exit (along with the other shutdowns) and stop monitoring..??? Or, am I
missing something here (probably)?

Best regards,
Jack L. Stone,
Administrator

SageOne Net
http://www.sage-one.net
[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Kirk Strauser


At 2002-09-27T13:45:42Z, Kirk Strauser <[EMAIL PROTECTED]> writes:

> I would think so.  Other people have mentioned the 'shutdown -p' command;
> does it do what you need?

I wrote that before reading some of the other messages - feel free to ignore
it.
-- 
Kirk Strauser
In Googlis non est, ergo non est.

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>Have you looked at the script I'm referring to...?? It's the one provided
>by apccontrol as I recall which contains several "shutdown -h" commands
>which can be stopped and go back to business if the power returns because
>apcupsd checks to see if the power is back before it runs the shutdown part
>of the script.

Yes, I have looked through the apcupsd package. Thank you for 
pointing it out. It is very similar to NUT, but only for APC devices 
(as the name implies :-)

Have you looked at apcupsd-3.8.5/distributions/suse/halt.in ? It does 
to SuSe what I would like to with FreeBSD. The README in 
distributions directory recommends SuSe as the best implementation.

>The "shutdown -p" is only run as the final decision by apcupsd to shut down
>the machine.

What happens if power returns AFTER this final decision, but BEFORE 
the system is actually shut down? The time frame can be over a minute.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>The fact of the matter is that if the timing is *just* wrong you
>probably can't automatically recover.  How likely is that to happen?

Power outages are rare and short around here. I remember one that 
lasted for an hour in the last five years. It made headlines.

My UPS is good for ca. 15 min. It is mainly intended for a safe 
shutdown rather than keeping the system up. The runtime is roughly 
the same as a "typical" power shortage. It takes a while for the 
power company to notice the outage, locate the reason, isolate it, 
and start supplying power some other route.

This makes the deadlock look possible.

On the other hand, my system usually shuts down quite quickly: 15 - 
20 seconds.  Only if there are some stuck processes it could take 
over a minute when init kindly waits for the processes to die before 
it uses violence.

I have no data about the distribution of the outages, but the 
likeliness could be of the order of one out of ten or twenty.

Considering the heated debates about the lengths of the encryption 
keys and other security measures in FreeBSD, this should be solved in 
a reasonable way.

>But, if you want to be "super safe," then you should be able to
>"shutdown" rather than than "shutdown -h" or "shutdown -p."  This
>should do most of the steps of shutdown and get all the users off to
>make partitions non-busy.  It may even umount all the partitions; I
>can't quite recall.
>
>Then it will start up /bin/sh.
>
>I can't recall whether /bin/sh will run any of the 'normal' startup
>scripts under this circumstance, but even if it does not you can
>replace it with a munged one that does . . .
>
>But the idea would be that on power-down you set a special
>"powering-down" file just before you issue the "shutdown."
>
>The /bin/csh startup scripts check and if that is set, they go into
>"shutdown mode", which umounts all but the root partition, remount the
>root partition read-only, and then the simply sleep for 120 seconds or
>so, and then "shutdown -r now."  (Of course it should remove that
>special marker file before it does anything else lest the system go
>into a loop.)
>
>Now, one of two things happens: either you really *did* power off, in
>which case the "sleep" never wakes up, because without power it can't
>go on.  Then when you get power back, the BIOS does its thing and you
>reboot.  Or the power never went off, in which after two minutes
>everything reboots.

This is a novel idea! I'll have to do some reaseach.

I thought about sending init the TERM signal, which puts it in single 
user mode, but my script wouldn't survive it. I couldn't figure out 
how to continue the shutdown script.

The powering-down flag is already available. Both NUT and apcupsd 
create such a file automatically for themselves.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Kirk Strauser


At 2002-09-27T11:21:18Z, Petri Riihikallio <[EMAIL PROTECTED]> writes:

> Thank you for your thoughts.

You are quite welcome.

>> I think that the biggest hurdle will be making sure that your filesystems
>> are cleanly unmounted.

> Yes, something like that should be done.

> There are still all the system daemons (sshd, postfix, named..)  started
> from rc that are still running. Should I try to notify them first? How
> will they react when disks change to read-only?

I don't *think* that any of those daemons would be harmed by unmounting the
drives.  After all, you can 'kill -9' them without any permanent bad
effects.

> I believe somebody (more competent than I) has written the necessary
> script for FreeBSD.

I would think so.  Other people have mentioned the 'shutdown -p' command;
does it do what you need?
-- 
Kirk Strauser

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>  > I didn't discover this problem myself. It is documented in
>>  http://www.apcupsd.com/users_manual/shutdown.html ("automatic
>>  reboot") and http://www.exploits.org/nut/docs/1.0.0/shutdown.html
>  > ("power race"). It is just that I haven't found any FreeBSD solution.
>
>Now I'm with you ... I think you have hit a limitation of FreeBSD rather
>than a bug/feature/whatever of the UPS software.

I don't think FreeBSD has any fundamental limitation in this respect. 
This is just a problem that needs to be solved. If nothing else 
helps, I can write a custom version of kern_shutdown.c. I just 
thought somebody had already solved this and I didn't want to 
reinvent the wheel.

>I'm way to green to be able to help, but thanks for taking the time to
>re-explain your situation.

No problem at all. Re-explaining the problem forces me to think it 
over from another viewpoint. It might bring me or somebody else 
closer to the solution. Thank you for you thought effort, too!
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Oliver Fromme

Petri Riihikallio <[EMAIL PROTECTED]> wrote:
 > I have a FreeBSD 4.6.2 box and an UPS. I have chosen NUT 
 > (http://www.exploits.org/nut) as my UPS monitor. Everything compiles 
 > and runs fine. I have a problem with the shutdown script.
 > 
 > How do I shut down the system properly?
 > [...]
 > stop)
 > if (test -f /etc/killpower) then
 > echo "Killing the power, bye!"
 > /bin/sync

"sync" is pretty much useless, it doesn't buy you anything.
Particularly, it won't mark your filesystems clean (so fsck
will still have to run on the next boot), and it does not
guarantee that there's no unwritten data left in memory.

 > ### what to do here ?
 > /usr/local/bin/upsdrvctl shutdown
 > ### never makes it this far

Oh yes, it will.  When the upsdrvctl powers the UPS off,
there are still at least several milliseconds of power
left to do lots of things.  :-)

 > I have called it znut.sh, so it should run last after all other 
 > shutdown scripts. (Nothing else runs after it in a powerfail 
 > situation ;-) Can I rely on alphabetical ordering?

No.  Upon shutdown, the scripts will be executed in reverse
ASCII order.  You should rather call it something like
"%%%whatever".  There's never a guarantee, however, that
some clever port tries to install a "%%foo" script in
order to get there first ...

Apart from that, there can be multiple directories with
start/stop scripts, which will all be visited in order.
By default, /usr/X11R6/etc/rc.d is used, too.

So, maybe the best thing is to add your script at the end
of /etc/rc.shutdown directly.

 > When the script finds the "/etc/killpower" file it syncs the disks 

.. which is useless ...

 > My problem is that the disks aren't clean.

Right.  You have to unmount them, or remount read-only.

 > If I put "umount -a" after the sync, I can't run the upsdrvctl from 
 > /usr. Should I remount /usr read-only?

Yes, exactly.  This should do:

umount -f -A
mount -u -o ro /
mount -o ro /usr

Or compile upsdrvctl as a static binary and copy it to your
root file system, so you don't need /usr.

BTW, you do not need sync.

 > I have read man pages for mount and umount. Both provide the -f flag, 
 > but warn against using it. Could I make use of it?

Yes, that should be save, because at that point the programs
get killed anyway.

 > What happens after the rc.shutdown? Are there any other housekeeping 
 > tasks after user scripts? I couldn't find any docs on that.

That's documented in /usr/src/sbin/init/init.c.

Regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"All that we see or seem is just a dream within a dream" (E. A. Poe)

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Brian T. Schellenberger




On Friday 27 September 2002 07:01 am, Petri Riihikallio wrote:
| >h I use apcupsd from ports which has shown to be very
| > reliable and has great docs. It has been months since I looked at
| > this stuff, but remember something like this issue you make was
| > covered in detail.
|
| Thanks, good pointer:
| http://www.apcupsd.com/users_manual/shutdown.html discusses the
| problem. In RedHat the disks are mounted back read-only at shutdown.
| I'll have to check how the FreeBSD port implements this.
|
| >I don't have any BIOS conflict that you mention that
| >will fight the daemons. They will shut down even if the power
| > returns if the minimum has been reached or exceeded. There are also
| > other settings that check things and allow the machines to resume
| > proper operation -- however, once the "doomsday" point is reached
| > -- the "shutdown -p now" will prevail. It will then require manual
| > restarts of those that are shut down.
|
| I don't want to argue, but..
|
| I have no BIOS conflict per se. I have just set up my BIOS to boot
| the system when power appears. The problem is: What happens if power
| never disappears?

The fact of the matter is that if the timing is *just* wrong you 
probably can't automatically recover.  How likely is that to happen?

But, if you want to be "super safe," then you should be able to 
"shutdown" rather than than "shutdown -h" or "shutdown -p."  This 
should do most of the steps of shutdown and get all the users off to 
make partitions non-busy.  It may even umount all the partitions; I 
can't quite recall.

Then it will start up /bin/sh.

I can't recall whether /bin/sh will run any of the 'normal' startup 
scripts under this circumstance, but even if it does not you can 
replace it with a munged one that does . . .

But the idea would be that on power-down you set a special 
"powering-down" file just before you issue the "shutdown."

The /bin/csh startup scripts check and if that is set, they go into 
"shutdown mode", which umounts all but the root partition, remount the 
root partition read-only, and then the simply sleep for 120 seconds or 
so, and then "shutdown -r now."  (Of course it should remove that 
special marker file before it does anything else lest the system go 
into a loop.)

Now, one of two things happens: either you really *did* power off, in 
which case the "sleep" never wakes up, because without power it can't 
go on.  Then when you get power back, the BIOS does its thing and you 
reboot.  Or the power never went off, in which after two minutes 
everything reboots.





 

|
| "shutdown -p now" kills apcupsd before it turns the power off. There
| is a time frame when there is no monitoring software running. If
| power returns in that time frame, you have to boot up manually. In
| RedHat Linux apcupsd is run once more in single-user mode with
| "/etc/apcupsd/apccontrol killpower".
|
| It appears you could test your setup with "/etc/apcupsd/apccontrol
| doshutdown". Do not pull the plug, just let the software shut down
| the system. If it reboots after a while - you have no problem. The
| "while" depends on shutdown grace delay, which value you can check
| with "apcaccess eeprom". I have a dumb BackUPS, so I don't have any
| delay.
|
| Thank you for your time!

-- 
Brian, the man from Babble-On . . . .   [EMAIL PROTECTED] (personal)

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>>What is wrong with
>>
>>   shutdown -p now
>>
>>?
>>
>>(Or shutdown -h now, if you don't have APM?)

The system is helpless, if the power returns before the UPS shuts 
down. Since there won't be any power-out, there won't be autoboot at 
power-return.

The time frame is over a minute. That's why the UPS can (and should) 
power down the system.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

Thank you for your thoughts.

>I haven't actually done this, so take my advice with a grain of salt.
>
>I think that the biggest hurdle will be making sure that your filesystems
>are cleanly unmounted.  I would *think* that:
>
>   umount -af
>   sync; sync; sync
>   umount -fr /
>
>should unmount everything except / , which it would remount as read-only.

Yes, something like that should be done.

There are still all the system daemons (sshd, postfix, named..) 
started from rc that are still running. Should I try to notify them 
first? How will they react when disks change to read-only?

Here is a snippet of SuSe Linux halt script for apcupsd:

># Write to wtmp file before unmounting /var
>$command -w
>
>echo "Sending all processes the TERM signal..."
>killall5 -15
>
>if [ "$1" = "fast" ]; then
>   sleep 1
>else
>   sleep 5
>fi
>
>echo "Sending all processes the KILL signal..."
>killall5 -9
>
>echo "Turning off swap."
>sync ; sync
>swapoff -a
>
>echo "Unmounting file systems"
>umount -av
>
># See if this is a powerfail situation.
>if [ -f @PWRFAILDIR@/powerfail ]; then
>   echo "APCUPSD attempting to shutoff UPS power"
>   echo
>   @sysconfdir@/apccontrol killpower
>   echo
>fi

I believe somebody (more competent than I) has written the necessary 
script for FreeBSD.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

Thanks for your reply!

>Maybe the question wasn't the clearest?

The problem is hard to explain. The post should be short, but include 
all information. Apparently I was too terse.

>>It doesn't feel right to crash after the UPS has run dry. (I don't 
>>have a generator.) About the first thing I was tought about Unix 
>>system administration was: "Always shut down properly". That's why 
>>I bought the UPS.
>
>How could you crash after the UPS has run dry?  You say you are 
>using NUT, then NUT should be able to initiate a system shutdown 
>_before_ the UPS runs out of juice - check your timings, don't let 
>the system run for longer than you have the capacity for.
>
>Maybe you should do "shutdown -h now" to actually halt the system, 
>then when the UPS powers off everything is dead.  If the power comes 
>back on, the UPS recharges a bit and then powers up your system 
>normally.

The problem is: What happens if power never disappears?

The situation I am worried about goes like this:

1. The UPS is almost empty, and the monitoring system issues shutdown -p.
2. The system starts the shutdown sequence. It can take well over a 
minute. There is no way to stop it now.
3. Power returns before the UPS is completely empty.

Now the system has shut down, but power is continuously available. 
The system won't boot automatically, no matter what you have set up 
in BIOS, because the power never goes down. With shutdown -h the 
system waits for a keypress to reboot.

It is a timing issue. You need plenty of bad luck to see it happen. 
But that's why UPSes have a way of killing battery power. This 
guarantees at least a short break of power. When the power returns, 
the BIOS settings can start the system.

>How can you send a command to the UPS _after_ the system has powered down?

:-) It is a chicken/egg-problem. The system can't send commands after 
powerdown, but if I issue the powerdown from multi-user system, the 
power disappears immediately. That's why I need to issue the 
powerdown command at the very end of shutdown, as close to cpu_halt() 
as possible.

In Linux scripts for apcupsd there is a halt-script to be run after 
everything else. The interesting part kills all other processes 
except for init and itself, unmounts all disks and stops swapping. 
The system is effectively in single-user state when the power 
disappears.

In FreeBSD there is no killall5, but I could write a replacement. 
Swapping can't be stopped in FreeBSD, but that is the case for normal 
shutdown as well. I can't run the UPS-shutdown command from 
/usr/local/bin after unmounting disks, so should I copy the UPS 
software to /bin or remount /usr read-only ?

I believed somebody else (more competent than I) would have written 
the necessary scripts.

apcupsd/halt.sh for SuSe (snippet):

># Write to wtmp file before unmounting /var
>$command -w
>
>echo "Sending all processes the TERM signal..."
>killall5 -15
>
>if [ "$1" = "fast" ]; then
>   sleep 1
>else
>   sleep 5
>fi
>
>echo "Sending all processes the KILL signal..."
>killall5 -9
>
>echo "Turning off swap."
>sync ; sync
>swapoff -a
>
>echo "Unmounting file systems"
>umount -av
>
># See if this is a powerfail situation.
>if [ -f @PWRFAILDIR@/powerfail ]; then
>   echo "APCUPSD attempting to shutoff UPS power"
>   echo
>   @sysconfdir@/apccontrol killpower
>   echo
>fi

The FreeBSD scripts have nothing like this. They just issue a 
shutdown -h and hope for the UPS to drain :-)

I didn't discover this problem myself. It is documented in 
http://www.apcupsd.com/users_manual/shutdown.html ("automatic 
reboot") and http://www.exploits.org/nut/docs/1.0.0/shutdown.html 
("power race"). It is just that I haven't found any FreeBSD solution.

Did this clarify the problem at all?
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>I have a small program that monitors an APC smart 700 that does what
>you are talking about... I do not really remember how it does it.
>
>If you are interested I can email you the source code.

Thank you, but I have the BackUPS 650, which is dumb. The serial 
control is completely different from the smart models.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>h I use apcupsd from ports which has shown to be very reliable and
>has great docs. It has been months since I looked at this stuff, but
>remember something like this issue you make was covered in detail.

Thanks, good pointer: 
http://www.apcupsd.com/users_manual/shutdown.html discusses the 
problem. In RedHat the disks are mounted back read-only at shutdown. 
I'll have to check how the FreeBSD port implements this.

>I don't have any BIOS conflict that you mention that
>will fight the daemons. They will shut down even if the power returns if
>the minimum has been reached or exceeded. There are also other settings
>that check things and allow the machines to resume proper operation --
>however, once the "doomsday" point is reached -- the "shutdown -p now" will
>prevail. It will then require manual restarts of those that are shut down.

I don't want to argue, but..

I have no BIOS conflict per se. I have just set up my BIOS to boot 
the system when power appears. The problem is: What happens if power 
never disappears?

"shutdown -p now" kills apcupsd before it turns the power off. There 
is a time frame when there is no monitoring software running. If 
power returns in that time frame, you have to boot up manually. In 
RedHat Linux apcupsd is run once more in single-user mode with 
"/etc/apcupsd/apccontrol killpower".

It appears you could test your setup with "/etc/apcupsd/apccontrol 
doshutdown". Do not pull the plug, just let the software shut down 
the system. If it reboots after a while - you have no problem. The 
"while" depends on shutdown grace delay, which value you can check 
with "apcaccess eeprom". I have a dumb BackUPS, so I don't have any 
delay.

Thank you for your time!
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-27 Thread Petri Riihikallio

>No, you are not the only one using UPS, but in my case, I don't use NUT and
>don't quite understand the problem you have with the shutdown. My scripts
>use shutdown -p just fine (rather than shutdown -h). It will only use that
>when it reaches the final designated time to do so. If power returns, then
>it stops the countdown just flawlessly and returns to normal operations. It

Thanks for your reply!

Have you thought about this situation:

1. The UPS is almost empty, and the monitoring system issues shutdown -p
2. The system starts the shutdown sequence. It can take well over a 
minute. There is no way to stop it now.
3. Power returns before the UPS is completely empty.

Now the system has shut down with the -p flag, but power is 
continuously available. The system won't boot automatically, no 
matter what you have set up in BIOS, because the power never was down.

It is a timing issue. That's why UPSes have a way of killing battery 
power. This guarantees at least a short break of power. When the 
power returns, the BIOS settings can start the system.

I currently have a setup like yours, but now that I am aware of the 
possibility of deadlock, I would like to avoid it.
-- 
Cheers,
Petri

Metis / Petri Riihikallio
GSM: +358 400 505 939

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-26 Thread Rob B

At 17:02 26/09/2002 +0300, Petri Riihikallio sent this up the stick:

>A couple of days ago I sent a message asking how to shut down a FreeBSD 
>system when I KNOW the power will be off after the next script command.
>
>Nobody has commented yet.

Maybe the question wasn't the clearest?

>Am I the only one using an UPS with FreeBSD?

Not at all

>It doesn't feel right to crash after the UPS has run dry. (I don't have a 
>generator.) About the first thing I was tought about Unix system 
>administration was: "Always shut down properly". That's why I bought the UPS.

How could you crash after the UPS has run dry?  You say you are using NUT, 
then NUT should be able to initiate a system shutdown _before_ the UPS runs 
out of juice - check your timings, don't let the system run for longer than 
you have the capacity for.

How can you send a command to the UPS _after_ the system has powered 
down?  Why tell the UPS to shutdown - your UPS should be able to turn 
itself off when it runs out of battery.

Maybe you should do "shutdown -h now" to actually halt the system, then 
when the UPS powers off everything is dead.  If the power comes back on, 
the UPS recharges a bit and then powers up your system normally.

Or maybe I can't understand what you are trying to do

Cheers,
Rob

>At 22:20 +0300 22.9.2002, Petri Riihikallio wrote:
>>Hello
>>
>>I have a FreeBSD 4.6.2 box and an UPS. I have chosen NUT 
>>(http://www.exploits.org/nut) as my UPS monitor. Everything compiles and 
>>runs fine. No problems with NUT. I have a problem with the shutdown script.
>>
>>How do I shut down the system properly?
>>
>>The problem is that I want to issue the command "upsdrvctl shutdown", 
>>which switches off the power from the UPS. What do I need to do before that?
>>
>>To be more specific: When the AC power is down and the UPS is almost 
>>exhausted, NUT creates a file "/etc/killpower" and starts system shutdown 
>>with "shutdown -h now". Init then runs all scripts in /usr/local/etc/rc.d 
>>with argument "stop". I have put a script like this in my /usr/local/etc/rc.d
>>
>>-/usr/local/etc/rc.d/znut.sh:
>>#! /bin/sh
>>case $1 in
>>start)
>> su nut -c /usr/local/libexec/upsdrvctl start
>> su nut -c /usr/local/sbin/upsd
>> /usr/local/upsmon
>> ;;
>>stop)
>> if (test -f /etc/killpower) then
>> echo "Killing the power, bye!"
>> /bin/sync
>> ### WHAT TO DO HERE ?  ###
>> /usr/local/bin/upsdrvctl shutdown
>> ### never makes it this far
>> else
>> killall upsmon
>> killall upsd
>> /usr/local/libexec/upsdrvctl stop
>> fi
>> ;;
>>*)
>> echo "Usage: $0: [ start | stop ]" 2>&1
>> exit 65
>> ;;
>>esac
>>---
>>
>>I have called the script znut.sh, so it should run last after all other 
>>shutdown scripts. (Nothing else runs after it in a powerfail situation 
>>;-) Can I rely on alphabetical ordering?
>>
>>When my script finds the "/etc/killpower" file it syncs the disks and 
>>switches the UPS off. This is necessary, since the power might return 
>>when the system is in the "Press any key to reboot"-state. Then it would 
>>wait for the keypress indefinitely.
>>
>>NUT can't use "shutdown -r now", since the system might start a reboot 
>>while the UPS still supplies power. NUT can't use "shutdown -p now", 
>>since if the power is restored before the UPS runs dry, the system won't 
>>boot automatically.
>>
>>The "upsdrvctl shutdown" avoids these deadlocks by killing power at the 
>>UPS. When the AC power returns, the UPS first recharges, then it starts 
>>supplying power and my BIOS is set up to boot when power returns.
>>
>>My problem is that the disks aren't clean.
>>
>>If I put "umount -a" after the sync, I can't run the upsdrvctl from /usr. 
>>Should I remount /usr read-only? Or should I move the NUT programs to 
>>/bin and "umount -A". This would leave root dirty.
>>
>>I have read man pages for mount and umount. Both provide the -f flag, but 
>>warn against using it. Could I make use of it?
>>
>>The "sync" man page tells that halt is better since it does more than 
>>just a sync. Can I emulate these functions of halt from a script?
>>
>>What happens after the rc.shutdown? Are there any other housekeeping 
>>tasks after user scripts? I couldn't find any docs on that.
>
>--
>The only number that is both even and odd is infinity.
>
>This is random quote 1025 of a collection of 1253
>[15200.8 km (8207.8 mi), 262.8 deg](Apparent) Rennerian


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-26 Thread Jack L. Stone

At 05:02 PM 9.26.2002 +0300, Petri Riihikallio wrote:
>Hello
>
>A couple of days ago I sent a message asking how to shut down a 
>FreeBSD system when I KNOW the power will be off after the next 
>script command.
>
>Nobody has commented yet.
>
>Am I the only one using an UPS with FreeBSD?
>



No, you are not the only one using UPS, but in my case, I don't use NUT and
don't quite understand the problem you have with the shutdown. My scripts
use shutdown -p just fine (rather than shutdown -h). It will only use that
when it reaches the final designated time to do so. If power returns, then
it stops the countdown just flawlessly and returns to normal operations. It
works on all of the FBSD machines and those running Windoze desktops. Some
are Masters (those are FBSD) and some are slaves (FBSD & WINs). Some share
the same APC and some do not. The ones that do not are attached to dumb UPS
backups, but are still told what to do by the APC master machines i.e.,
shutdown or continue.

So, I have not jumped into this because it is complicated enough without
trying to discuss accross different daemons

Best regards,
Jack L. Stone,
Administrator

SageOne Net
http://www.sage-one.net
[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-26 Thread Brian T. Schellenberger


What is wrong with

  shutdown -p now

?

(Or shutdown -h now, if you don't have APM?)

On Thursday 26 September 2002 11:09 am, Kirk Strauser wrote:
| At 2002-09-26T14:02:01Z, Petri Riihikallio 
<[EMAIL PROTECTED]> writes:
| > A couple of days ago I sent a message asking how to shut down a
| > FreeBSD system when I KNOW the power will be off after the next
| > script command.
|
| I haven't actually done this, so take my advice with a grain of salt.
|
| I think that the biggest hurdle will be making sure that your
| filesystems are cleanly unmounted.  I would *think* that:
|
|   umount -af
|   sync; sync; sync
|   umount -fr /
|
| should unmount everything except / , which it would remount as
| read-only.

-- 
Brian, the man from Babble-On . . . .   [EMAIL PROTECTED] (personal)

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-26 Thread Kirk Strauser


At 2002-09-26T14:02:01Z, Petri Riihikallio <[EMAIL PROTECTED]> writes:

> A couple of days ago I sent a message asking how to shut down a FreeBSD
> system when I KNOW the power will be off after the next script command.

I haven't actually done this, so take my advice with a grain of salt.

I think that the biggest hurdle will be making sure that your filesystems
are cleanly unmounted.  I would *think* that:

  umount -af
  sync; sync; sync
  umount -fr /

should unmount everything except / , which it would remount as read-only.
-- 
Kirk Strauser
In Googlis non est, ergo non est.

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message



Re: How to shut down cleanly by killing power

2002-09-26 Thread Roman Neuhauser

# [EMAIL PROTECTED] / 2002-09-26 17:02:01 +0300:
> Hello
> 
> A couple of days ago I sent a message asking how to shut down a 
> FreeBSD system when I KNOW the power will be off after the next 
> script command.
> 
> Nobody has commented yet.

i think the policy is that it's ok to ask on hackers@ if you don't
receive a (meaningful) reply from questions@ within a few days.

-- 
begin 666 nonexistent.vbs
FreeBSD 4.7-RC
4:15PM up 8 days, 23:30, 12 users, load averages: 0.11, 0.06, 0.02
end

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message