Skip to content

Commit

Permalink
add auto rebooter.
Browse files Browse the repository at this point in the history
  • Loading branch information
uzulla committed May 27, 2013
1 parent 6f388ec commit 276c247
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ pm_to_blib
config.pl
config.pl.bak
MYMETA.*
start.sh.log
yancha.pid
access_log
.htpasswd
3 changes: 3 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#!/bin/sh
twiggy -l :3000 chat.psgi
#export YANCHA_DEBUG=1
#twiggy -l :3000 --access-log access_log chat.psgi &
echo $! > yancha.pid
2 changes: 2 additions & 0 deletions stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
kill `cat yancha.pid`
48 changes: 48 additions & 0 deletions watcher.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env perl
use strict;
use utf8;
use warnings;
use Time::Piece;
use LWP::UserAgent;

my $YANCHA_URL = 'http://localhost:3000/';

my $ua = LWP::UserAgent->new;
$ua->timeout(10);
print localtime->datetime;
print " watch start\n";

while(1){
my $response = eval {
local $SIG{ALRM} = sub { die HTTP::Response->new(408, "got alarm, read timeout.") };
alarm 10;
my $res = $ua->get($YANCHA_URL);
alarm 0;
$res;
};

if ($response->is_success) {
# print "OK\n";
}else{
print localtime->datetime;
print " NG! \n";
`kill \`cat yancha.pid\``;
# must restart
`nohup ./start.sh >> start.sh.log 2>&1 &`;
}
sleep 10;
}

=pod
Yancha Auto Rebooter
Author: uzulla
HOW TO START
0. edit watcher.pl ($YANCHA_URL)
1. run watcher.pl (You can use this an alternate for start.sh.)
HOW TO STOP
1, kill watchr.pl
2, stop.sh
=cut

0 comments on commit 276c247

Please sign in to comment.