2008-05-13 14:05:18 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#-------------------------------------------------------
|
|
|
|
package xCAT_plugin::FTPsn;
|
|
|
|
use xCAT::Table;
|
|
|
|
|
|
|
|
use xCAT::Utils;
|
|
|
|
use File::Basename;
|
2008-05-21 14:02:38 +00:00
|
|
|
use File::Path;
|
2008-05-13 14:05:18 +00:00
|
|
|
use xCAT::MsgUtils;
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2008-05-21 14:02:38 +00:00
|
|
|
=head1
|
2008-09-09 12:31:27 +00:00
|
|
|
xCAT plugin package to setup vstftp on a Linux service node
|
2008-05-13 14:05:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2008-05-21 14:02:38 +00:00
|
|
|
=head3 handled_commands
|
2008-05-13 14:05:18 +00:00
|
|
|
|
2008-09-09 12:31:27 +00:00
|
|
|
This runs on Linux Service Node
|
2008-05-13 14:05:18 +00:00
|
|
|
Checks servicenode table ftpserver attribute
|
2008-09-09 12:31:27 +00:00
|
|
|
Call setup_TFTP (actually setting up vstftp)
|
2008-05-13 14:05:18 +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-09-09 12:31:27 +00:00
|
|
|
if (xCAT::Utils->isAIX()) { # do not run on AIX
|
|
|
|
return 0;
|
|
|
|
}
|
2008-05-19 18:15:48 +00:00
|
|
|
|
2008-05-13 14:05:18 +00:00
|
|
|
my $rc = 0;
|
|
|
|
|
|
|
|
# setup vstftp
|
|
|
|
if (xCAT::Utils->isServiceNode())
|
|
|
|
{
|
|
|
|
my @nodeinfo = xCAT::Utils->determinehostname;
|
|
|
|
my $nodename = pop @nodeinfo; # get hostname
|
|
|
|
my @nodeipaddr = @nodeinfo; # get ip addresses
|
|
|
|
my $service = "ftpserver";
|
|
|
|
$rc = xCAT::Utils->isServiceReq($nodename, $service, \@nodeipaddr);
|
2008-05-13 18:10:52 +00:00
|
|
|
if ($rc == 1)
|
2008-05-13 14:05:18 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
$rc = &setup_FTP(); # setup vsftpd
|
|
|
|
if ($rc == 0)
|
|
|
|
{
|
|
|
|
xCAT::Utils->update_xCATSN($service);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($rc == 2)
|
|
|
|
{ # just start the daemon
|
|
|
|
my $cmd = "service vsftpd restart";
|
|
|
|
system $cmd;
|
|
|
|
if ($? > 0)
|
|
|
|
{ # error
|
|
|
|
xCAT::MsgUtils->message("S", "Error on command: $cmd");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { # Management Node
|
|
|
|
$rc = &setup_FTP(); # setup vsftpd
|
|
|
|
}
|
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
|
2008-05-21 14:02:38 +00:00
|
|
|
=head3 process_request
|
2008-05-13 14:05:18 +00:00
|
|
|
|
|
|
|
Process the command
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-------------------------------------------------------
|
|
|
|
sub process_request
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
2008-05-21 14:02:38 +00:00
|
|
|
=head3 setup_FTP
|
2008-05-13 14:05:18 +00:00
|
|
|
|
2008-05-21 14:02:38 +00:00
|
|
|
Sets up FTP services (vstftp)
|
2008-05-13 14:05:18 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub setup_FTP
|
|
|
|
{
|
|
|
|
my $rc = 0;
|
|
|
|
my $cmd;
|
|
|
|
$XCATROOT = "/opt/xcat"; # default
|
|
|
|
|
|
|
|
if ($ENV{'XCATROOT'})
|
|
|
|
{
|
|
|
|
$XCATROOT = $ENV{'XCATROOT'};
|
|
|
|
}
|
|
|
|
|
|
|
|
# change ftp user id home directory to installdir
|
|
|
|
# link installdir
|
|
|
|
# restart the daemon
|
|
|
|
my $installdir = "/install"; # default
|
|
|
|
# read from database
|
|
|
|
my @installdir1 = xCAT::Utils->get_site_attribute("installdir");
|
|
|
|
if ($installdir1[0]) # if exists
|
|
|
|
{
|
|
|
|
$installdir = $installdir1[0];
|
|
|
|
}
|
|
|
|
if (!(-e $installdir)) # make it
|
|
|
|
{
|
|
|
|
mkpath($installdir);
|
|
|
|
}
|
|
|
|
$cmd = "usermod -d $installdir ftp";
|
|
|
|
system $cmd;
|
2008-05-21 14:02:38 +00:00
|
|
|
if ($? > 0) {
|
|
|
|
|
2008-05-13 14:05:18 +00:00
|
|
|
xCAT::MsgUtils->message("S", "Error from command:$cmd");
|
|
|
|
}
|
|
|
|
|
|
|
|
# restart tftp
|
|
|
|
|
|
|
|
my $cmd = "service vsftpd restart";
|
|
|
|
system $cmd;
|
|
|
|
if ($? > 0)
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("S", "Error from command:$cmd");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
my $cmd = "chkconfig vsftpd on";
|
|
|
|
system $cmd;
|
|
|
|
if ($? > 0)
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("S", "Error from command:$cmd");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
1;
|