2008-02-25 13:05:21 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#-------------------------------------------------------
|
|
|
|
package xCAT_plugin::TFTPsn;
|
|
|
|
use xCAT::Table;
|
|
|
|
|
|
|
|
use xCAT::Utils;
|
|
|
|
|
|
|
|
use xCAT::MsgUtils;
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head1
|
2008-05-13 18:25:39 +00:00
|
|
|
xCAT plugin package to setup atftp on a service node
|
2008-02-25 13:05:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 handled_commands
|
|
|
|
|
2008-04-22 13:24:38 +00:00
|
|
|
This runs on Service Node
|
2008-05-13 12:49:38 +00:00
|
|
|
Checks servicenode table tfpserver attribute
|
2008-02-27 22:06:42 +00:00
|
|
|
Call setup_TFTP (actually setting up atftp)
|
2008-02-25 13:05:21 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
sub handled_commands
|
|
|
|
{
|
2008-05-19 18:15:48 +00:00
|
|
|
# If called in XCATBYPASS mode, don't do any setup
|
|
|
|
if ($ENV{'XCATBYPASS'}) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-06 18:42:32 +00:00
|
|
|
my $rc = 0;
|
2008-02-27 22:06:42 +00:00
|
|
|
|
|
|
|
# setup atftp
|
2008-04-22 13:24:38 +00:00
|
|
|
if (xCAT::Utils->isServiceNode())
|
2008-03-16 13:40:12 +00:00
|
|
|
{
|
2008-04-22 13:24:38 +00:00
|
|
|
my @nodeinfo = xCAT::Utils->determinehostname;
|
|
|
|
my $nodename = pop @nodeinfo; # get hostname
|
|
|
|
my @nodeipaddr = @nodeinfo; # get ip addresses
|
|
|
|
my $service = "tftpserver";
|
|
|
|
$rc = xCAT::Utils->isServiceReq($nodename, $service, \@nodeipaddr);
|
2008-05-13 12:49:38 +00:00
|
|
|
if ($rc == 1)
|
2008-02-27 22:06:42 +00:00
|
|
|
{
|
2008-05-13 18:25:39 +00:00
|
|
|
|
|
|
|
$rc = &setup_TFTP($nodename); # setup TFTP (ATFTP)
|
2008-04-22 13:24:38 +00:00
|
|
|
if ($rc == 0)
|
|
|
|
{
|
|
|
|
xCAT::Utils->update_xCATSN($service);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($rc == 2)
|
|
|
|
{ # just start the daemon
|
|
|
|
my $cmd = "service tftpd start";
|
2008-05-13 12:49:38 +00:00
|
|
|
system $cmd;
|
|
|
|
if ($? > 0)
|
2008-04-22 13:24:38 +00:00
|
|
|
{ # error
|
|
|
|
xCAT::MsgUtils->message("S", "Error on command: $cmd");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2008-02-25 13:05:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 process_request
|
|
|
|
|
|
|
|
Process the command
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub process_request
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 setup_TFTP
|
|
|
|
|
2008-02-27 22:06:42 +00:00
|
|
|
Sets up TFTP services (using atftp)
|
2008-02-25 13:05:21 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub setup_TFTP
|
|
|
|
{
|
|
|
|
my ($nodename) = @_;
|
2008-02-27 22:06:42 +00:00
|
|
|
my $rc = 0;
|
|
|
|
my $tftpdir = "/tftpboot"; # default
|
|
|
|
my $cmd;
|
|
|
|
my $master;
|
|
|
|
my $os;
|
|
|
|
my $arch;
|
|
|
|
$XCATROOT = "/opt/xcat"; # default
|
|
|
|
|
|
|
|
if ($ENV{'XCATROOT'})
|
|
|
|
{
|
|
|
|
$XCATROOT = $ENV{'XCATROOT'};
|
2008-02-25 13:05:21 +00:00
|
|
|
}
|
|
|
|
|
2008-04-22 13:24:38 +00:00
|
|
|
# read DB for nodeinfo
|
2008-05-13 18:25:39 +00:00
|
|
|
my $retdata = xCAT::Utils->readSNInfo($nodename);
|
2008-04-22 13:24:38 +00:00
|
|
|
$master = $retdata->{'master'};
|
|
|
|
$os = $retdata->{'os'};
|
|
|
|
$arch = $retdata->{'arch'};
|
|
|
|
if (!($arch))
|
2008-05-13 18:25:39 +00:00
|
|
|
{ # error
|
2008-04-22 13:24:38 +00:00
|
|
|
xCAT::MsgUtils->message("S", " Error reading service node arch.");
|
|
|
|
return 1;
|
2008-02-25 13:05:21 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 22:06:42 +00:00
|
|
|
# check to see if atftp is installed
|
|
|
|
$cmd = "/usr/sbin/in.tftpd -V";
|
|
|
|
my @output = xCAT::Utils->runcmd($cmd, -1);
|
|
|
|
if ($::RUNCMD_RC != 0)
|
2008-05-13 18:25:39 +00:00
|
|
|
{ # not installed
|
2008-02-27 22:06:42 +00:00
|
|
|
xCAT::MsgUtils->message("S", "atftp is not installed");
|
|
|
|
return 1;
|
|
|
|
}
|
2008-05-13 18:25:39 +00:00
|
|
|
if ($output[0] =~ "atftp") # it is atftp
|
2008-02-27 22:06:42 +00:00
|
|
|
{
|
2008-02-25 13:05:21 +00:00
|
|
|
|
2008-05-13 18:25:39 +00:00
|
|
|
# read tftpdir directory from database
|
2008-02-27 22:06:42 +00:00
|
|
|
my @tftpdir1 = xCAT::Utils->get_site_attribute("tftpdir");
|
|
|
|
if ($tftpdir1[0])
|
2008-02-25 13:05:21 +00:00
|
|
|
{
|
2008-02-27 22:06:42 +00:00
|
|
|
$tftpdir = $tftpdir1[0];
|
2008-02-25 13:05:21 +00:00
|
|
|
}
|
2008-05-13 18:25:39 +00:00
|
|
|
if (!(-e $tftpdir))
|
|
|
|
{
|
|
|
|
mkdir($tftpdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
# check to see if tftp directory already mounted
|
|
|
|
my $mounted = xCAT::Utils->isMounted($tftpdir);
|
|
|
|
if ($mounted == 0) # not already mounted
|
|
|
|
{
|
|
|
|
|
|
|
|
# need to mount the directory
|
|
|
|
my $cmd = " mount -o rw,nolock $master:$tftpdir $tftpdir";
|
|
|
|
system $cmd;
|
|
|
|
if ($? > 0)
|
|
|
|
{ # error
|
|
|
|
$rc = 1;
|
|
|
|
xCAT::MsgUtils->message("S", "Error $cmd");
|
|
|
|
}
|
|
|
|
}
|
2008-03-16 13:40:12 +00:00
|
|
|
|
2008-04-22 13:24:38 +00:00
|
|
|
# start atftp
|
2008-02-27 22:06:42 +00:00
|
|
|
|
2008-03-16 13:40:12 +00:00
|
|
|
$cmd = "service tftpd stop";
|
2008-05-13 12:49:38 +00:00
|
|
|
system $cmd;
|
|
|
|
if ($? > 0)
|
2008-03-16 13:40:12 +00:00
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("S", "Error from command:$cmd");
|
2008-02-27 22:06:42 +00:00
|
|
|
}
|
2008-03-16 13:40:12 +00:00
|
|
|
$cmd = "service tftpd start";
|
2008-05-13 12:49:38 +00:00
|
|
|
system $cmd;
|
|
|
|
if ($? > 0)
|
2008-02-27 22:06:42 +00:00
|
|
|
{
|
2008-03-16 13:40:12 +00:00
|
|
|
xCAT::MsgUtils->message("S", "Error from command:$cmd");
|
|
|
|
return 1;
|
2008-02-27 22:06:42 +00:00
|
|
|
}
|
2008-02-25 13:05:21 +00:00
|
|
|
}
|
2008-02-27 22:06:42 +00:00
|
|
|
else
|
|
|
|
{ # no ATFTP
|
|
|
|
xCAT::MsgUtils->message("S", "atftp is not installed");
|
|
|
|
return 1;
|
|
|
|
}
|
2008-04-22 13:24:38 +00:00
|
|
|
|
|
|
|
if ($rc == 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
# update fstab so that it will restart on reboot
|
|
|
|
$cmd =
|
|
|
|
"fgrep \"$master:$tftpdir $tftpdir nfs timeo=14,intr 1 2\" /etc/fstab";
|
|
|
|
xCAT::Utils->runcmd($cmd, -1);
|
|
|
|
if ($::RUNCMD_RC != 0) # not already there
|
|
|
|
{
|
|
|
|
|
|
|
|
`echo "$master:$tftpdir $tftpdir nfs timeo=14,intr 1 2" >>/etc/fstab`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-27 22:06:42 +00:00
|
|
|
return $rc;
|
2008-02-25 13:05:21 +00:00
|
|
|
}
|
|
|
|
1;
|