Re: Shutdown script (derived from "Simple startup daemon's on boot question?")

Previous thread: Hardened PhP5 (suhosin patch) and XCache, memcached by Artur Litwinowicz on Wednesday, September 19, 2007 - 6:20 am. (1 message)

Next thread: Slow ral(4) 802.11b in hostap mode? by Damon McMahon on Wednesday, September 19, 2007 - 10:37 am. (5 messages)
To: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 7:48 am

Hi list,

Watching the thread about startup script I thought of a question about
shutdown script. Is it necessary to shutdown certain services when
machine goes down? Like for example mysql, dovecot, clamav, amavis or
openvpn. I've never saw anybody do that. Lots of people on their
manuals, tutorials or posts writes how to start mysql, but none of then
writes a shutdown script. So maybe it is not so necessary? (But then
again, mysql is a database engine, and databases should be handle with
care).

To: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 9:33 am

any software which requires special shutdown handling ist busted.

all processes get a SIGTERM on shutdown. the ones that need to do
cleanup before they exit need to install a signal handler for that (and
in general they do).

--
Henning Brauer, hb@bsws.de, henning@openbsd.org
BS Web Services, http://bsws.de
Full-Service ISP - Secure Hosting, Mail and DNS Services
Dedicated Servers, Rootservers, Application Hosting - Hamburg & Amsterdam

To: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 10:43 am

Pardon the ignorant question.
By what method is shutdown then forced to wait until said processes have
cleaned up? Is a response expected by shutdown from the daemon as a
result to sending SIGTERM?

Regards,
-Lars

To: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 11:03 am

None. rc.shutdown is for those processes with slow/important shutdown
that needs waiting for.

---
Lars Hansson

To: Misc OpenBSD <misc@...>
Cc: Lars Hansson <romabysen@...>
Date: Wednesday, September 19, 2007 - 11:37 am

Ok. So then rc.shutdown should be sure to poll the processes until they
are dead.

To: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 8:34 am

$ man rc.shutdown

Up to you. I shut down almost all daemons in it. Again, you can call
your own scripts, e.g:

echo -n ' mailman'
/usr/local/lib/mailman/bin/mailmanctl -q stop
sleep 30

echo -n ' mailgraph'
/usr/local/site/sbin/mailgraphctl stop > /dev/null

echo -n ' squid'
/usr/local/sbin/squid -k shutdown

echo -n ' dovecot'
pkill dovecot

echo -n ' apache'
apachectl stop

echo -n ' postfix'
/usr/local/site/sbin/postfixctl stop

echo -n ' viagrad'
su -m _viagrad /usr/local/site/libexec/viagrad/viagrad stop

echo -n ' named'
rndc stop

echo '.'

To: Craig Skinner <craig.skinner@...>
Cc: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 9:58 am

Thanks, I will start using rc.shutdown more often :)

To: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 8:31 am

At least MySQL should have told you how to shutdown when installing it.

rc.shutdown(8)

To: Julian Leyh <julian@...>
Cc: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 9:41 am

Yes, it should have, but it haven't :) So I've got wondering :)

Julian Leyh wrote:

On 14:48 Wed 19 Sep , Tomas wrote:

Hi list,

Watching the thread about startup script I thought of a question about
shutdown script. Is it necessary to shutdown certain services when machine
goes down? Like for example mysql, dovecot, clamav, amavis or openvpn. I've
never saw anybody do that. Lots of people on their manuals, tutorials or
posts writes how to start mysql, but none of then writes a shutdown script.
So maybe it is not so necessary? (But then again, mysql is a database
engine, and databases should be handle with care).

At least MySQL should have told you how to shutdown when installing it.

rc.shutdown(8)

To: Tomas <s.tomas@...>
Cc: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 8:17 am

Very few, I'd wager. The only ones I bother with doing it for are
postgresql and mysql since it can take them a while to shut down
correctly and it can get messy if they're not.

---
Lars Hansson

To: Lars Hansson <romabysen@...>
Cc: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 9:25 am

And can I ask how do you do it? Because I don't want to write my mysql
password in rc.shutdown script.

Lars Hansson wrote:

On 9/19/07, Tomas <s.tomas@gmail.com> wrote:

Is it necessary to shutdown certain services when
machine goes down?

Very few, I'd wager. The only ones I bother with doing it for are
postgresql and mysql since it can take them a while to shut down
correctly and it can get messy if they're not.

---
Lars Hansson

To: Tomas <s.tomas@...>
Cc: <misc@...>
Date: Wednesday, September 19, 2007 - 10:10 am

Try: /usr/local/share/mysql/mysql.server stop

To: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 9:51 am

Write a script /root/sbin/mysql-shutdown.sh with whatever you need in
it, & call that script from /etc/rc.shutdown

Only root can read it.

Or:

/usr/local/site/sbin/mysql-shutdown.sh

chmod it 0770, and chown it root:dba so that anyone in the dba group can
edit (passwd changes) and run the script.

To: <misc@...>
Date: Wednesday, September 19, 2007 - 8:24 am

Hi,
yes, You are right - proper shutdown is important. This functionality
realizes script /etc/rc.shutdown fired during shutdown. I that place should
be commands for all services which require shutdown command.
I hope it is what You looking for ;) (sorry if it is to obvious true for
You).

Best regards,
Artur

To: Artur Litwinowicz <bsd_news@...>
Cc: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 9:39 am

Yes it's obvious :) But I've got a little bit confused because I've seen
very few using it. But that's already my problem, isn't it? :) Thanks :)

Artur Litwinowicz wrote:

Hi,
yes, You are right - proper shutdown is important. This functionality
realizes script /etc/rc.shutdown fired during shutdown. I that place should
be commands for all services which require shutdown command.
I hope it is what You looking for ;) (sorry if it is to obvious true for
You).

Best regards,
Artur

On Wed, 19 Sep 2007 14:48:54 +0300, Tomas <s.tomas@gmail.com> wrote:

Hi list,

Watching the thread about startup script I thought of a question about
shutdown script. Is it necessary to shutdown certain services when
machine goes down? Like for example mysql, dovecot, clamav, amavis or
openvpn. I've never saw anybody do that. Lots of people on their
manuals, tutorials or posts writes how to start mysql, but none of then
writes a shutdown script. So maybe it is not so necessary? (But then
again, mysql is a database engine, and databases should be handle with
care).

To: Tomas <s.tomas@...>
Cc: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 8:21 am

For most things, there's no need to worry at all.

From http://dev.mysql.com/doc/refman/5.0/en/server-shutdown.html,
mysql does a controlled shutdown when it receives SIGTERM.

Examining the code of halt(8) (in src/sbin/reboot), at normal shutdown
SIGTERM is sent to running processes, then a delay of 2 seconds before
a sync(2), then a delay of 3 seconds followed by SIGKILL to anything
still running.

So the question is, whether mysql has enough time to shut down
before it's killed. If you think it doesn't, you might like to add
something like 'pkill mysqld; sleep 10' to rc.shutdown. (No need
for some 'mysqladmin shutdown' which would mean listing a plain-
text password in the file).

To: Tomas <s.tomas@...>, OpenBSD misc list <misc@...>
Date: Thursday, September 20, 2007 - 9:59 pm

Thank you so much Stuart for your reply :-)

I have a similar doubt.
What happens when I have a lot of windows open in my fvwm2 and I click
on my desktop and click "Exit Fvwm2" ?

Will all the X11 applications be shutdown decently?
Or is it better to type "halt" in an xterm?
What is the right way to shutdown a desktop?

Thank you so much once again :-)

Kind regards

Siju

To: Siju George <sgeorge.ml@...>
Cc: Tomas <s.tomas@...>, OpenBSD misc list <misc@...>
Date: Friday, September 21, 2007 - 2:47 am

There are some mechanisms to tell applications to shutdown when you
quit X (either by exiting the window manager, or more brutally with
Ctl+Alt+Backspace). They are a bit complex, and no all applications
handle the events they get. (and not all window managers implement the
same protocol).

For instance in my experience, firefox manages to remove its lock (in
~/.mozilla/firefox/hexstuff/) most of the time when I exit from X
(using Ctl+Alt+Backspace) without quitting it first.

But the safest way is to quit each application 1st, then exit the
window manager. Of course this is mainly important for applications
with pending changes like text editors, e-mail clients, or such.
xclock or xload don't care if they are terminated badly.

To: Stuart Henderson <stu@...>
Cc: openBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 9:28 am

Stuart Henderson wrote:

On 2007/09/19 14:48, Tomas wrote:

Watching the thread about startup script I thought of a question about
shutdown script. Is it necessary to shutdown certain services when machine
goes down? Like for example mysql, dovecot, clamav, amavis or openvpn. I've
never saw anybody do that.

For most things, there's no need to worry at all.

