From: Stephane CHAZELAS on
2010-01-13, 00:53(-05), Barry Margolin:
> In article
> <9711e184-7cb6-46e4-9c55-d4b7bd03aea4(a)j19g2000yqk.googlegroups.com>,
> David Schwartz <davids(a)webmaster.com> wrote:
>
>> On Jan 12, 2:20�pm, neilsolent <n...(a)solenttechnology.co.uk> wrote:
>>
>> > The C program below certainly reboots my Solaris 10 system, but it
>> > does not seem to do it cleanly (doesn't send SIGTERM to the running
>> > processes). If I run the Solaris reboot command though, that does seem
>> > to cleanly reboot.
>> > How come?
>>
>> The reboot command sends a SIGTERM to the running process before
>> rebooting and your code doesn't. Your question is self-answering. Your
>> code doesn't send a SIGTERM to the running processes because it
>> contains no code that would do that anywhere in it. It simply commands
>> the system to reboot, so that's what happens.
>>
>> DS
>
> More to the point, the reboot() system call is what the reboot command
> calls AFTER it has broadcast a shutdown notice on all the terminals,
> sent all the SIGTERMs, etc. Eventually it has to tell the OS to reboot,
> and it does it using this system call.

From the reboot man page:

Although reboot can be run by the super-user at any time, shutdown(1M)
is normally used first to warn all users logged in of the impending
loss of service. See shutdown(1M) for details.

NOTES
The reboot utility does not execute the scripts in /etc/rcnum.d or exe-
cute shutdown actions in inittab(4). To ensure a complete shutdown of
system services, use shutdown(1M) or init(1M) to reboot a Solaris sys-
tem.

To sum up, shutdown does more than "telinit 6" that does more
than "reboot"

So system("shutdown -r now") is probably gonna be the best
solution (and probably the most portable as well).

--
St�phane
From: neilsolent on

Thanks for your posts.
I was hoping that the C libs would have a useful system call that took
care of handling a clean reboot.
Going with a modified version of your idea (as "shutdown -r now" is
invalid syntax on my Solaris 10 platform):


[C code]:
system("reboot.sh");

[reboot.sh]
#!/bin/sh

case "`uname -s`" in
'SunOS')
/usr/sbin/shutdown -y -i 6
;;
*)
/sbin/shutdown -r now -t 60
;;
esac


Running this, I find the situation is worse than just calling the
reboot command. Perhaps reboot is sending the SIGTERMs which causes
processes to end that don't have shutdown scripts, whereas shutdown
assumes each process has a shutdown script ?

I am unsure what the best solution is now.
I want a simple way of doing a clean reboot from a C program across
UNIX platforms.

thanks again,
Neil

From: neilsolent on
To recap.
We don't think there is any C function call that will do a clean
reboot on UNIX.
We need to call a shell command.
So we want a shell script that will check the version of UNIX and do a
clean reboot.

On Solaris, I find /usr/bin/shutdown does not seem to SIGTERM all the
processes (I guess - it assumes every process has a shutdown script if
it needs it). I find the reboot command does send a SIGTERM to the
processes. Ideally - the shutdown scripts are run, and remaining
processes are signalled.
Thoughts / experiences anyone?
What's a standard script for rebooting UNIX?

Bueller?

Anyone?

From: Alan Curry on
In article <81648a97-e547-452b-8f4f-b386af42a35c(a)v25g2000yqk.googlegroups.com>,
neilsolent <n(a)solenttechnology.co.uk> wrote:
>To recap.
>We don't think there is any C function call that will do a clean
>reboot on UNIX.

Maybe this is because a reboot is a major event in unix, and if it needs to
be done, it deserves to be supervised by an administrator familiar with the
system (who knows the commands, and can decide how many minutes, hours, or
days ahead of time the downtime should be announced to the users), not by
some third-party shell script hacked together with fragments gathered from
Usenet.

"Reboots are for kernel upgrades", the saying goes...

--
Alan Curry
From: David Schwartz on
On Jan 16, 7:52 am, neilsolent <n...(a)solenttechnology.co.uk> wrote:
> To recap.
> We don't think there is any C function call that will do a clean
> reboot on UNIX.
> We need to call a shell command.
> So we want a shell script that will check the version of UNIX and do a
> clean reboot.

Cannot be done. The proper way to do a clean reboot is critically
system dependent. You must ask a human being for permission and for
instruction.

There is no "one right way" to do a clean reboot. On some machines, it
requires arranging load migration to other machines in the cluster. On
some machines, it can only be done intentionally during a maintenance
window.

> On Solaris, I find /usr/bin/shutdown does not seem to SIGTERM all the
> processes (I guess - it assumes every process has a shutdown script if
> it needs it). I find the reboot command does send a SIGTERM to the
> processes. Ideally - the shutdown scripts are run, and remaining
> processes are signalled.
> Thoughts / experiences anyone?
> What's a standard script for rebooting UNIX?

There is no standard script. Every system is different, and rightfully
and necessarily so.

Why are you rebooting the machine from a script anyway?

DS