/usr/bin/gift-start.pl is in gnuift-perl 0.1.14-12.1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | #!/usr/bin/perl -w # -*- mode: perl -*-
# GIFT, a flexible content based image retrieval system.
# Copyright (C) 1998, 1999, 2000, 2001, 2002, CUI University of Geneva
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# this script starts the gift and opens at least one session
#
use IO::Socket;
use lib '/usr/bin'; # for including CFeedbackClient
use CXMLTreeWriter;
use CXMLTreeBuilder;
use CXMLTreeVisitor;
use Net::SMTP;
use POSIX ":sys_wait_h";
use Getopt::Long;
use strict;
use vars qw($lHost
$lPort
$gMailTo
$gMailFromUser
$gSMTPHost
$lDirectory
);
print "
gift-start.pl [--gift-host host] [--gift-port port] [--gift-home gift-home] \\
[--smtp-host host] [--mail-from-user user(s)] [--mail-to user(s)]
This program starts one instance of the GIFT. If this instance dies,
it will send out a message to a list of addresses, saying that the
GIFT has died. It will then automatically restart the GIFT.
STDOUT from the GIFT will be redirected to /dev/null
--gift-host this is the host the GIFT will listen to
(currently NOT USED)
--gift-port this is the port the GIFT will listen to
--gift-home this is the directory where the GIFT will expect its
configuration data.
--smtp-host this is the smtp host which will be used for sending out mail
--mail-to a mail will be sent to this user.
THIS CAN BE A COMMA-SEPARATED LIST OF EMAIL ADDRESSES
--mail-from-user
This program will contact the SMTP server as the following user
";
# Begin:
# this code is taken from the perlipc manpage
#
sub REAPER {
my $child;
$child = wait;
# loathe sysV: it makes us not only reinstate
# the handler, but place it after the wait
$SIG{CHLD} = \&REAPER;
}
# End:
# this code is taken from the perlipc manpage
#
print "$0: Diagnose: I just installed the REAPER\n";
($lHost,$lPort)=split(":","localhost:12789");
$lDirectory=$ENV{GIFT_HOME} || $ENV{HOME};
$gSMTPHost="localhost";
$gMailTo="root\@localhost";
$gMailFromUser=$ENV{USER};
GetOptions('gift-home=s'=>\$lDirectory,
'gift-host=s'=>\$lHost,
'gift-port=s'=>\$lPort,
'smtp-host=s'=>\$gSMTPHost,
'mail-from-user=s'=>\$gMailFromUser,
'mail-to=s'=>\$gMailTo);
die "something wrong, no gift-home directory given" unless $lDirectory;
while(1){
print "doing ps\n";
open PS,"ps -axww|" or die "could not ps";
my $lFound=0;
my $lPID=0;
while(<PS>){
my $lLine=$_;
my(@lParsed)=split(/:\d\d\s/,$lLine);
my $lCall=$lParsed[-1];
if($lCall=~m/gift\s+(\d+)/){
print "FOUND GIFT WITH PORT $1\n";
if($1 == $lPort){
$lFound=1;
$lParsed[0]=~m/^\s+(\d+)/;
$lPID=$1;
}
}
}
unless($lFound){
$SIG{CHLD} = \&REAPER;
print "Before fork to sendit";
if(fork == 0){
&sendIt($lHost,$lPort);
die "Sendit dies";
}else{
my $lCallstring="/usr/bin/gift $lPort $lDirectory > /dev/null";
system("$lCallstring");
print STDERR "gift DIED!\nCalled: $lCallstring\n";
print STDERR "trying to send mail to $gMailTo, using $gSMTPHost, user $gMailFromUser\n";
my $smtp = Net::SMTP->new($gSMTPHost) or die "NO MAILHOST $gSMTPHost";
$smtp->mail($gMailFromUser) or die "Sending mail failed: $!";
$smtp->to((split(",",$gMailTo))) or die "Sending mail failed: $!";
$smtp->data() or die "Sending mail failed: $!";
$smtp->datasend("To: $gMailTo\n") or die "Sending mail failed: $!";
$smtp->datasend("Subject: [dead-GIFT] $lHost:$lPort Reviving: $lCallstring\n") or die "Sending mail failed: $!";
$smtp->datasend("\n") or die "Sending mail failed: $!";
$smtp->datasend("$lCallstring\n
just died
It has been restarted automatically.
this message has been generated automatically by
$0
") or die "Sending mail failed: $!";
$smtp->dataend() or die "Sending mail failed: $!";
$smtp->quit or die "Sending mail failed: $!";
print "Mail successfully sent to $gMailTo\n";
sleep 10;
}
}else{
sleep 300;#sleep for 5 minutes and try again
}
}
sub sendIt( $$ ){
my $lHost=shift;
my $lPort=shift;
sleep 5;
my $self={};
my $lTree={
element=>"mrml",
attributes=>{
},
children=>[
{
element=>"open-session",
attributes=>{
"user-name"=>"giftstart",
"session-name"=>"something",
},
children=>[]
}
,
{
element=>"get-algorithms",
attributes=>{},
children=>[]
}
,
{
element=>"get-collections",
attributes=>{},
children=>[]
}
]
};
my $lSocket = IO::Socket::INET->new(PeerAddr => $lHost,
PeerPort => $lPort,
Proto => 'tcp')
or die "No socket to $lHost:$lPort\n";
$lSocket->autoflush(1);
my $lWriter=new CXMLTreeWriter();
$lWriter->writeToStream($lTree,
$lSocket);
$lSocket->shutdown(1);
my $lRead="";
while(<$lSocket>){
$lRead.=$_;
}
print "READ:$lRead:READ";
my $lBuilder=new CXMLTreeBuilder();
my $lParsed=$lBuilder->stringToTree($lRead);
print "The sessionID is : $lParsed->{attributes}->{'session-id'}\n";
# very GENEVA SPECIFIC: system("find /usr/local/httpd/htdocs/tutorial/ -name \"*.html.in\" -exec perl /home/wolfgang/configure-tutorial.pl $lParsed->{attributes}->{'session-id'} \{\} \\;");
}
|