#!/usr/bin/perl -w ####################################################################### ### $Id: pwatch_pl.txt,v 1.1 2003/08/23 08:55:08 mate Exp $ ### use strict; use Proc::ProcessTable; alarm(30); # 正常な場合のメッセージ表示 my $VERBOSE = 0; # 停止している場合に実行するコマンド my %CMD = ( postfix => [ "/usr/local/etc/rc.d/postfix.sh start", ], postgres => [ "/usr/local/etc/rc.d/postgres.sh start", ], web => [ "/usr/local/etc/rc.d/apache.sh start", ], ); my (%proc); my $p = new Proc::ProcessTable; $proc{getpwuid($_->uid)} = $_->cmndline for @{$p->table}; foreach (sort keys %CMD) { if (exists $proc{$_}) { print "$_ is running: $proc{$_}\n" if $VERBOSE; next; } foreach (@{$CMD{$_}}) { print "$_\n"; (system($_) == 0) or warn("WARNING: system($_) at $?\n"), last; } } exit; __END__ ### Local Variables: ### mode: perl ### End: =head1 NAME pwatch.pl - プロセス監視スクリプト =head1 SYNOPSIS ./pwatch.pl 停止しているプロセスをチェックして設定したコマンドを実行します。 =head1 DESCRIPTION 例) cron で実行する場合 0 * * * * /path/to/pwatch.pl 2>&1| /usr/bin/mail -E -s 'Auto Restart domain.net' root =head1 AUTHOR Yutaka Kojima Eyutaka@asmate.netE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO =cut