>From http://dev.mysql.com/doc/refman/5.0/en/server-shutdown.html ,
mysql does a controlled shutdown when it receives SIGTERM.

Examining the code of halt(8) (in src/sbin/reboot), at normal shutdown
SIGTERM is sent to running processes, then a delay of 2 seconds before
a sync(2), then a delay of 3 seconds followed by SIGKILL to anything
still running.

So the question is, whether mysql has enough time to shut down
before it's killed. If you think it doesn't, you might like to add
something like 'pkill mysqld; sleep 10' to rc.shutdown. (No need
for some 'mysqladmin shutdown' which would mean listing a plain-
text password in the file).

That's an excelent idea. I will use 'pkill mysqld'. But instead of 'sleep 10' myabe it's better to check every second if mysqld.sock exists?

To: Tomas <s.tomas@...>
Cc: openBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 10:43 am

I would choose to limit the maximum time, in case mysqld deadlocks.

I think "pgrep mysqld" is a safer test than mysqld.sock (unless
you've read mysql code and determined that the control socket is
only removed after the tables have been flushed).

To: 'Tomas' <s.tomas@...>, 'Stuart Henderson' <stu@...>
Cc: 'openBSD misc list' <misc@...>
Date: Wednesday, September 19, 2007 - 11:52 am

Something you should be aware of:
If there is insufficient space, MySQL will wait patiently for the
space to become available at which point it picks up like there
never was a problem.
Current behavior may be different. YMMV etc.
Surprising, but it can allow manipulation in low-disk situations.
I've no idea what happens to pending transactions (non-MyISAM databases)

To: Tomas <s.tomas@...>
Cc: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 8:16 am

I myself can't say if it's necessary, but it is probably good practice.

I do notice that OpenBSD does not use anything similar to System V
runlevels (which may or may not be good to avoid) but does provide
/etc/rc.shutdown:

Checking on my systems, I see that none of the packages that run daemons
use it, even the ones installed from the official packages and ports.
In fact, rc.shutdown appears completely empty. Perhaps you have found
an error / oversight?

Regards,
-Lars

To: Lars Noodén <larsnooden@...>
Cc: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 9:23 am

That's a good practice. There's no doubt about it. But like I said I've
seen very few people using it, in fact I saw it only once, shuting down
amavisd-new. But I don't think that's an error or oversight, that's our
ignorance :) And don't want to be ignorant :) So I've asked the question :)

To: <misc@...>
Date: Wednesday, September 19, 2007 - 8:36 am

postgresql-server uses it..

--
Przemyslaw Nowaczyk <p_nowaczyk@o2.pl>
CS student @ Poznan University of Technology
http://www.student.put.poznan.pl/~przemyslaw.nowaczyk/

To: Tomas <s.tomas@...>
Cc: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 8:03 am

Hi!

Probably most programs that need non-trivial cleanup handle SIGTERM
appropriately.

Kind regards,

Hannah.

To: Hannah Schroeter <hannah@...>
Cc: OpenBSD misc list <misc@...>
Date: Wednesday, September 19, 2007 - 9:15 am

Probably most of the programs does handle SIGTERM appropriately, but it
may be too little time for a program to clean itself before it receives
SIGKILL signal. For an example mysql. It needs to kill any connections to
it (and if any problem killing it, it should wait for some time and then
try again), sync data, remove socket (I don't know the exact order of
mysql shutdown task and I'm only guessing). And what if SIGKILL arrives
in the middle of the mysql shutdown tasks?

Hannah Schroeter wrote:

Hi!

On Wed, Sep 19, 2007 at 02:48:54PM +0300, Tomas wrote:

Watching the thread about startup script I thought of a question about
shutdown script. Is it necessary to shutdown certain services when
machine goes down? Like for example mysql, dovecot, clamav, amavis or
openvpn. I've never saw anybody do that. Lots of people on their
manuals, tutorials or posts writes how to start mysql, but none of then
writes a shutdown script. So maybe it is not so necessary? (But then
again, mysql is a database engine, and databases should be handle with
care).

Probably most programs that need non-trivial cleanup handle SIGTERM
appropriately.

Kind regards,

Hannah.

Previous thread: Hardened PhP5 (suhosin patch) and XCache, memcached by Artur Litwinowicz on Wednesday, September 19, 2007 - 6:20 am. (1 message)

Next thread: Slow ral(4) 802.11b in hostap mode? by Damon McMahon on Wednesday, September 19, 2007 - 10:37 am. (5 messages)