Gentoo Archives: gentoo-user

From: Michael Higgins <linux@×××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Re: [OT] attach a perl script to daemon services
Date: Sat, 27 Feb 2010 20:58:13
Message-Id: 20100227125741.06b6b132@lappy.evolone.org
In Reply to: [gentoo-user] Re: [OT] attach a perl script to daemon services by Harry Putnam
1 On Sat, 27 Feb 2010 12:40:17 -0600
2 Harry Putnam <reader@×××××××.com> wrote:
3
4 > > reload() {
5 > > ebegin "Reloading evolone_agi configuration"
6 > > start-stop-daemon --signal 1
7 > > --pidfile /var/run/evolone_agi.pid eend $? "Error reloading
8 > > evolone_agi" }
9
10 > Thanks ... good info. How does the script behave regarding what
11 > happens if it receives a sigINT or sigKILL, or some other way dies
12 > (even from an internal error)?
13
14 This script is more proof-of-concept piece hacked together in an hour
15 which just routes my outgoing calls to local free PSTN or SIP. So I know
16 if it needs restarting when I can't make a call from home. ;-)
17
18 Basically, I think if you perldoc Net::Server[::SIG]
19
20 In there is:
21
22 $self->pre_server_close_hook;
23
24 ... might be your friend to share some Sys::Syslog routines.
25
26 In the Net::Server code:
27 ### set some sigs
28 $SIG{INT} = $SIG{TERM} = $SIG{QUIT} = sub { $self->server_close; };
29
30 ### most cases, a closed pipe will take care of itself
31 $SIG{PIPE} = 'IGNORE';
32
33 ### catch children (mainly for Fork and PreFork but works for any
34 chld) $SIG{CHLD} = \&sig_chld;
35
36 ### catch sighup
37 $SIG{HUP} = sub { $self->sig_hup; }
38
39
40 ... seems to have it covered for most cases. ;-) You can see sig_hup is
41 almost expected to do something.
42
43 >
44 > Does it log to syslog? and notify sysadmin?
45
46 I think a good use of Net::Server::* and Sys::Syslog can get you where
47 you want. I'd bet you can put anything in that pre_server_close_hook
48 hook... send an email, set off the building alarms... it's perl, after
49 all. But I really haven't done much directly with it.
50
51 >
52 > I haven't had occasion to run into an `EXIT trap' in perl... but there
53 > must be such a thing.
54 >
55
56 perldoc -q signal
57 perldoc perlipc
58
59 HTH.
60
61 --
62 |\ /| | | ~ ~
63 | \/ | |---| `|` ?
64 | |ichael | |iggins \^ /
65 michael.higgins[at]evolone[dot]org