Gentoo Archives: gentoo-user

From: Harry Putnam <reader@×××××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] [OT] attach a perl script to daemon services
Date: Fri, 26 Feb 2010 18:41:18
1 ALERT [ This is a slightly rewritten repost from
2 `gmane.[...].perl.beginners', where it got no responses]
3 ------- --------- ---=--- --------- --------
5 My subject line is probably not really that
6 good at describing what I want advice on but here it is:
8 I've setup one linux (gentoo) box as a logserver running rsyslog and
9 several other linux boxes sending syslog info to it.
11 I want to set the server rsyslog.conf so that in addition to normal
12 logging to /var/log/whateverlogs it also writes everything to a named
13 pipe (fifo).
15 Then tap into the fifo with a perl script that is written to be able
16 to sort and write the syslog output according to various regex that
17 may be part of startup cmd or fed in later during the running script.
19 I think I can manage the sorting/writing and maybe reading regex into
20 the running process. (Just by an awkward funky method of having the
21 script reread a file on disk every 5 minutes, and put what ever regex
22 become necessary there).
24 There are probably cleaner better ways... and I may be back asking
25 about that but right now, where I have no real idea is how to attach
26 the perl script to a service like the system logger.
28 I mean so the script starts and stops with system logger and somehow
29 alerts the system logger (and sysadmin) if it (the script) for some
30 reason is killed or dies on its own while the system logger is still
31 running.
33 I imagine getting the perl script to start/stop with the logger daemon
34 on boot up would be simple enough by inserting something into the init
35 script that starts the logger.
37 From there I'm just drawing blanks as to how a script would know if
38 the system logger stopped, and further some kind of `trap' that would
39 send out info to be logged by the logger and to the system admin if
40 the script itself died or was killed.
42 I'm slightly familiar with shell script traps but haven't encountered
43 or had need of such in a perl script.
45 But really I suspect I'm going at this wrong right from the start and
46 there is a better plan to be had.
48 I'm hoping someone with that kind of experience can outline how this
49 might be done. I can handle most of the perl scripting but not sure
50 about coding a `trap' style function.. That I can get from the
51 perl.beginners group. so here I'm looking for an overview of how to go
52 at this.
54 I'm thinking an experienced sysadmin here will have at the top of
55 there head.. the basic outline of how something like this might be
56 done.
58 So to summarize I want to:
59 Attach a perl script to a service daemon (rsyslog) so it
60 starts/stops with the daemon, and has some code that will put
61 something into syslog output and notify the admin in the event the
62 script itself is terminated unexpectedly. Something along the line
63 of a bash/ksh exit `trap'
65 It would also need to check when being started, that the system
66 logger is running else fail and send notice to admin.


Subject Author
Re: [gentoo-user] [OT] attach a perl script to daemon services Alan McKinnon <alan.mckinnon@×××××.com>