Вот пришлось написать Демон который контроллирует другие проги и запускает если их срубило.
А то бывало отвалиться ночью почтарь непонятно покаким причинам...
Мож кому пригодиться :-)
Плюс бэкап CommuniGate сервера пришлось останавливать его чтобы забэкапить!
Код: Выделить всё
#!/usr/bin/perl -w
#use strict;
use IO::File;
use Time::localtime;
use Proc::Daemon;
Proc::Daemon::Init;
$^X='ATRET';
$0='DAEMON';
while(1){
$tm=localtime;
($DAY, $MONTH, $YEAR, $HOUR, $MINUTES, $SECONDS) = ($tm->mday,$tm->mon+1,$tm->year+1900,$tm->hour,$tm->min,$tm->sec);
if($HOUR==0 or $HOUR==1 or $HOUR==3 or $HOUR==4 or $HOUR==5 or $HOUR==6 or $HOUR==7 or $HOUR==8 or $HOUR==9 or $HOUR==10 or $HOUR==11 or $HOUR==12 or $HOUR==13 or $HOUR==14 or $HOUR==15 or $HOUR==16 or $HOUR==17 or $HOUR==18 or $HOUR==19 or $HOUR==20 or $HOUR==21 or $HOUR==22 or $HOUR==23){
# open(PROBA_TIME, ">>/usr/local/scripts/SBORKA_DEMONA/MAIN/proba_time");
# print PROBA_TIME "SEiCHAS $HOUR chasov!!! I $MINUTES minut"."\n";
# close (PROBA_TIME);
$processes=`ps -auxw > /usr/local/scripts/SBORKA_DEMONA/MAIN/top.top`;
open(MYFILE,"/usr/local/scripts/SBORKA_DEMONA/MAIN/top.top") or die "Error!!!:$!";
$id_life=0;
$id_lifw_httpd=0;
$id_life_mysql=0;
$id_life_cg=0;
# $tm=localtime;
# ($DAY, $MONTH, $YEAR, $HOUR, $MINUTES, $SECONDS) = ($tm->mday,$tm->mon+1,$tm->year+1900,$tm->hour,$tm->min,$tm->sec);
# open(PROBA_TIME, ">>/usr/local/scripts/SBORKA_DEMONA/MAIN/proba_time");
# printf PROBA_TIME "$DAY-%02d-$YEAR $HOUR:$MINUTES:%02d"."\n",$MONTH+1,$SECONDS;
# close (PROBA_TIME);
while(<MYFILE>){
# $processes=`ps -auxw > /usr/local/scripts/DAEMON/top.top`;
chomp $_;
# open(VIVOD,">>/usr/local/scripts/SBORKA_DEMONA/MAIN/rabota.tmp") or die "Error!!!:$!";
# @massiv=split(/ /,$_);
# $massiv2=join(" ",$_);
if($_=~m/\/usr\/local\/libexec\/vsftpd/)
{
# open(VIVOD,">>/usr/local/scripts/DAEMON/rabota.tmp") or die "Error!!!:$!";
# print VIVOD "RABOTAET!!!"."\n";
$id_life=1;
# close (VIVOD);
}
# else {
# $id_life=0;
# }
#Apache
if($_=~m/\/usr\/local\/sbin\/httpd/)
{
$id_lifw_httpd=1;
# print VIVOD "rabotaet APACHE"."\n";
}
#MySQL
if($_=~m/\/usr\/local\/libexec\/mysqld/)
{
$id_life_mysql=1;
# print VIVOD "MYSQL!!! RABOTAET!!!"."\n";
}
#CommuniGate
if($_=~m/\/usr\/local\/sbin\/CommuniGate\/CGServer/)
{
$id_life_cg=1;
# print VIVOD "CommuniGate!!! RABOTAET!!!"."\n";
}
# else{
# system("/usr/local/etc/rc.d/mysql-server.sh start");
# print "MYSQL!!! SRUBILO!!! SRUBILO!!! SRUBILO!!!"."\n";
# }
}
# print "$id_life"."\n";
close (MYFILE);
if($id_life==0){
$zapusk=`/usr/local/etc/rc.d/vsftpd.sh start`;
# print VIVOD "SRUBILO"."\n";
}
if($id_lifw_httpd==0){
system("/usr/local/etc/rc.d/apache2.sh start");
}
if($id_life_mysql==0){
system("/usr/local/etc/rc.d/mysql-server.sh start");
}
if($id_life_cg==0){
system("/usr/local/etc/rc.d/CommuniGate.sh start");
}
close (VIVOD);
# print "$massiv2"."\n";
# print "NAchalo\n";
# print "$massiv[2]"."\n";
# print "@massiv2"."\n";
# <>
}
if($HOUR==2 and $MINUTES==30){
system("/usr/local/etc/rc.d/apache.sh stop");
system("/usr/local/etc/rc.d/mysql-server.sh stop");
system("/usr/local/etc/rc.d/CommuniGate.sh stop");
system("tar cf - /usr/local/www/data-dist/ | gzip -9c > /remote/backup_apache.tar.gz");
system("tar cf - /var/db/mysql/ | gzip -9c > /remote/backup_mysql.tar.gz");
system("tar cf - /var/CommuniGate/ | gzip -9c > /remote/backup_CG.tar.gz");
open(PROBA_TIME, ">>/usr/local/scripts/SBORKA_DEMONA/MAIN/proba_time");
print PROBA_TIME "BACKUP POSHEL!!!"."\n";
close (PROBA_TIME);
system("/usr/local/etc/rc.d/apache.sh start");
system("/usr/local/etc/rc.d/mysql-server.sh start");
system("/usr/local/etc/rc.d/CommuniGate.sh start");
}
sleep (10);
}
#<>
Если что непонятно спрашивайте!
Много демонов написал :-)