-
Notifications
You must be signed in to change notification settings - Fork 15
/
watcher.pl
executable file
·48 lines (40 loc) · 922 Bytes
/
watcher.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 30;
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 30;
}
=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