1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | # wait until woken-up by reception of a "Compile MAD for Windows!\n" message |
---|
4 | # on the receiving socket |
---|
5 | |
---|
6 | # this script should be scheduled on each startup of the Windows box, with the |
---|
7 | # Start->All Programs->Accessories->System Tools->Scheduled Tasks. |
---|
8 | # |
---|
9 | # the script is installed under /afs/user/n/nougaret/scractch0/mad-automation |
---|
10 | # together with the other scripts, BUT IF I DO SO IT CAN'T BE VIEWED THROUGH SAMBA |
---|
11 | # HENCE NEED TO FIND SOMETHING ELSE... |
---|
12 | |
---|
13 | #use MIME::Lite; |
---|
14 | use IO::Socket::INET; |
---|
15 | use Cwd; # to get current directory on Windows (would work on Linux as well) |
---|
16 | |
---|
17 | |
---|
18 | # upon start-up, send e-mail |
---|
19 | #my $msg = MIME::Lite->new( |
---|
20 | # From => 'Jean-Luc.Nougaret@cern.ch', |
---|
21 | # To => 'Jean-Luc.Nougaret@cern.ch', |
---|
22 | # Subject => 'MAD windows monitor started' |
---|
23 | # Data => 'now waiting for a trigger signal through dedicated socket port' |
---|
24 | #); |
---|
25 | #$msg->send; |
---|
26 | |
---|
27 | use Sys::Hostname; |
---|
28 | |
---|
29 | |
---|
30 | my $os = 'windows'; |
---|
31 | |
---|
32 | my $socketPortWindows = 7070; # agreed-up with client |
---|
33 | my $socketPortLinux = 7071; # could be the same as above |
---|
34 | |
---|
35 | # my $windowsHost = 'abpc10788'; |
---|
36 | $windowsHost = hostname; |
---|
37 | |
---|
38 | my $sock = new IO::Socket::INET ( |
---|
39 | LocalHost => $windowsHost, |
---|
40 | LocalPort => $socketPortWindows, |
---|
41 | Proto => 'tcp', |
---|
42 | Listen => 1, |
---|
43 | Reuse => 1 |
---|
44 | ); |
---|
45 | |
---|
46 | die "Could not create client socket: $!\n" unless $sock; |
---|
47 | |
---|
48 | |
---|
49 | print "now accepting messages sent through socket $socketPortWindows\n"; |
---|
50 | |
---|
51 | while(1){ |
---|
52 | |
---|
53 | my $receiving = $sock->accept(); |
---|
54 | |
---|
55 | my $clientHost; |
---|
56 | |
---|
57 | while (<$receiving>){ |
---|
58 | print $_; |
---|
59 | if (/([\w\d\-\_]+) asks: Compile MAD for Windows!/){ # message signalling compilation trigger |
---|
60 | |
---|
61 | # following is specific to the DOS system |
---|
62 | if ($os eq 'windows'){ |
---|
63 | my $dir = getcwd; # get current working directory |
---|
64 | print "we are now in $dir\n"; |
---|
65 | chdir("Y:\\MAD-X-WINDOWS\\madX"); # changed Z to Y |
---|
66 | $dir = getcwd; |
---|
67 | print "we are now in $dir\n"; |
---|
68 | # first make sure we are in sync with the CVS repository |
---|
69 | my @needsUpdate = `cvs status | grep Need`; |
---|
70 | print "list of files requiring refreshment from the CVS:\n"; |
---|
71 | foreach $file (@needsUpdate){ |
---|
72 | print "$file\n"; |
---|
73 | } |
---|
74 | # if is cumbersome on Windows, we may assume the CVS synch is already achieved |
---|
75 | # on the Linux side. |
---|
76 | |
---|
77 | |
---|
78 | print "now trigger compilation of madx.exe, madxp.exe and pars.exe\n"; |
---|
79 | print "(for the time-being, skip compilation)\n"; |
---|
80 | # invoke compilation of madx.exe, madxp.exe and pars.exe |
---|
81 | # monday 29 september 2009: comment/uncomment the following: |
---|
82 | system("MakefileIntel.bat"); |
---|
83 | # moving these files to the proper AFS web folder is left to the calling |
---|
84 | # Linux-side Perl script... |
---|
85 | # (an e-mail will be sent to observers of the Windows distribution of MAD-X) |
---|
86 | |
---|
87 | # chdir("Z:\\MAD-X\\madX\"); |
---|
88 | } |
---|
89 | |
---|
90 | sleep 5; # necessary ????? |
---|
91 | |
---|
92 | $clientHost = $1; |
---|
93 | print "clientHost is '$clientHost'\n"; |
---|
94 | |
---|
95 | my $replySock = new IO::Socket::INET( |
---|
96 | PeerAddr => $clientHost, |
---|
97 | PeerPort => $socketPortLinux, |
---|
98 | Proto => 'tcp' |
---|
99 | ); |
---|
100 | |
---|
101 | die "Could not create socket $socketPortLinux to reply: $!\n" unless $replySock; |
---|
102 | print $replySock "Compilation completed\n"; |
---|
103 | print "sent acknowledgement to $clientHost\n"; |
---|
104 | close($replySock); |
---|
105 | |
---|
106 | # once compliation completed, send an acknowledgement message to the |
---|
107 | # the Linux box that triggered the compilation in the first place |
---|
108 | |
---|
109 | #last; |
---|
110 | |
---|
111 | } # if client requests MAD compilation on Windows |
---|
112 | } # receiving from the socket |
---|
113 | |
---|
114 | print "disconnected from client\n"; |
---|
115 | |
---|
116 | } # do for ever |
---|
117 | |
---|
118 | |
---|
119 | close($sock); |
---|