Software Freedom Law Center

root/trunk/dev-tools/svn-scripts-run-check.plx

Revision 13, 3.4 kB (checked in by bkuhn, 1 year ago)
  • Date::Manip not actually needed
Line 
1 #!/usr/bin/perl
2 # Copyright (c) 2006, 2007 Software Freedom Law Center, Inc.
3 #
4 # This software gives you freedom; it is licensed to you under version 3
5 # of the GNU General Public License.
6 #
7 # This software is distributed WITHOUT ANY WARRANTY, without even the
8 # implied warranties of MERCHANTABILITY and FITNESS FOR A PARTICULAR
9 # PURPOSE.  See the GNU General Public License for further details.
10 #
11 # You should have received a copy of the GNU General Public License,
12 # version 3.  If not, see <http://www.gnu.org/licenses/>
13 #
14 # License: GPLv3-only
15
16 # This script is designed to be run launched by svn's post hooks under the
17 # uid of the Mercurial repository.  It generally lives in ~svn/bin
18 # and called from the repository post hooks
19
20 # This program might be of interest to people who want to do some sort of
21 # operation on files after an SVN commit that requires some set of
22 # commands to be run on the repository's local system.  In other words, if
23 # you really wish that when an SVN commit happened, you could log into the
24 # server and run a bunch of commands against a local checkout of what was
25 # just committed, then this script is for you.
26
27 # The whole thing is a hack -- no question.  If there's a better way to do
28 # this job, I'd love to hear about it.
29
30 use strict;
31 use warnings;
32
33 use Unix::Syslog qw(:subs);
34 use Unix::Syslog qw(:macros);
35
36 my $PAGE_EMAIL = "root\@softwarefreeom.org";
37
38 {
39   my %messageHistory;
40
41   sub WarnLog ($$) {
42     my($now, $message) = @_;
43
44     syslog LOG_INFO, $message;
45
46     my $lastTime = $messageHistory{$message};
47
48     my $sendIt = 0;
49     if (not defined $lastTime) {
50       $sendIt = 1;
51     } else {
52       my $err;
53       my $sinceLast = DateCalc($lastTime,"+ 10 minutes",\$err);
54       $sendIt = 1 if ($now gt $sinceLast);
55     }
56     if ($sendIt) {
57       open(SENDMAIL, "|/usr/sbin/sendmail -f root\@softwarefreedom.org -t");
58       print SENDMAIL "To: $PAGE_EMAIL\nFrom: root\@softwarefreedom.org\n",
59       "Subject: CAL, COMMIT_HOOK\n\n$message\n.\n";
60       close(SENDMAIL);
61       if ($? != 0) {
62         syslog LOG_INFO, "Unable to perform sendmail: $!";
63       } else {
64         $messageHistory{$message} = $now;
65       }
66     }
67   }
68 }
69 ###############################################################################
70 %ENV = ();
71 $ENV{PATH} = "/bin:/usr/bin";
72 #$ENV{HOME} = "/home/svn";
73 #$ENV{USER} = $ENV{LOGNAME} ='svn';
74 $ENV{SHELL} = "/bin/bash";
75
76 chdir("/home/hg")
77   or WarnLog(ParseDate("today"), "unable to change to /home/hg: $!");
78
79 my %programs = ('loblaw-test' => { pidFile =>
80                                   "/home/hg/pids/loblaw-test-update.pid",
81                      scriptFile => "/home/hg/bin/update-loblaw-test.plx" });
82
83 foreach my $key (keys %programs) {
84   my $pid;
85   if (-f $programs{$key}{pidFile}) {
86     open(PID_FILE, "<$programs{$key}{pidFile}")
87      or WarnLog(ParseDate("today"),
88                 "unable to open $programs{$key}{pidFile}: $!");
89
90     $pid = <PID_FILE>;
91     close PID_FILE;
92     chomp $pid;
93
94     system("/bin/ps h --pid $pid > /dev/null 2>&1");
95   }
96
97   if ( (not defined $pid) or $pid eq "" or $? != 0) {
98     unlink($programs{$key}{pidFile});
99     system("/usr/bin/nohup $programs{$key}{scriptFile} >> /home/hg/logs/${key}.log 2>&1 &");
100     WarnLog(ParseDate("today"), "unable to launch $key bot: $!")
101       unless ($? == 0);
102   }
103 }
104
105 ###############################################################################
106 #
107 # Local variables:
108 # compile-command: "perl -c svn-scripts-run-check.plx"
109 # End:
110 #
Note: See TracBrowser for help on using the browser.

SFLC Main Page

[frdm] Support SFLC