* [gentoo-user] [OT] attach a perl script to daemon services
@ 2010-02-26 18:40 Harry Putnam
2010-02-26 20:22 ` Alan McKinnon
0 siblings, 1 reply; 12+ messages in thread
From: Harry Putnam @ 2010-02-26 18:40 UTC (permalink / raw
To: gentoo-user
ALERT [ This is a slightly rewritten repost from
`gmane.[...].perl.beginners', where it got no responses]
------- --------- ---=--- --------- --------
My subject line is probably not really that
good at describing what I want advice on but here it is:
I've setup one linux (gentoo) box as a logserver running rsyslog and
several other linux boxes sending syslog info to it.
I want to set the server rsyslog.conf so that in addition to normal
logging to /var/log/whateverlogs it also writes everything to a named
pipe (fifo).
Then tap into the fifo with a perl script that is written to be able
to sort and write the syslog output according to various regex that
may be part of startup cmd or fed in later during the running script.
I think I can manage the sorting/writing and maybe reading regex into
the running process. (Just by an awkward funky method of having the
script reread a file on disk every 5 minutes, and put what ever regex
become necessary there).
There are probably cleaner better ways... and I may be back asking
about that but right now, where I have no real idea is how to attach
the perl script to a service like the system logger.
I mean so the script starts and stops with system logger and somehow
alerts the system logger (and sysadmin) if it (the script) for some
reason is killed or dies on its own while the system logger is still
running.
I imagine getting the perl script to start/stop with the logger daemon
on boot up would be simple enough by inserting something into the init
script that starts the logger.
From there I'm just drawing blanks as to how a script would know if
the system logger stopped, and further some kind of `trap' that would
send out info to be logged by the logger and to the system admin if
the script itself died or was killed.
I'm slightly familiar with shell script traps but haven't encountered
or had need of such in a perl script.
But really I suspect I'm going at this wrong right from the start and
there is a better plan to be had.
I'm hoping someone with that kind of experience can outline how this
might be done. I can handle most of the perl scripting but not sure
about coding a `trap' style function.. That I can get from the
perl.beginners group. so here I'm looking for an overview of how to go
at this.
I'm thinking an experienced sysadmin here will have at the top of
there head.. the basic outline of how something like this might be
done.
So to summarize I want to:
Attach a perl script to a service daemon (rsyslog) so it
starts/stops with the daemon, and has some code that will put
something into syslog output and notify the admin in the event the
script itself is terminated unexpectedly. Something along the line
of a bash/ksh exit `trap'
It would also need to check when being started, that the system
logger is running else fail and send notice to admin.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] [OT] attach a perl script to daemon services
2010-02-26 18:40 [gentoo-user] [OT] attach a perl script to daemon services Harry Putnam
@ 2010-02-26 20:22 ` Alan McKinnon
2010-02-26 21:44 ` [gentoo-user] " Harry Putnam
0 siblings, 1 reply; 12+ messages in thread
From: Alan McKinnon @ 2010-02-26 20:22 UTC (permalink / raw
To: gentoo-user
On Friday 26 February 2010 20:40:40 Harry Putnam wrote:
> ALERT [ This is a slightly rewritten repost from
> `gmane.[...].perl.beginners', where it got no responses]
> ------- --------- ---=--- --------- --------
>
> My subject line is probably not really that
> good at describing what I want advice on but here it is:
>
> I've setup one linux (gentoo) box as a logserver running rsyslog and
> several other linux boxes sending syslog info to it.
>
> I want to set the server rsyslog.conf so that in addition to normal
> logging to /var/log/whateverlogs it also writes everything to a named
> pipe (fifo).
>
> Then tap into the fifo with a perl script that is written to be able
> to sort and write the syslog output according to various regex that
> may be part of startup cmd or fed in later during the running script.
I don't know rsyslog at all (I use syslog-ng), but certain concepts are stable
and universal.
Any log daemon must receive logs from somewhere and send them somewhere, and
almost all support the notion of sending logs to a process instead of a file-
like destination.
Does rsyslog not support something like this:
destination "| /path/to/script.pl"
--
alan dot mckinnon at gmail dot com
^ permalink raw reply [flat|nested] 12+ messages in thread
* [gentoo-user] Re: [OT] attach a perl script to daemon services
2010-02-26 20:22 ` Alan McKinnon
@ 2010-02-26 21:44 ` Harry Putnam
2010-02-26 23:00 ` Alan McKinnon
0 siblings, 1 reply; 12+ messages in thread
From: Harry Putnam @ 2010-02-26 21:44 UTC (permalink / raw
To: gentoo-user
Alan McKinnon <alan.mckinnon@gmail.com> writes:
>> Then tap into the fifo with a perl script that is written to be able
>> to sort and write the syslog output according to various regex that
>> may be part of startup cmd or fed in later during the running script.
>
> I don't know rsyslog at all (I use syslog-ng), but certain concepts
> are stable and universal.
Please reread my OP or maybe I should attempt to clarify what must be
a poorly written question.
I'm not asking help on anything about writing to a named pipe or
anything about the functioning of rsyslog... I know that part.
Not asking about the bulk of the perl scripting, such as sorting by
regex, reading from fifo, etc (are all understood [at least well enough]).
I want an overview/outline of how one goes about attaching a script to
the operations such as start/stop of a daemon
Even there... the additions necessary to the scripts in
/etc/init.d... are understood.
I guess I want to know if its even advisable to attach custom
scripting to a daemon or if there is a well worn path for doing that.
Assuming its not clear off the wall then:
Where I'm weak is the part where the custom script checks if the
daemon is running, before the script itself starts. That part would
need to be something pretty fool proof... maybe just grep ps output
for the daemon?
And where the custom script sends syslog (and sysadmin) a message in
the event the script itself is killed or dies for some unexpected
reason. Something like an EXIT `trap' in shell scripting... (how its
done is perl)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Re: [OT] attach a perl script to daemon services
2010-02-26 21:44 ` [gentoo-user] " Harry Putnam
@ 2010-02-26 23:00 ` Alan McKinnon
2010-02-26 23:34 ` Michael Higgins
2010-02-27 18:40 ` Harry Putnam
0 siblings, 2 replies; 12+ messages in thread
From: Alan McKinnon @ 2010-02-26 23:00 UTC (permalink / raw
To: gentoo-user
On Friday 26 February 2010 23:44:03 Harry Putnam wrote:
> Where I'm weak is the part where the custom script checks if the
> daemon is running, before the script itself starts. That part would
> need to be something pretty fool proof... maybe just grep ps output
> for the daemon?
Maybe I'm misunderstanding you, but I don't understand this approach.
If the daemon is not running there's nothing in the fifo. Why got to all the
complexity of writing an independent program that checks if something is
running then does various actions? The script necessarily depends on the
daemon running so instead of checking if it is, simply have the daemon start
the script. No daemon running = no script launched = no complexity.
The script will simply accept what is it is given, no complex checks needed.
Seeing as the input is from a logger, chances are you are inserting logs to a
db, or launching a log analyser, right? Modern loggers support launching child
scripts as a matter of routine.
If I'm still off-bat and this approach cannot work for solid technical
reasons, then I'll go away and shut if if you say so :-)
--
alan dot mckinnon at gmail dot com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Re: [OT] attach a perl script to daemon services
2010-02-26 23:00 ` Alan McKinnon
@ 2010-02-26 23:34 ` Michael Higgins
2010-02-27 18:40 ` Harry Putnam
1 sibling, 0 replies; 12+ messages in thread
From: Michael Higgins @ 2010-02-26 23:34 UTC (permalink / raw
To: gentoo-user
On Sat, 27 Feb 2010 01:00:43 +0200
Alan McKinnon <alan.mckinnon@gmail.com> wrote:
> > Where I'm weak is the part where the custom script checks if the
> > daemon is running, before the script itself starts. That part would
> > need to be something pretty fool proof... maybe just grep ps output
> > for the daemon?
I have a perl fastAGI script that launches in /etc/init.d/.... I just
cribbed some code from something there...
in my perl script:
log_file=>'Sys::Syslog', pid_file=>'/var/run/evolone_agi.pid';
Sys::Syslog" is an interface to the UNIX syslog(3) program.
from /etc/init.d/evolone_agi
depend() {
need net asterisk postgresql-8.4
}
As for reading new information, there are a gazillion ways. Trap a
signal to reread the configs?
reload() {
ebegin "Reloading evolone_agi configuration"
start-stop-daemon --signal 1 --pidfile /var/run/evolone_agi.pid
eend $? "Error reloading evolone_agi"
}
.. for example.
Hope this helps. '-)
--
|\ /| | | ~ ~
| \/ | |---| `|` ?
| |ichael | |iggins \^ /
michael.higgins[at]evolone[dot]org
^ permalink raw reply [flat|nested] 12+ messages in thread
* [gentoo-user] Re: [OT] attach a perl script to daemon services
2010-02-26 23:00 ` Alan McKinnon
2010-02-26 23:34 ` Michael Higgins
@ 2010-02-27 18:40 ` Harry Putnam
2010-02-27 20:57 ` Michael Higgins
2010-02-28 21:50 ` Alan McKinnon
1 sibling, 2 replies; 12+ messages in thread
From: Harry Putnam @ 2010-02-27 18:40 UTC (permalink / raw
To: gentoo-user
Alan McKinnon <alan.mckinnon@gmail.com> writes:
> On Friday 26 February 2010 23:44:03 Harry Putnam wrote:
>> Where I'm weak is the part where the custom script checks if the
>> daemon is running, before the script itself starts. That part would
>> need to be something pretty fool proof... maybe just grep ps output
>> for the daemon?
>
> Maybe I'm misunderstanding you, but I don't understand this approach.
>
> If the daemon is not running there's nothing in the fifo. Why got to all the
> complexity of writing an independent program that checks if something is
> running then does various actions? The script necessarily depends on the
> daemon running so instead of checking if it is, simply have the daemon start
> the script. No daemon running = no script launched = no complexity.
In the back of my mind there was a reason on opensolaris, that the
script would fail if the fifo was empty... Then once data comes the
script isn't listening. Or syslog won't write or something similar.
I also have an opensolaris box that will be using this same script.
I don't want to back up and relocate all that right now... Not sure I
have it remembered right either, it seems just easier to have the
script check before trying to start (for portability).
Solaris syslog can write to named pipes but no so readily as linux
syslog. Not sure of the details now.
> If I'm still off-bat and this approach cannot work for solid technical
> reasons, then I'll go away and shut if if you say so :-)
No, not off-base... thanks. The checking isn't so hard to figure
anyway, but you didn't talk about the script having some kind of trap
or something to cover unexpected kill or failure.
Michael has covered that somewhat.
Also I didn't think to search cpan for something that does what I
want. That may turn up something I can just plug into.
Michael Higgins <linux@evolone.org> writes:
[...]
> in my perl script:
>
> log_file=>'Sys::Syslog', pid_file=>'/var/run/evolone_agi.pid';
>
> Sys::Syslog" is an interface to the UNIX syslog(3) program.
>
> from /etc/init.d/evolone_agi
>
> depend() {
> need net asterisk postgresql-8.4
> }
>
> As for reading new information, there are a gazillion ways. Trap a
> signal to reread the configs?
>
> reload() {
> ebegin "Reloading evolone_agi configuration"
> start-stop-daemon --signal 1 --pidfile /var/run/evolone_agi.pid
> eend $? "Error reloading evolone_agi"
> }
Thanks ... good info. How does the script behave regarding what
happens if it receives a sigINT or sigKILL, or some other way dies
(even from an internal error)?
Does it log to syslog? and notify sysadmin?
I haven't had occasion to run into an `EXIT trap' in perl... but there
must be such a thing.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Re: [OT] attach a perl script to daemon services
2010-02-27 18:40 ` Harry Putnam
@ 2010-02-27 20:57 ` Michael Higgins
2010-02-28 21:50 ` Alan McKinnon
1 sibling, 0 replies; 12+ messages in thread
From: Michael Higgins @ 2010-02-27 20:57 UTC (permalink / raw
To: gentoo-user
On Sat, 27 Feb 2010 12:40:17 -0600
Harry Putnam <reader@newsguy.com> wrote:
> > reload() {
> > ebegin "Reloading evolone_agi configuration"
> > start-stop-daemon --signal 1
> > --pidfile /var/run/evolone_agi.pid eend $? "Error reloading
> > evolone_agi" }
> Thanks ... good info. How does the script behave regarding what
> happens if it receives a sigINT or sigKILL, or some other way dies
> (even from an internal error)?
This script is more proof-of-concept piece hacked together in an hour
which just routes my outgoing calls to local free PSTN or SIP. So I know
if it needs restarting when I can't make a call from home. ;-)
Basically, I think if you perldoc Net::Server[::SIG]
In there is:
$self->pre_server_close_hook;
... might be your friend to share some Sys::Syslog routines.
In the Net::Server code:
### set some sigs
$SIG{INT} = $SIG{TERM} = $SIG{QUIT} = sub { $self->server_close; };
### most cases, a closed pipe will take care of itself
$SIG{PIPE} = 'IGNORE';
### catch children (mainly for Fork and PreFork but works for any
chld) $SIG{CHLD} = \&sig_chld;
### catch sighup
$SIG{HUP} = sub { $self->sig_hup; }
... seems to have it covered for most cases. ;-) You can see sig_hup is
almost expected to do something.
>
> Does it log to syslog? and notify sysadmin?
I think a good use of Net::Server::* and Sys::Syslog can get you where
you want. I'd bet you can put anything in that pre_server_close_hook
hook... send an email, set off the building alarms... it's perl, after
all. But I really haven't done much directly with it.
>
> I haven't had occasion to run into an `EXIT trap' in perl... but there
> must be such a thing.
>
perldoc -q signal
perldoc perlipc
HTH.
--
|\ /| | | ~ ~
| \/ | |---| `|` ?
| |ichael | |iggins \^ /
michael.higgins[at]evolone[dot]org
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Re: [OT] attach a perl script to daemon services
2010-02-27 18:40 ` Harry Putnam
2010-02-27 20:57 ` Michael Higgins
@ 2010-02-28 21:50 ` Alan McKinnon
2010-03-01 4:16 ` Harry Putnam
1 sibling, 1 reply; 12+ messages in thread
From: Alan McKinnon @ 2010-02-28 21:50 UTC (permalink / raw
To: gentoo-user
On Saturday 27 February 2010 20:40:17 Harry Putnam wrote:
> In the back of my mind there was a reason on opensolaris, that the
> script would fail if the fifo was empty... Then once data comes the
> script isn't listening. Or syslog won't write or something similar.
>
> I also have an opensolaris box that will be using this same script.
>
> I don't want to back up and relocate all that right now... Not sure I
> have it remembered right either, it seems just easier to have the
> script check before trying to start (for portability).
>
> Solaris syslog can write to named pipes but no so readily as linux
> syslog. Not sure of the details now.
The rest of your post seems adequately answered elsewhere.
FWIW, Solaris syslogd is like other basic tools on Solaris: standards
compliant in that it caters for the lowest common denominator that comprises
Unix. Which is to say, almost always useless for real work.
I tossed syslogd on Solaris long long ago and migrated everything to syslog-
ng. The nice thing about syslog-ng is that it actually *works*, and does so
predictably.
--
alan dot mckinnon at gmail dot com
^ permalink raw reply [flat|nested] 12+ messages in thread
* [gentoo-user] Re: [OT] attach a perl script to daemon services
2010-02-28 21:50 ` Alan McKinnon
@ 2010-03-01 4:16 ` Harry Putnam
2010-03-01 9:02 ` Alan McKinnon
0 siblings, 1 reply; 12+ messages in thread
From: Harry Putnam @ 2010-03-01 4:16 UTC (permalink / raw
To: gentoo-user
Alan McKinnon <alan.mckinnon@gmail.com> writes:
> FWIW, Solaris syslogd is like other basic tools on Solaris: standards
> compliant in that it caters for the lowest common denominator that comprises
> Unix. Which is to say, almost always useless for real work.
A little turn towards OT:
so what are using your opensolaris machines for?
The advantages of zfs?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Re: [OT] attach a perl script to daemon services
2010-03-01 4:16 ` Harry Putnam
@ 2010-03-01 9:02 ` Alan McKinnon
2010-03-02 22:26 ` Harry Putnam
0 siblings, 1 reply; 12+ messages in thread
From: Alan McKinnon @ 2010-03-01 9:02 UTC (permalink / raw
To: gentoo-user
On Monday 01 March 2010 06:16:09 Harry Putnam wrote:
> Alan McKinnon <alan.mckinnon@gmail.com> writes:
> > FWIW, Solaris syslogd is like other basic tools on Solaris: standards
> > compliant in that it caters for the lowest common denominator that
> > comprises Unix. Which is to say, almost always useless for real work.
>
> A little turn towards OT:
> so what are using your opensolaris machines for?
> The advantages of zfs?
I had Solaris, not OpenSolaris. I've been steadily reducing my Solaris
machines (mostly because of the horrendous cost) and not many are left. Other
teams here still have quite a few, mostly for proprietary ISP monitoring
stuff, Oracle, VoIP billing systems - that kind of thing.
--
alan dot mckinnon at gmail dot com
^ permalink raw reply [flat|nested] 12+ messages in thread
* [gentoo-user] Re: [OT] attach a perl script to daemon services
2010-03-01 9:02 ` Alan McKinnon
@ 2010-03-02 22:26 ` Harry Putnam
2010-03-02 23:03 ` Alan McKinnon
0 siblings, 1 reply; 12+ messages in thread
From: Harry Putnam @ 2010-03-02 22:26 UTC (permalink / raw
To: gentoo-user
Alan McKinnon <alan.mckinnon@gmail.com> writes:
> On Monday 01 March 2010 06:16:09 Harry Putnam wrote:
>> Alan McKinnon <alan.mckinnon@gmail.com> writes:
>> > FWIW, Solaris syslogd is like other basic tools on Solaris:
>> > standards compliant in that it caters for the lowest common
>> > denominator that comprises Unix. Which is to say, almost always
>> > useless for real work.
>>
>> A little turn towards OT:
>> so what are using your opensolaris machines for?
>> The advantages of zfs?
>
>
> I had Solaris, not OpenSolaris. I've been steadily reducing my
> Solaris machines (mostly because of the horrendous cost) and not
> many are left. Other teams here still have quite a few, mostly for
> proprietary ISP monitoring stuff, Oracle, VoIP billing systems -
> that kind of thing.
No interest in opensolaris then? The `ZFS' file system alone makes it
worth looking at... its a working system very similar to what linux
community is trying with btrfs
I guess you know that Oracle bought Sun. Some on the opensolaris
lists have been pretty concerned about the fate of opensolaris.
In the last few days some Oracle heavies have put it on line that
Oracle plans to put more devel money into Opensolaris than Sun had
been so many in that community are relieved.
If you're interested, look for:
Subject: Oracle Says OpenSolaris Will Stay Open Source
On news.gmane.org under:
gmane.os.solaris.opensolaris.general
The only url have to hand is below but there were several others
cited a fair bit more info in thead as well:
http://www.internetnews.com/dev-news/article.php/3867776/Oracle+Says+OpenSolaris+Will+Stay+Open+Source.htm
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Re: [OT] attach a perl script to daemon services
2010-03-02 22:26 ` Harry Putnam
@ 2010-03-02 23:03 ` Alan McKinnon
0 siblings, 0 replies; 12+ messages in thread
From: Alan McKinnon @ 2010-03-02 23:03 UTC (permalink / raw
To: gentoo-user
On Wednesday 03 March 2010 00:26:35 Harry Putnam wrote:
> Alan McKinnon <alan.mckinnon@gmail.com> writes:
> > On Monday 01 March 2010 06:16:09 Harry Putnam wrote:
> >> Alan McKinnon <alan.mckinnon@gmail.com> writes:
> >> > FWIW, Solaris syslogd is like other basic tools on Solaris:
> >> > standards compliant in that it caters for the lowest common
> >> > denominator that comprises Unix. Which is to say, almost always
> >> > useless for real work.
> >>
> >> A little turn towards OT:
> >> so what are using your opensolaris machines for?
> >> The advantages of zfs?
> >
> > I had Solaris, not OpenSolaris. I've been steadily reducing my
> > Solaris machines (mostly because of the horrendous cost) and not
> > many are left. Other teams here still have quite a few, mostly for
> > proprietary ISP monitoring stuff, Oracle, VoIP billing systems -
> > that kind of thing.
>
> No interest in opensolaris then? The `ZFS' file system alone makes it
> worth looking at... its a working system very similar to what linux
> community is trying with btrfs
Sadly, using opensolaris would require a massive change in how we do things,
and it's just not worth it for us.
ZFS is great, but it's not something we'd use. Rather, it's not something we
have a pressing need for and the problems it solves are not problems we have.
>
> I guess you know that Oracle bought Sun. Some on the opensolaris
> lists have been pretty concerned about the fate of opensolaris.
>
> In the last few days some Oracle heavies have put it on line that
> Oracle plans to put more devel money into Opensolaris than Sun had
> been so many in that community are relieved.
>
> If you're interested, look for:
>
> Subject: Oracle Says OpenSolaris Will Stay Open Source
>
> On news.gmane.org under:
> gmane.os.solaris.opensolaris.general
>
> The only url have to hand is below but there were several others
> cited a fair bit more info in thead as well:
>
>
> http://www.internetnews.com/dev-news/article.php/3867776/Oracle+Says+OpenS
> olaris+Will+Stay+Open+Source.htm
--
alan dot mckinnon at gmail dot com
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2010-03-02 23:06 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-26 18:40 [gentoo-user] [OT] attach a perl script to daemon services Harry Putnam
2010-02-26 20:22 ` Alan McKinnon
2010-02-26 21:44 ` [gentoo-user] " Harry Putnam
2010-02-26 23:00 ` Alan McKinnon
2010-02-26 23:34 ` Michael Higgins
2010-02-27 18:40 ` Harry Putnam
2010-02-27 20:57 ` Michael Higgins
2010-02-28 21:50 ` Alan McKinnon
2010-03-01 4:16 ` Harry Putnam
2010-03-01 9:02 ` Alan McKinnon
2010-03-02 22:26 ` Harry Putnam
2010-03-02 23:03 ` Alan McKinnon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox