2009-07-31 14:56:34 +00:00
#!/usr/bin/env perl
2008-01-22 18:53:53 +00:00
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#
2009-07-31 14:56:34 +00:00
#-----------------------------------------------------------------------------
=head1 xcatconfig
This is script is called during the initial installation of xCAT
It can also be called directly to various parts of the configuration
root ssh keys, node host keys, credentials database setup or all
=cut
2008-01-22 18:53:53 +00:00
BEGIN
{
2008-06-11 18:45:47 +00:00
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
$::XCATDIR = $ENV{'XCATDIR'} ? $ENV{'XCATDIR'} : '/etc/xcat';
2008-01-22 18:53:53 +00:00
}
use lib "$::XCATROOT/lib/perl";
2009-12-15 18:55:36 +00:00
use strict;
2008-01-22 18:53:53 +00:00
use xCAT::Utils;
2010-05-12 03:09:08 +00:00
use xCAT::NetworkUtils;
2008-01-22 18:53:53 +00:00
use Getopt::Long;
use xCAT::MsgUtils;
2011-12-20 10:53:50 +00:00
use xCAT::Table;
2008-01-22 18:53:53 +00:00
use Socket;
2009-07-31 14:56:34 +00:00
#-----------------------------------------------------------------------------
# Main
2008-01-22 18:53:53 +00:00
2009-07-31 14:56:34 +00:00
$::progname = "xcatconfig";
my $args = join ' ', @ARGV;
$::command = "$0 $args";
2008-06-11 18:45:47 +00:00
Getopt::Long::Configure("bundling");
$Getopt::Long::ignorecase = 0;
2008-01-22 18:53:53 +00:00
2010-02-24 08:43:40 +00:00
# Default Install dir location
$::INSTALLDIR = "/install";
# Default TFTP dir location
$::TFTPDIR = "/tftpboot";
2008-01-22 18:53:53 +00:00
# parse the options
2008-06-11 18:45:47 +00:00
if (
!GetOptions(
2009-07-31 14:56:34 +00:00
'f|force' => \$::FORCE,
'i|initinstall' => \$::INITIALINSTALL,
'u|updateinstall' => \$::UPDATEINSTALL,
'k|sshkeys' => \$::genSSHRootKeys,
's|sshnodehostkeys' => \$::genSSHNodeHostKeys,
'c|credentials' => \$::genCredentials,
'd|database' => \$::initDB,
'h|help' => \$::HELP,
'v|version' => \$::VERSION,
2009-10-02 19:19:26 +00:00
'V|verbose' => \$::VERBOSE,
2010-02-24 08:43:40 +00:00
'installdir=s' => \$::INSTALLDIR,
'tftpdir=s' => \$::TFTPDIR,
2008-06-11 18:45:47 +00:00
)
)
2008-01-22 18:53:53 +00:00
{
2008-06-11 18:45:47 +00:00
&usage;
exit(1);
2008-01-22 18:53:53 +00:00
}
2009-07-31 14:56:34 +00:00
if ( (!$::HELP)
&& (!$::FORCE)
&& (!$::INITIALINSTALL)
&& (!$::UPDATEINSTALL)
&& (!$::genSSHRootKeys)
&& (!$::genSSHNodeHostKeys)
&& (!$::genCredentials)
&& (!$::initDB)
&& (!$::VERSION))
{
&usage;
exit(1);
}
2008-01-22 18:53:53 +00:00
# display the usage if -h or --help is specified
2008-06-11 18:45:47 +00:00
if ($::HELP)
{
&usage;
exit(0);
2008-01-22 18:53:53 +00:00
}
# display the version statement if -v or --verison is specified
if ($::VERSION)
{
2009-07-31 14:56:34 +00:00
my $version = xCAT::Utils->Version();
$version .= "\n";
xCAT::MsgUtils->message("N", $version);
exit 0;
}
if ($::FORCE)
{
if ( $::INITIALINSTALL
|| $::UPDATEINSTALL
|| $::genSSHRootKeys
|| $::genSSHNodeHostKey
|| $::genCredentials
|| $::initDB)
{
my $warning =
" The -f flag includes the function for the -i, -u, -k, -s, -c, -d flags. Do not combine with other flags.\n ";
xCAT::MsgUtils->message("N", $warning);
exit 1;
}
}
if (($::INITIALINSTALL) && ($::UPDATEINSTALL))
{
my $warning =
" The -i and -u flags may not be input to the command. Use one or the other. \n ";
xCAT::MsgUtils->message("N", $warning);
exit 1;
2008-01-22 18:53:53 +00:00
}
2009-07-31 14:56:34 +00:00
#
# Display command
#
2009-10-02 19:19:26 +00:00
verbose("Running $::command");
2009-07-31 14:56:34 +00:00
if (xCAT::Utils->isAIX())
{
$::osname = 'AIX';
}
else
{
$::osname = 'Linux';
}
2011-02-21 02:19:12 +00:00
#
2011-07-12 04:47:40 +00:00
# To support AIX INUCLIENTS, to support the scenario where the user needs to install xCAT rpms
# into the INUCLIENT=1 environment, such as AIX diskless node(installing xCAT in AIX NIM SPOT),
# or alternative disk installation.
2011-02-21 02:19:12 +00:00
#
2011-07-12 04:47:40 +00:00
2011-02-21 02:19:12 +00:00
if (($::osname eq 'AIX') && ($ENV{'INUCLIENTS'} == 1))
{
# INUCLIENTS is configured, add xcatconfig to /etc/inittab
my $cmd = "/usr/sbin/lsitab xcatconfig > /dev/null 2>&1";
my $rc = system("$cmd") >>8;
if ($rc != 0)
{
# add new entry
my $flag;
if ($::INITIALINSTALL)
{
$flag = "-i";
}
if ($::UPDATEINSTALL)
{
$flag = "-u";
}
if ($::initDB)
{
$flag = "-d";
}
my $mkcmd = qq~/usr/sbin/mkitab "xcatconfig:2:once:$::XCATROOT/sbin/xcatconfig $flag > /dev/console 2>&1"~;
system("$mkcmd");
}
exit(0);
}
2008-06-11 18:45:47 +00:00
if ($::osname eq 'AIX')
{
$::arch = `uname -p`;
2010-11-10 04:31:27 +00:00
#$::root = "";
$::root = xCAT::Utils->getHomeDir();
2008-06-11 18:45:47 +00:00
}
else
{
$::arch = `uname -m`;
$::root = "/root";
2008-01-22 18:53:53 +00:00
}
chomp $::arch;
chomp $::root;
2009-02-10 19:48:29 +00:00
2008-06-11 18:45:47 +00:00
2009-07-31 14:56:34 +00:00
# some Linux-only config
2009-10-02 19:19:26 +00:00
# Do not need to start vsftpd here, because when xcatd starts, it will restart it
#if ($::osname eq 'Linux')
#{
2009-12-15 18:55:36 +00:00
# start vsftpd
2009-10-02 19:19:26 +00:00
# my $cmd = "/sbin/chkconfig vsftpd on";
# my $outref = xCAT::Utils->runcmd("$cmd", 0);
# my $cmd = "/etc/init.d/vsftpd restart";
# my $outref = xCAT::Utils->runcmd("$cmd", 0);
# if ($::RUNCMD_RC != 0)
# {
# xCAT::MsgUtils->message('E', "Could not start VSFTPD.");
# }
# else
# {
# xCAT::MsgUtils->message('I', "VSFTPD has been restarted.");
# }
#} # end Linux-only
2008-01-22 18:53:53 +00:00
#
2009-07-31 14:56:34 +00:00
# Generate ssh host keys for the nodes
#
2008-01-22 18:53:53 +00:00
#
2010-12-15 14:54:45 +00:00
if (xCAT::Utils->isMN()) {
&genSSHNodeHostKey;
}
2009-07-31 14:56:34 +00:00
#
# gen root's ssh keys, if needed and copy to appropriate directories to
# be used during install
#
if ($::INITIALINSTALL || $::FORCE || $::genSSHRootKeys)
2009-02-10 19:48:29 +00:00
{
2009-07-31 14:56:34 +00:00
&genSSHRootKeys; # gen new rsa ssh key for root
2009-02-10 19:48:29 +00:00
}
2008-06-11 18:45:47 +00:00
2009-11-06 20:27:08 +00:00
#
# Update /etc/profile on AIX
#
2009-12-15 18:55:36 +00:00
if ($::INITIALINSTALL)
{
my $profname = "/etc/profile";
if ($::osname eq 'AIX')
{
my $cmd = qq~cat $profname | grep "XCATROOT"~;
my $outref = xCAT::Utils->runcmd("$cmd", -1);
if ($::RUNCMD_RC != 0)
{
# make back up file
my $cpcmd = qq~/bin/cp -p $profname $profname.orig~;
my $outref = xCAT::Utils->runcmd("$cpcmd", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E', "Could not copy $profname.");
}
# add xCAT paths
my $eccmd =
2011-10-09 00:50:21 +00:00
qq~echo '# xCAT setup\nXCATROOT=$::XCATROOT\nPATH=\$XCATROOT/bin:\$XCATROOT/sbin:\$PATH\nMANPATH=\$XCATROOT/share/man:\$MANPATH\nexport XCATROOT PATH MANPATH' >>$profname~;
2010-04-27 20:44:09 +00:00
$outref = xCAT::Utils->runcmd("$eccmd", 0);
2009-12-15 18:55:36 +00:00
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E', "Could not update $profname.");
}
}
}
2009-11-06 20:27:08 +00:00
}
2009-07-31 14:56:34 +00:00
if ($::INITIALINSTALL || $::FORCE || $::UPDATEINSTALL)
{
2008-06-11 18:45:47 +00:00
2009-02-10 19:48:29 +00:00
#
2009-07-31 14:56:34 +00:00
# For all MNs create /var/log/consoles if needed
# Conserver won't start without it
2009-02-10 19:48:29 +00:00
#
2009-07-31 14:56:34 +00:00
if (!-d "/var/log/consoles")
2009-05-11 17:48:54 +00:00
{
2009-07-31 14:56:34 +00:00
my $cmd = "/bin/mkdir -p /var/log/consoles";
2009-05-11 17:48:54 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
2009-07-31 14:56:34 +00:00
xCAT::MsgUtils->message('E',
2009-12-15 18:55:36 +00:00
"Could not create /var/log/consoles directory.");
2009-05-11 17:48:54 +00:00
}
2009-07-31 14:56:34 +00:00
else
2009-05-11 17:48:54 +00:00
{
2009-10-02 19:19:26 +00:00
verbose("Created /var/log/consoles directory.");
2009-05-11 17:48:54 +00:00
}
}
2009-07-31 14:56:34 +00:00
if ($::osname eq 'AIX')
2009-05-11 17:48:54 +00:00
{
2012-07-10 18:51:30 +00:00
if ($::INITIALINSTALL) { # only do once on install
xCAT::Utils->setupAIXconserver($::VERBOSE);
}
2009-12-15 18:55:36 +00:00
&setupAIXIPMITool;
2009-07-31 14:56:34 +00:00
2009-12-03 08:01:33 +00:00
# Add the xcatd subsystem to the AIX
no strict 'refs';
2009-12-15 18:55:36 +00:00
my $mkssys_cmd =
"mkssys -p $::XCATROOT/sbin/xcatd -s xcatd -u 0 -S -n 15 -f 15 -a \"-f\"";
2009-12-03 08:01:33 +00:00
system($mkssys_cmd);
use strict;
2011-11-04 10:37:02 +00:00
# if not Update, add to inittab
# breaks HAMS to add on update
if (! $::UPDATEINSTALL) {
2010-03-24 15:15:08 +00:00
# for AIX systems add xcatd to the /etc/inittab file
2011-07-01 14:58:53 +00:00
# add xcatd entry if one does not exist
2010-03-24 15:15:08 +00:00
my $rcmd = "/bin/cat /etc/inittab | grep 'xcatd'";
my $outref = xCAT::Utils->runcmd("$rcmd", -1);
2011-07-01 14:58:53 +00:00
if ($::RUNCMD_RC != 0) {
my $mkitab_cmd =
"mkitab \"xcatd:2:once:$::XCATROOT/sbin/restartxcatd > /dev/console 2>&1\" > /dev/null 2>&1";
xCAT::Utils->runcmd("$mkitab_cmd", 0);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message('E', "Could not set up inittab.");
}
2010-03-24 15:15:08 +00:00
}
2011-11-04 10:37:02 +00:00
}
2010-03-24 15:15:08 +00:00
2009-07-31 14:56:34 +00:00
# add AIX needed exports
&setupAIXexports;
2009-05-11 17:48:54 +00:00
}
2009-07-31 14:56:34 +00:00
2009-12-15 18:55:36 +00:00
else # for Linux
2009-05-11 17:48:54 +00:00
{
2009-12-15 18:55:36 +00:00
&setupLinuxexports; # add Linux exports
2009-07-31 14:56:34 +00:00
2009-05-11 17:48:54 +00:00
}
2009-07-31 14:56:34 +00:00
} # end install,update or force
2010-03-18 16:32:06 +00:00
#
# set up the certificates for xcatd, gen new ones if requested or do not exist
#
2010-04-23 18:06:29 +00:00
if ($::INITIALINSTALL || $::UPDATEINSTALL || $::FORCE || $::genCredentials)
2010-03-18 16:32:06 +00:00
{
&genCredentials;
}
2009-07-31 14:56:34 +00:00
#
# Setup database
#
if ($::INITIALINSTALL || $::UPDATEINSTALL || $::FORCE || $::initDB)
{
&initDB;
}
#
# set up syslog
#
# use postscript to set up syslog
if ($::INITIALINSTALL || $::FORCE || $::UPDATEINSTALL)
{
2010-02-24 08:43:40 +00:00
my $cmd = "$::INSTALLDIR/postscripts/syslog";
2009-05-11 17:48:54 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "Could not set up syslog.");
2009-05-11 17:48:54 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
verbose("syslog has been set up.");
2009-05-11 17:48:54 +00:00
}
2008-06-11 18:45:47 +00:00
}
2009-02-10 19:48:29 +00:00
2008-05-29 13:50:12 +00:00
#
2009-07-31 14:56:34 +00:00
#
# start xcatd
2008-01-22 18:53:53 +00:00
#
2009-07-31 14:56:34 +00:00
if ($::INITIALINSTALL || $::FORCE || $::UPDATEINSTALL || $::genCredentials)
2008-06-11 18:45:47 +00:00
{
2009-07-31 14:56:34 +00:00
my $xcmd;
if ($::osname eq 'AIX')
2008-06-11 18:45:47 +00:00
{
2011-02-21 02:19:12 +00:00
$xcmd = "$::XCATROOT/sbin/restartxcatd";
2008-06-11 18:45:47 +00:00
}
else
{
2009-07-31 14:56:34 +00:00
$xcmd = "/etc/init.d/xcatd restart";
2008-06-11 18:45:47 +00:00
}
2009-07-31 14:56:34 +00:00
system($xcmd);
2008-01-22 18:53:53 +00:00
}
2011-04-15 14:17:42 +00:00
# more config needed after xcatd start
if ($::INITIALINSTALL || $::FORCE)
2008-06-11 18:45:47 +00:00
{
2010-12-15 14:21:04 +00:00
my $cmd;
2011-04-15 14:17:42 +00:00
if ($::osname eq 'Linux') {
#Zap the almost certainly wrong pxelinux.cfg file
if (-f "$::TFTPDIR/pxelinux.cfg/default")
{
2010-02-24 08:43:40 +00:00
$cmd = "/bin/rm $::TFTPDIR/pxelinux.cfg/default";
2008-06-11 18:45:47 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
2010-02-24 08:43:40 +00:00
"Could not remove $::TFTPDIR/pxelinux.cfg/default");
2008-06-11 18:45:47 +00:00
}
else
{
2010-02-24 08:43:40 +00:00
verbose("Removed $::TFTPDIR/pxelinux.cfg/default.");
2008-06-11 18:45:47 +00:00
}
2011-04-15 14:17:42 +00:00
}
2008-06-11 18:45:47 +00:00
2011-04-15 14:17:42 +00:00
# run mknb - only needed for Intel platforms for now
&mknb;
2008-01-22 18:53:53 +00:00
2011-04-15 14:17:42 +00:00
# makenetworks and setup http
&makenetworks;
&setuphttp;
2009-07-31 14:56:34 +00:00
2012-06-29 03:14:32 +00:00
# chkconfig dhcpd on
system("chkconfig dhcpd on");
2011-04-15 14:17:42 +00:00
my $linux_note =
"xCAT is now running, it is recommended to tabedit networks \nand set a dynamic ip address range on any networks where nodes \nare to be discovered. Then, run makedhcp -n to create a new dhcpd \nconfiguration file, and \/etc\/init.d\/dhcpd restart. Either examine sample \nconfiguration templates, or write your own, or specify a value per \nnode with nodeadd or tabedit.";
xCAT::MsgUtils->message('I', $linux_note);
} else { #AIX
# makenetworks
&makenetworks;
my $AIX_note =
"xCAT is now running.";
xCAT::MsgUtils->message('I', $AIX_note);
}
2009-07-31 14:56:34 +00:00
} #End - more - Linux-only config
2011-02-21 02:19:12 +00:00
END
{
# Remove xcatconfig itself from the inittab
if (($::osname eq 'AIX') && ($ENV{'INUCLIENTS'} != 1))
{
my $cmd = "/usr/sbin/lsitab xcatconfig > /dev/null 2>&1";
my $rc = system("$cmd") >>8;
if ($rc == 0)
{
my $rmcmd = '/usr/sbin/rmitab xcatconfig';
system("$rmcmd");
}
}
}
2009-07-31 14:56:34 +00:00
exit;
#####################################
# subroutines
#####################################
#-----------------------------------------------------------------------------
=head3 usage
Displays message for -h option
=cut
#-----------------------------------------------------------------------------
sub usage
2008-06-11 18:45:47 +00:00
{
2009-07-31 14:56:34 +00:00
xCAT::MsgUtils->message(
'I',
2009-10-02 19:19:26 +00:00
"Usage:\nxcatconfig - Performs basic xCAT setup operations on an xCAT management node. This command should not be run on an xCAT Service Node, unless you are making it a Management Node.\n"
2009-07-31 14:56:34 +00:00
);
xCAT::MsgUtils->message(
'I',
2009-10-02 19:19:26 +00:00
"xcatconfig [-h|--help]\nxcatconfig [-v|--version]\nxcatconfig [-f|--force] [-V|--verbose]\nxcatconfig [-i|--initinstall] [-V|--verbose]\nxcatconfig [-u|--updateinstall] [-V|--verbose]\nxcatconfig [-k|--sshkeys] [-s|--sshnodehostkeys] [-c|--credentials] [-d|database] [-V|--verbose]"
2009-07-31 14:56:34 +00:00
);
2008-01-22 18:53:53 +00:00
}
2009-10-02 19:19:26 +00:00
sub verbose
{
2009-12-15 18:55:36 +00:00
if (!$::VERBOSE) { return; }
my $msg = shift;
xCAT::MsgUtils->message("I", $msg);
2009-10-02 19:19:26 +00:00
}
2009-12-15 18:55:36 +00:00
2009-07-31 14:56:34 +00:00
#-----------------------------------------------------------------------------
=head3 genSSHRootKeys
Will generate a new ssh rsa key for the root user, if it does not exist or if requested by the input -k flag.
=cut
#-----------------------------------------------------------------------------
sub genSSHRootKeys
2008-06-11 18:45:47 +00:00
{
2009-07-31 14:56:34 +00:00
#
# create /.ssh dir if needed
#
my $sshdir = "$::root/.ssh";
if (!-d $sshdir)
2008-06-11 18:45:47 +00:00
{
2009-07-31 14:56:34 +00:00
my $cmd = "/bin/mkdir -m 700 -p $sshdir";
2008-01-22 18:53:53 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
2008-06-11 18:45:47 +00:00
if ($::RUNCMD_RC != 0)
{
2009-12-15 18:55:36 +00:00
xCAT::MsgUtils->message('E', "Could not create $sshdir directory.");
2008-06-11 18:45:47 +00:00
}
else
2008-01-22 18:53:53 +00:00
{
2009-10-02 19:19:26 +00:00
verbose("Created $sshdir directory.");
2008-01-22 18:53:53 +00:00
}
}
2009-07-31 14:56:34 +00:00
#
# create or modify the -/.ssh/config file
#
my $cfgfile = "$::root/.ssh/config";
if (-f $cfgfile)
2008-06-11 18:45:47 +00:00
{
2009-07-31 14:56:34 +00:00
# it exists - so see if it needs to be updated
my $cmd = "/bin/cat $cfgfile | grep 'StrictHostKeyChecking no'";
my $outref = xCAT::Utils->runcmd("$cmd", -1);
if ($::RUNCMD_RC != 0)
2009-02-10 19:48:29 +00:00
{
2009-07-31 14:56:34 +00:00
# ok - then add this entry
my $cmd =
"/bin/echo StrictHostKeyChecking no >> $cfgfile; chmod 600 $cfgfile";
2009-02-10 19:48:29 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
2009-12-15 18:55:36 +00:00
"Could not update the $cfgfile file.");
2009-02-10 19:48:29 +00:00
}
else
{
xCAT::MsgUtils->message('I',
2009-12-15 18:55:36 +00:00
"Added updates to the $cfgfile file.");
2009-02-10 19:48:29 +00:00
}
}
2008-06-11 18:45:47 +00:00
}
else
{
2008-01-22 18:53:53 +00:00
2009-07-31 14:56:34 +00:00
# file doesn't exist so just create it
my $cmd =
"/bin/echo StrictHostKeyChecking no > $cfgfile; chmod 600 $cfgfile";
2009-05-02 21:21:40 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
2009-03-19 07:57:02 +00:00
if ($::RUNCMD_RC != 0)
{
2009-12-15 18:55:36 +00:00
xCAT::MsgUtils->message('E', "Could not update the $cfgfile file.");
2009-03-19 07:57:02 +00:00
}
else
{
2009-12-15 18:55:36 +00:00
xCAT::MsgUtils->message('I', "Added updates to the $cfgfile file.");
2009-03-19 07:57:02 +00:00
}
}
2009-05-02 21:21:40 +00:00
2009-07-31 14:56:34 +00:00
#
# create /install/postscripts/_ssh if needed
#
2010-02-24 08:43:40 +00:00
if (!-d "$::INSTALLDIR/postscripts/_ssh")
2009-05-02 21:21:40 +00:00
{
2010-10-27 10:38:13 +00:00
my $cmd = "/bin/mkdir -m 755 -p $::INSTALLDIR/postscripts/_ssh";
2009-07-31 14:56:34 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
2009-05-02 21:21:40 +00:00
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
2010-02-24 08:43:40 +00:00
"Could not create $::INSTALLDIR/postscripts/_ssh directory.");
2009-05-02 21:21:40 +00:00
}
else
{
2010-02-24 08:43:40 +00:00
verbose("Created $::INSTALLDIR/postscripts/_ssh directory.");
2009-05-02 21:21:40 +00:00
}
2009-03-19 07:57:02 +00:00
}
2008-01-22 18:53:53 +00:00
2009-07-31 14:56:34 +00:00
#need to gen a new rsa key for root ssh, if Force, genkey or does not exist
my $pubfile = "$::root/.ssh/id_rsa.pub";
my $rsafile = "$::root/.ssh/id_rsa";
2008-01-22 18:53:53 +00:00
2009-07-31 14:56:34 +00:00
# if exists, and generated new then
# need to remove the old files
if ((-r $pubfile) && ($::FORCE || $::genSSHRootKeys))
2008-01-22 18:53:53 +00:00
{
2009-07-31 14:56:34 +00:00
my $cmd = "/bin/rm $::root/.ssh/id_rsa*";
2008-01-22 18:53:53 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
2008-06-11 18:45:47 +00:00
if ($::RUNCMD_RC != 0)
{
2009-12-15 18:55:36 +00:00
xCAT::MsgUtils->message('E',
"Could not remove id_rsa files from $::root/.ssh directory.");
2008-06-11 18:45:47 +00:00
}
else
2008-01-22 18:53:53 +00:00
{
2008-06-11 18:45:47 +00:00
xCAT::MsgUtils->message('I',
2009-12-15 18:55:36 +00:00
"Removed id_rsa files from $::root/.ssh directory.");
2008-01-22 18:53:53 +00:00
}
2008-06-11 18:45:47 +00:00
}
2008-01-22 18:53:53 +00:00
2009-07-31 14:56:34 +00:00
# ssh key does not exist, gen a new one else leave alone
if (!-r $pubfile)
2008-01-22 18:53:53 +00:00
{
2009-07-31 14:56:34 +00:00
my $cmd = "/usr/bin/ssh-keygen -t rsa -q -b 2048 -N '' -f $rsafile";
2008-01-22 18:53:53 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
2008-06-11 18:45:47 +00:00
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "Could not generate $pubfile.");
2008-06-11 18:45:47 +00:00
}
else
2008-01-22 18:53:53 +00:00
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('I', "Generated $pubfile.");
2009-07-31 14:56:34 +00:00
2008-01-22 18:53:53 +00:00
}
}
2009-07-31 14:56:34 +00:00
# copy authorized_keys for install on node
if (-r $pubfile)
2008-06-11 18:45:47 +00:00
{
2009-07-31 14:56:34 +00:00
my $cmd =
2010-02-24 08:43:40 +00:00
"/bin/cp -p $pubfile $::INSTALLDIR/postscripts/_ssh/authorized_keys ";
2008-06-11 18:45:47 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
2009-07-31 14:56:34 +00:00
xCAT::MsgUtils->message(
'E',
2010-02-24 08:43:40 +00:00
"Could not copy $pubfile to $::INSTALLDIR/postscripts/_ssh/authorized_keys."
2009-07-31 14:56:34 +00:00
);
2008-06-11 18:45:47 +00:00
}
else
2008-01-22 18:53:53 +00:00
{
2009-07-31 14:56:34 +00:00
xCAT::MsgUtils->message(
2009-12-15 18:55:36 +00:00
'I',
2010-02-24 08:43:40 +00:00
"Copied $pubfile to $::INSTALLDIR/postscripts/_ssh/authorized_keys."
2009-12-15 18:55:36 +00:00
);
2008-06-11 18:45:47 +00:00
}
}
2009-05-02 21:21:40 +00:00
else
{
2009-07-31 14:56:34 +00:00
xCAT::MsgUtils->message(
'E',
2010-02-24 08:43:40 +00:00
"Could not copy $pubfile to $::INSTALLDIR/postscripts/_ssh/authorized_keys,because $pubfile does not exist."
2009-07-31 14:56:34 +00:00
);
2009-05-02 21:21:40 +00:00
}
2008-06-11 18:45:47 +00:00
}
2009-07-31 14:56:34 +00:00
#-----------------------------------------------------------------------------
2008-06-11 18:45:47 +00:00
2009-07-31 14:56:34 +00:00
=head3 genSSHNodeHostKey
If node private node hostkeys do not exist in either directory or force option
or generate host key option, we need to generate them
These keys are installed on the nodes in /etc/ssh directory and allow the
node to ssh without password node to node.
They are store in /etc/xcat/hostkeys on the MN.
This also includes some migration to /install/postscripts/hostkeys
for the install process
2008-01-22 18:53:53 +00:00
2009-07-31 14:56:34 +00:00
=cut
2008-01-22 18:53:53 +00:00
2009-07-31 14:56:34 +00:00
#-----------------------------------------------------------------------------
2008-01-22 18:53:53 +00:00
2009-07-31 14:56:34 +00:00
sub genSSHNodeHostKey
2008-01-22 18:53:53 +00:00
2008-06-11 18:45:47 +00:00
{
2008-04-15 12:53:58 +00:00
2010-02-24 08:43:40 +00:00
my $hostkey = "$::INSTALLDIR/postscripts/hostkeys/ssh_host_rsa_key";
2009-07-31 14:56:34 +00:00
my $hostkey2 = "/etc/xcat/hostkeys/ssh_host_rsa_key";
if ( ((!-r $hostkey) && (!-r $hostkey2))
|| $::FORCE
|| $::genSSHNodeHostKeys)
2008-06-11 18:45:47 +00:00
{
2009-07-31 14:56:34 +00:00
# create directories /etc/xcat/hostkeys and /install/postscripts/hostkeys
2010-02-24 08:43:40 +00:00
if (!-d "$::INSTALLDIR/postscripts/hostkeys") # directory for public keys
2009-07-31 14:56:34 +00:00
{
2010-10-27 10:38:13 +00:00
my $cmd = "/bin/mkdir -m 755 -p $::INSTALLDIR/postscripts/hostkeys";
2009-07-31 14:56:34 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message(
2009-12-15 18:55:36 +00:00
'E',
2010-02-24 08:43:40 +00:00
"Could not create $::INSTALLDIR/postscripts/hostkeys directory."
2009-12-15 18:55:36 +00:00
);
2009-07-31 14:56:34 +00:00
}
}
if (!-d "/etc/xcat/hostkeys") # directory for public/private keys
{
my $cmd = "/bin/mkdir -p /etc/xcat/hostkeys";
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
2009-12-15 18:55:36 +00:00
"Could not create /etc/xcat/hostkeys directory.");
2009-07-31 14:56:34 +00:00
}
}
# remove the old keys
if (-r $hostkey)
{
2010-02-24 08:43:40 +00:00
my $cmd = "/bin/rm $::INSTALLDIR/postscripts/hostkeys/ssh_host*";
2009-07-31 14:56:34 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", -1);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message(
'I',
2010-02-24 08:43:40 +00:00
"Could not remove ssh keys from $::INSTALLDIR/postscripts/hostkeys directory. They may not exist."
2009-07-31 14:56:34 +00:00
);
}
}
# remove the old keys
if (-r $hostkey2)
{
my $cmd = "/bin/rm /etc/xcat/hostkeys/ssh_host*";
my $outref = xCAT::Utils->runcmd("$cmd", -1);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message(
'I',
2009-10-02 19:19:26 +00:00
"Could not remove ssh keys from /etc/xcat/hostkeys directory. They may not exist."
2009-07-31 14:56:34 +00:00
);
}
}
#
# generate new hostkeys
#
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('I', "Generating new node hostkeys...");
xCAT::MsgUtils->message('I', "Generating SSH1 RSA Key...");
2009-07-31 14:56:34 +00:00
my $cmd =
"/usr/bin/ssh-keygen -t rsa1 -f /etc/xcat/hostkeys/ssh_host_key -C '' -N ''";
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "Could not generate SSH1 RSA key.");
2009-07-31 14:56:34 +00:00
}
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('I', "Generating SSH2 RSA Key...");
2010-04-27 20:44:09 +00:00
$cmd =
2009-07-31 14:56:34 +00:00
"/usr/bin/ssh-keygen -t rsa -f /etc/xcat/hostkeys/ssh_host_rsa_key -C '' -N ''";
2010-04-27 20:44:09 +00:00
$outref = xCAT::Utils->runcmd("$cmd", 0);
2009-07-31 14:56:34 +00:00
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "Could not generate SSH2 RSA key.");
2009-07-31 14:56:34 +00:00
}
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('I', "Generating SSH2 DSA Key...");
2010-04-27 20:44:09 +00:00
$cmd =
2009-07-31 14:56:34 +00:00
"/usr/bin/ssh-keygen -t dsa -f /etc/xcat/hostkeys/ssh_host_dsa_key -C '' -N ''";
2010-04-27 20:44:09 +00:00
$outref = xCAT::Utils->runcmd("$cmd", 0);
2009-07-31 14:56:34 +00:00
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "Could not generate SSH2 DSA key.");
2009-07-31 14:56:34 +00:00
}
# copy the public keys to install directory
2010-04-27 20:44:09 +00:00
$cmd =
2010-02-24 08:43:40 +00:00
"/bin/cp /etc/xcat/hostkeys/*.pub $::INSTALLDIR/postscripts/hostkeys/.";
2010-04-27 20:44:09 +00:00
$outref = xCAT::Utils->runcmd("$cmd", 0);
2009-07-31 14:56:34 +00:00
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "$cmd not successful.");
2009-07-31 14:56:34 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
verbose("$cmd is successful");
2009-07-31 14:56:34 +00:00
}
}
else
{ # keys exist and not a request to regenerate
# so if private keys are in /install ( some migration)
# move old hostkeys keys if they exist in /install, to the
# new directory /etc/xcat/hostkeys & remove private keys from /install
2010-02-24 08:43:40 +00:00
if (-f "$::INSTALLDIR/postscripts/hostkeys/ssh_host_rsa_key")
2009-07-31 14:56:34 +00:00
{
# copy all keys to /etc/xcat/hostkeys directory
my $cmd =
2010-02-24 08:43:40 +00:00
"/bin/cp -p $::INSTALLDIR/postscripts/hostkeys/* /etc/xcat/hostkeys/.";
2009-07-31 14:56:34 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "$cmd not successful.");
2009-07-31 14:56:34 +00:00
}
# remove private keys from install dir, leave the public keys
2010-02-24 08:43:40 +00:00
if (-f "$::INSTALLDIR/postscripts/hostkeys/ssh_host_dsa_key")
2009-07-31 14:56:34 +00:00
{
my $cmd =
2010-02-24 08:43:40 +00:00
"/bin/rm $::INSTALLDIR/postscripts/hostkeys/ssh_host_dsa_key";
2009-07-31 14:56:34 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "$cmd not successful.");
2009-07-31 14:56:34 +00:00
}
}
2010-02-24 08:43:40 +00:00
if (-f "$::INSTALLDIR/postscripts/hostkeys/ssh_host_key")
2009-07-31 14:56:34 +00:00
{
2010-02-24 08:43:40 +00:00
my $cmd = "/bin/rm $::INSTALLDIR/postscripts/hostkeys/ssh_host_key";
2009-07-31 14:56:34 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "$cmd not successful.");
2009-07-31 14:56:34 +00:00
}
}
2010-02-24 08:43:40 +00:00
if (-f "$::INSTALLDIR/postscripts/hostkeys/ssh_host_rsa_key")
2009-07-31 14:56:34 +00:00
{
my $cmd =
2010-02-24 08:43:40 +00:00
"/bin/rm $::INSTALLDIR/postscripts/hostkeys/ssh_host_rsa_key";
2009-07-31 14:56:34 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "$cmd not successful.");
2009-07-31 14:56:34 +00:00
}
}
}
# so if no public key in /install/postscripts/hostkeys
# copy the /etc/xcat/hostkeys
# public keys to /install/postscripts/hostkeys
2010-02-24 08:43:40 +00:00
if (!(-f "$::INSTALLDIR/postscripts/hostkeys/ssh_host_rsa_key.pub"))
2009-07-31 14:56:34 +00:00
{
# rm any files
2010-02-24 08:43:40 +00:00
my $cmd = "/bin/rm $::INSTALLDIR/postscripts/hostkeys/*";
2009-07-31 14:56:34 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", -1);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
2009-12-15 18:55:36 +00:00
"$cmd not successful. Files may not exist.");
2009-07-31 14:56:34 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
verbose("$cmd is successful");
2009-07-31 14:56:34 +00:00
}
# copy the public keys to install directory
2010-04-27 20:44:09 +00:00
$cmd =
2010-02-24 08:43:40 +00:00
"/bin/cp /etc/xcat/hostkeys/*.pub $::INSTALLDIR/postscripts/hostkeys/.";
2010-04-27 20:44:09 +00:00
$outref = xCAT::Utils->runcmd("$cmd", 0);
2009-07-31 14:56:34 +00:00
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "$cmd not successful.");
2009-07-31 14:56:34 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
verbose("$cmd is successful");
2009-07-31 14:56:34 +00:00
}
}
2008-04-15 12:53:58 +00:00
}
}
2011-10-06 17:45:08 +00:00
# is_lsb_ubuntu return value indicates whether system appears to be Ubuntu.
# Using required /etc/lsb-release file, instead of optional lsb_release command.
sub is_lsb_ubuntu
{
if (open(my $relfile, "<", "/etc/lsb-release")) {
my @text = <$relfile>;
close($relfile);
chomp(@text);
my $distrib_id = '';
foreach (@text) {
if ( $_ =~ /^\s*DISTRIB_ID=(.*)$/ ) {
$distrib_id = $1; # last DISTRIB_ID value in file used
}
}
if ( $distrib_id =~ /^(Ubuntu|"Ubuntu")\s*$/ ) {
return 1; # return "true"
}
}
return 0; # return "false"
}
2011-09-26 13:34:20 +00:00
# on Ubuntu need to painstakingly compare /etc/localtime with files under
# /usr/share/zoneinfo since /etc/localtime # isn't always a symbolic link
sub discover_timezone_ubuntu
{
my $localtime = "/etc/localtime";
my $zoneinfo = "/usr/share/zoneinfo";
my $zone_result = `find $zoneinfo -type f -exec cmp -s $localtime {} \\; -print | grep -v posix | grep -v SystemV`;
my @zones = split /\n/, $zone_result;
$zones[0] =~ s/$zoneinfo\///;
return $zones[0];
}
2009-07-31 14:56:34 +00:00
#-----------------------------------------------------------------------------
=head3 initDB
Will initialize the DB if it does not already exist, also updates with
2011-12-20 10:53:50 +00:00
new data needed or database changes during xCAT update install.
2009-07-31 14:56:34 +00:00
=cut
#-----------------------------------------------------------------------------
sub initDB
2008-06-11 18:45:47 +00:00
{
2009-07-31 14:56:34 +00:00
my $hname = `hostname`;
chomp $hname;
# some values common to both AIX & Linux
my $xcatport = "3001";
my $xcatiport = "3002";
2010-02-24 08:43:40 +00:00
my $tftpdir = "$::TFTPDIR";
my $installdir = "$::INSTALLDIR";
2009-09-08 19:11:22 +00:00
my $master;
2010-05-12 03:09:08 +00:00
$master = xCAT::NetworkUtils->getipaddr($hname);
if (!$master) {
2009-12-15 18:55:36 +00:00
xCAT::MsgUtils->message("E", "Hostname resolution for $hname failed.");
$master = "NORESOLUTION";
2011-03-30 17:37:53 +00:00
}
# get forwarders which are the nameserver entries in /etc/resolv.conf
2011-07-17 13:27:09 +00:00
# don't use if the address is this machine (Management Node)
2011-05-12 17:26:57 +00:00
my $forwarders;
2011-07-17 13:27:09 +00:00
# find out the names for the Management Node
my @MNnodeinfo = xCAT::Utils->determinehostname;
my $MNnodename = pop @MNnodeinfo; # hostname
my @MNnodeipaddr = @MNnodeinfo; # ipaddresses
my @names;
my @tmpnames =
2011-05-12 17:26:57 +00:00
xCAT::Utils->runcmd(
"/bin/grep ^[^#]*nameserver /etc/resolv.conf | awk '{print \$2}'", -1);
2011-07-17 13:27:09 +00:00
foreach my $ip (@tmpnames) {
if (!grep(/$ip/, @MNnodeipaddr))
{ # if not the MN
push @names,$ip; # add it as a forwarder
}
}
2011-05-12 17:26:57 +00:00
if (@names)
{
$forwarders = join(',', @names);
}
2011-03-30 17:37:53 +00:00
2010-03-18 16:32:06 +00:00
# for policy table
# get hostname from the /etc/xcat/cert/server-cert.pem
my $MNname;
if ( -e ("/etc/xcat/cert/server-cert.pem")) {
my $cmd ="grep Subject /etc/xcat/cert/server-cert.pem";
my $result = xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message("E", "Error from $cmd.\n MN policy not created.");
}
(my $subject,my $mname) = split /CN=/ , $result;
($MNname, my $endstuff) = split /Subject/, $mname;
$MNname =~ s/\s*//g;
}
2009-12-15 18:55:36 +00:00
2009-07-31 14:56:34 +00:00
# set value based on OS
my ($domain, $timezone);
2008-06-11 18:45:47 +00:00
if ($::osname eq 'AIX')
{
2009-07-31 14:56:34 +00:00
my ($name, $rest) = split('\.', $hname);
if ($rest)
{
($domain = $hname) =~ s/^.*?\.//;
}
else
{
$domain = "";
}
$timezone = $ENV{'TZ'};
}
else # linux
{
$domain = `hostname -d`;
my $tz;
if (-f "/etc/redhat-release")
{
# on Redhat look for "ZONE"
$tz =
`grep ^ZONE /etc/sysconfig/clock|cut -d= -f 2|sed -e 's/"//g'`;
}
2011-10-06 17:45:08 +00:00
elsif ( is_lsb_ubuntu() )
2011-09-26 13:34:20 +00:00
{
$tz = discover_timezone_ubuntu;
}
2009-07-31 14:56:34 +00:00
else
{
# on SuSE look for "TIMEZONE"
$tz =
`grep ^TIMEZONE /etc/sysconfig/clock|cut -d= -f 2|sed -e 's/"//g'`;
}
$timezone = $tz;
}
chomp $timezone;
chomp $master;
chomp $domain;
# create basic site definition, if they do not exist reset request
if ( ((!-r "/etc/xcat/site.sqlite") && (!-r "/etc/xcat/cfgloc"))
|| $::FORCE
|| $::initDB)
{
my $chtabcmds;
2009-12-15 18:55:36 +00:00
my $confdir = "/etc/xcat";
my $syncdir = "/var/xcat/syncfiles";
$chtabcmds = "$::XCATROOT/sbin/chtab key=blademaxp site.value=64;";
2009-09-21 19:12:42 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=domain site.value=$domain;";
2009-12-15 18:55:36 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=fsptimeout site.value=0;";
2008-06-11 18:45:47 +00:00
$chtabcmds .=
2009-07-31 14:56:34 +00:00
"$::XCATROOT/sbin/chtab key=installdir site.value=$installdir;";
2009-09-21 19:12:42 +00:00
if ($::osname eq 'Linux')
{
2009-12-15 18:55:36 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=ipmimaxp site.value=64;";
$chtabcmds .=
"$::XCATROOT/sbin/chtab key=ipmiretries site.value=3;";
$chtabcmds .=
"$::XCATROOT/sbin/chtab key=ipmitimeout site.value=2;";
2009-09-21 19:12:42 +00:00
$chtabcmds .=
2010-04-13 13:20:00 +00:00
"$::XCATROOT/sbin/chtab key=consoleondemand site.value=no;";
2009-09-21 19:12:42 +00:00
}
2009-07-31 14:56:34 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=master site.value=$master;";
2011-03-30 17:37:53 +00:00
if ($forwarders) {
$chtabcmds .= "$::XCATROOT/sbin/chtab key=forwarders site.value=$forwarders;";
}
$chtabcmds .= "$::XCATROOT/sbin/chtab key=nameservers site.value=$master;";
2009-12-15 18:55:36 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=maxssh site.value=8;";
$chtabcmds .= "$::XCATROOT/sbin/chtab key=ppcmaxp site.value=64;";
$chtabcmds .= "$::XCATROOT/sbin/chtab key=ppcretry site.value=3;";
$chtabcmds .= "$::XCATROOT/sbin/chtab key=ppctimeout site.value=0;";
2011-11-30 08:26:45 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=powerinterval site.value=0;";
$chtabcmds .= "$::XCATROOT/sbin/chtab key=syspowerinterval site.value=0;";
2009-12-19 14:20:26 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=sharedtftp site.value=1;";
2009-12-15 18:55:36 +00:00
$chtabcmds .=
"$::XCATROOT/sbin/chtab key=SNsyncfiledir site.value=$syncdir;";
2009-09-21 19:12:42 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=tftpdir site.value=$tftpdir;";
$chtabcmds .=
"$::XCATROOT/sbin/chtab key=xcatdport site.value=$xcatport;";
$chtabcmds .=
"$::XCATROOT/sbin/chtab key=xcatiport site.value=$xcatiport;";
2009-12-15 18:55:36 +00:00
$chtabcmds .=
"$::XCATROOT/sbin/chtab key=xcatconfdir site.value=$confdir;";
2008-06-11 18:45:47 +00:00
$chtabcmds .=
2012-11-21 08:54:16 +00:00
"$::XCATROOT/sbin/chtab key=timezone site.value=\"$timezone\";";
2009-11-06 20:27:08 +00:00
2009-12-15 18:55:36 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=useNmapfromMN site.value=no;";
2010-08-12 03:30:31 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=enableASMI site.value=no;";
2010-09-28 15:38:28 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=db2installloc site.value=\/mntdb2;";
2011-03-15 15:51:40 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=databaseloc site.value=\/var\/lib;";
2010-10-28 17:30:40 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=sshbetweennodes site.value=ALLGROUPS;";
2011-05-11 08:03:51 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=dnshandler site.value=ddns;";
2011-11-15 03:11:34 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=vsftp site.value=n;";
2011-07-04 08:58:30 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=cleanupxcatpost site.value=no;";
2012-05-16 12:25:49 +00:00
$chtabcmds .= "$::XCATROOT/sbin/chtab key=dhcplease site.value=43200;";
2009-07-31 14:56:34 +00:00
if ($::osname eq 'AIX')
{
$chtabcmds .=
"$::XCATROOT/sbin/chtab key=useSSHonAIX site.value=yes;";
2011-09-07 06:03:24 +00:00
$chtabcmds .=
"$::XCATROOT/sbin/chtab key=useNFSv4onAIX site.value=no;";
2009-07-31 14:56:34 +00:00
$chtabcmds .=
"$::XCATROOT/sbin/chtab key=consoleondemand site.value=yes;";
}
my $outref = xCAT::Utils->runcmd("$chtabcmds", 0);
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "Could not create site definition.");
2009-07-31 14:56:34 +00:00
}
else
{
2011-12-13 17:03:05 +00:00
verbose("Updated cluster site definition.");
2009-07-31 14:56:34 +00:00
}
}
# create default postscript list in postscripts table
# if it does not exist, or request reset
if ( ((!-r "/etc/xcat/postscripts.sqlite") && (!-r "/etc/xcat/cfgloc"))
|| $::FORCE
|| $::initDB)
{
2009-12-15 18:55:36 +00:00
2012-03-23 15:05:53 +00:00
# For Linux check to see if otherpkgs in the postscripts table
2010-04-27 20:44:09 +00:00
# if it is do not change it, otherwise put in postbootscripts
2009-12-15 18:55:36 +00:00
my $chtabcmds = "";
2012-03-23 15:05:53 +00:00
my $otherpkgsprocessed = 0;
my $otherpkgsexist;
if ($::osname eq 'Linux') {
$otherpkgsexist = &checkotherpkgs;
# 0 = does not exist
# 1 = exists in postscripts
# 2 = exists in postbootscripts
# if otherpkgs does not exist or we are initializing the DB
# put in postbootscripts
if (($otherpkgsexist == 0) || ($::initDB))
{
2009-07-31 14:56:34 +00:00
$chtabcmds =
2009-12-15 18:55:36 +00:00
"$::XCATROOT/sbin/chtab node=xcatdefaults postscripts.postbootscripts='otherpkgs';";
$otherpkgsprocessed = 1;
2012-03-23 15:05:53 +00:00
}
# if already processed otherpkgs or it is in postbootscripts attr
# then don't put otherpkgs in the postscripts attribute
# else it was in postscripts attribute so leave it there.
if (($otherpkgsprocessed == 1) || ($otherpkgsexist == 2))
{
2009-12-15 18:55:36 +00:00
$chtabcmds .=
"$::XCATROOT/sbin/chtab node=xcatdefaults postscripts.postscripts='syslog,remoteshell,syncfiles';";
2012-03-23 15:05:53 +00:00
}
else
{ # put otherpkgs in postscripts attr
2009-12-15 18:55:36 +00:00
$chtabcmds .=
"$::XCATROOT/sbin/chtab node=xcatdefaults postscripts.postscripts='syslog,remoteshell,otherpkgs,syncfiles';";
2012-03-23 15:05:53 +00:00
}
# add servicenode default
$chtabcmds .=
2011-12-13 17:03:05 +00:00
"$::XCATROOT/sbin/chtab node=service postscripts.postscripts='servicenode'";
2012-03-23 15:05:53 +00:00
}
if ($::osname eq 'AIX') { # we don't use otherpkgs on AIX
$chtabcmds .=
"$::XCATROOT/sbin/chtab node=xcatdefaults postscripts.postscripts='syslog,aixremoteshell,syncfiles';";
$chtabcmds .=
2012-08-16 19:08:09 +00:00
"$::XCATROOT/sbin/chtab node=service postscripts.postscripts='servicenode'";
2012-03-23 15:05:53 +00:00
2009-07-31 14:56:34 +00:00
}
my $outref = xCAT::Utils->runcmd("$chtabcmds", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
2009-12-15 18:55:36 +00:00
"Could not create postscripts definition.");
2009-07-31 14:56:34 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
verbose("Created postscripts definition.");
2009-07-31 14:56:34 +00:00
}
}
2011-12-20 10:53:50 +00:00
# create or reset basic policy table definitions
2009-07-31 14:56:34 +00:00
if ( ((!-r "/etc/xcat/policy.sqlite") && (!-r "/etc/xcat/cfgloc"))
|| $::FORCE
|| $::initDB)
{
my $chtabcmds;
if ($::osname eq 'AIX')
{
$chtabcmds =
"$::XCATROOT/sbin/chtab priority=1 policy.name=root policy.rule=allow;";
2010-03-18 16:32:06 +00:00
if (defined($MNname)){
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=1.2 policy.name=$MNname policy.rule=trusted;";
}
2009-07-31 14:56:34 +00:00
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=4.4 policy.commands=getpostscript policy.rule=allow;";
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=4.5 policy.commands=getcredentials policy.rule=allow;";
$chtabcmds .=
2009-12-19 14:20:26 +00:00
"$::XCATROOT/sbin/chtab priority=4.6 policy.commands=syncfiles policy.rule=allow;";
2011-02-22 05:45:52 +00:00
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=2.3 policy.commands=lsxcatd policy.rule=allow;";
2009-07-31 14:56:34 +00:00
}
else # linux
{
$chtabcmds =
"$::XCATROOT/sbin/chtab priority=1 policy.name=root policy.rule=allow;";
2010-03-18 16:32:06 +00:00
if (defined($MNname)){
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=1.2 policy.name=$MNname policy.rule=trusted;";
}
2009-07-31 14:56:34 +00:00
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=2 policy.commands=getbmcconfig policy.rule=allow;";
2010-10-27 16:25:14 +00:00
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=2.3 policy.commands=lsxcatd policy.rule=allow;";
2009-07-31 14:56:34 +00:00
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=3 policy.commands=nextdestiny policy.rule=allow;";
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=4 policy.commands=getdestiny policy.rule=allow;";
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=4.4 policy.commands=getpostscript policy.rule=allow;";
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=4.5 policy.commands=getcredentials policy.rule=allow;";
$chtabcmds .=
2009-12-19 14:20:26 +00:00
"$::XCATROOT/sbin/chtab priority=4.6 policy.commands=syncfiles policy.rule=allow;";
2009-12-15 20:47:25 +00:00
$chtabcmds .=
2009-12-19 14:20:26 +00:00
"$::XCATROOT/sbin/chtab priority=4.7 policy.commands=litefile policy.rule=allow;";
2009-12-15 20:47:25 +00:00
$chtabcmds .=
2009-12-19 14:20:26 +00:00
"$::XCATROOT/sbin/chtab priority=4.8 policy.commands=litetree policy.rule=allow;";
2009-07-31 14:56:34 +00:00
}
my $outref = xCAT::Utils->runcmd("$chtabcmds", 0);
if ($::RUNCMD_RC != 0)
{
2009-12-15 18:55:36 +00:00
xCAT::MsgUtils->message('E', "Could not create policy definition.");
2009-07-31 14:56:34 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
verbose("Created policy definition.");
2009-07-31 14:56:34 +00:00
}
}
# update install processing
if ($::UPDATEINSTALL)
{
2010-03-12 18:38:10 +00:00
# setup Management Node policy to trusted
my $chtabcmds;
$chtabcmds =
2010-10-28 13:42:16 +00:00
"$::XCATROOT/sbin/chtab priority=1.2 policy.name=$MNname policy.rule=trusted;";
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=2.3 policy.commands=lsxcatd policy.rule=allow;";
2010-03-12 18:38:10 +00:00
my $outref = xCAT::Utils->runcmd("$chtabcmds", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
"Could not update policy.name=$hname rule.");
}
else
{
verbose("Updated policy definition for MN.");
}
2010-07-28 12:06:56 +00:00
# add statelite policies on update for Linux
if ($::osname eq 'Linux') {
$chtabcmds =
"$::XCATROOT/sbin/chtab priority=4.7 policy.commands=litefile policy.rule=allow;";
$chtabcmds .=
"$::XCATROOT/sbin/chtab priority=4.8 policy.commands=litetree policy.rule=allow;";
my $outref = xCAT::Utils->runcmd("$chtabcmds", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E', "Could not create statelite policy.");
}
else
{
verbose("Created statelite policy definition.");
}
}
2009-12-15 18:55:36 +00:00
2012-03-23 15:05:53 +00:00
# For Linux check to see if otherpkgs is in the postscripts table
2010-04-27 20:44:09 +00:00
# if it is do not change it, otherwise put in postbootscripts
2009-12-15 18:55:36 +00:00
# 0 = does not exist
# 1 = exists in postscripts
# 2 = exists in postbootscripts
2012-03-23 15:05:53 +00:00
my $otherpkgsexist;
2010-04-27 20:44:09 +00:00
$chtabcmds ="";
2012-03-23 15:05:53 +00:00
if ($::osname eq 'Linux') {
$otherpkgsexist = &checkotherpkgs;
if (($otherpkgsexist == 1) || ($otherpkgsexist == 2)) {
2010-04-27 20:44:09 +00:00
# otherpkgs already in postscripts or in postbootscripts
2012-03-23 15:05:53 +00:00
# just add syncfiles
$chtabcmds = "$::XCATROOT/sbin/chtab node=xcatdefaults postscripts.postscripts+='syncfiles'";
}
else
{ # otherpkgs does not exist
# put in postbootscripts
$chtabcmds = "$::XCATROOT/sbin/chtab node=xcatdefaults postscripts.postbootscripts+='otherpkgs';";
}
} else { # AIX , no otherpkgs just add syncfiles
2010-04-27 20:44:09 +00:00
$chtabcmds = "$::XCATROOT/sbin/chtab node=xcatdefaults postscripts.postscripts+='syncfiles'";
2009-12-15 18:55:36 +00:00
}
2010-04-23 08:35:05 +00:00
2010-04-27 20:44:09 +00:00
if ($chtabcmds ne "") {
my $outref = xCAT::Utils->runcmd("$chtabcmds", 0);
2010-04-23 08:35:05 +00:00
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
2009-12-15 18:55:36 +00:00
"Could not update postscripts definition.");
2010-04-23 08:35:05 +00:00
}
else
{
verbose("Updated postscripts definition.");
}
2009-07-31 14:56:34 +00:00
}
2010-04-27 20:44:09 +00:00
2010-04-23 11:09:06 +00:00
# remove any xcatdefaults node in nodelist
# leave to cleanup from previous bug
my $rmdefault="$::XCATROOT/sbin/chtab -d node=xcatdefaults nodelist";
2010-04-27 20:44:09 +00:00
$outref = xCAT::Utils->runcmd("$rmdefault", 0);
2010-04-23 11:09:06 +00:00
if ($::RUNCMD_RC != 0)
{
2010-04-27 20:44:09 +00:00
xCAT::MsgUtils->message('E',"Could not remove xcatdefaults.");
2010-04-23 11:09:06 +00:00
}
else
{
verbose("Removed xcatdefaults.");
}
2009-07-31 14:56:34 +00:00
2011-05-11 08:03:51 +00:00
# switch from bind.pm to ddns.pm
# give a warning message for the first time
2012-08-09 08:56:01 +00:00
my $cmds = "XCATBYPASS=Y $::XCATROOT/sbin/tabdump site 2>/dev/null |grep dnshandler";
2011-05-11 08:03:51 +00:00
$outref = xCAT::Utils->runcmd("$cmds", -1);
if ($::RUNCMD_RC != 0)
{
# set site.dnshandler
$cmds = "$::XCATROOT/sbin/chtab key=dnshandler site.value=ddns;";
$outref = xCAT::Utils->runcmd("$cmds", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',"Could not set ddns as dnshandler.");
}
}
2011-08-04 07:18:24 +00:00
2011-12-20 10:53:50 +00:00
}
# remove xcatserver,xcatclient
# from the postscripts. They are now called by servicenode
&cleanupPSTable;
2009-07-31 14:56:34 +00:00
} # end initial DB install setup
#-----------------------------------------------------------------------------
2009-12-15 18:55:36 +00:00
=head3 check for otherpkgs
Check to see if other pkgs exists in postscripts table.
If it does not we will be putting it in postbootscripts
2010-04-27 20:44:09 +00:00
return exist_flag
2010-04-23 08:35:05 +00:00
exist_flag = 0 does not exist
exist_flag = 1 exists in postscripts
exist_flag = 2 exists in postbootscripts
2009-12-15 18:55:36 +00:00
=cut
#-----------------------------------------------------------------------------
sub checkotherpkgs
{
my $otherpkgsexist = 0;
my $postscriptstab = xCAT::Table->new('postscripts');
my $attr = "xcatdefaults";
2010-04-27 20:44:09 +00:00
my @values;
2009-12-15 18:55:36 +00:00
if ($postscriptstab)
{
my $ref = $postscriptstab->getAttribs({node => $attr}, 'postscripts');
if ($ref)
{
2010-04-27 20:44:09 +00:00
@values = $ref->{postscripts};
if (grep(/otherpkgs/, @values))
2009-12-15 18:55:36 +00:00
{
$otherpkgsexist = 1;
}
}
if ($otherpkgsexist == 0)
{
# check postbootscripts
2010-04-27 20:44:09 +00:00
my $ref = $postscriptstab->getAttribs({node => $attr}, 'postbootscripts');
2009-12-15 18:55:36 +00:00
if ($ref)
{
2010-04-27 20:44:09 +00:00
@values = $ref->{postscripts};
if (grep(/otherpkgs/, @values))
2009-12-15 18:55:36 +00:00
{
$otherpkgsexist = 2;
}
}
}
}
2010-04-27 20:44:09 +00:00
return $otherpkgsexist;
2009-12-15 18:55:36 +00:00
}
#-----------------------------------------------------------------------------
2009-07-31 14:56:34 +00:00
=head3 genCredentials
Will generate the xCAT credential, if new install or requested to
regenerate.
=cut
#-----------------------------------------------------------------------------
sub genCredentials
{
my $hname = `hostname`;
chomp $hname;
if ((!-d "/etc/xcat/ca") || $::FORCE || $::genCredentials)
{
xCAT::MsgUtils->message(
'I',
2009-10-02 19:19:26 +00:00
"\nSetting up basic certificates. Respond with a \'y\' when prompted.\n"
2009-07-31 14:56:34 +00:00
);
my $cmd =
"echo 'y\ny\ny\ny' |$::XCATROOT/share/xcat/scripts/setup-xcat-ca.sh 'xCAT CA'";
2009-10-02 19:19:26 +00:00
verbose("Running $cmd");
2009-07-31 14:56:34 +00:00
my $rc = system($cmd);
if ($rc >> 8)
{
xCAT::MsgUtils->message('E',
2009-12-15 18:55:36 +00:00
"Could not create xCAT certificate in /etc/xcat/ca.");
2009-07-31 14:56:34 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('I', "Created xCAT certificate.");
2009-07-31 14:56:34 +00:00
}
}
2010-04-23 18:06:29 +00:00
# copy to postscript directory just non-sensitive files
2010-02-24 08:43:40 +00:00
my $cmd = "/bin/rm -rf $::INSTALLDIR/postscripts/ca >/dev/null 2>&1";
2009-07-31 14:56:34 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
2010-10-27 10:38:13 +00:00
$cmd = "/bin/mkdir -m 755 -p $::INSTALLDIR/postscripts/ca";
2010-04-27 20:44:09 +00:00
$outref = xCAT::Utils->runcmd("$cmd", 0);
2009-07-31 14:56:34 +00:00
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
2010-04-23 18:06:29 +00:00
"Could not create $::INSTALLDIR/postscripts/ca directory.");
2008-06-11 18:45:47 +00:00
}
else
{
2010-04-23 18:06:29 +00:00
verbose("Created $::INSTALLDIR/postscripts/ca directory.");
2008-06-11 18:45:47 +00:00
}
2010-04-27 20:44:09 +00:00
$cmd = "/bin/cp -p /etc/xcat/ca/ca-cert.pem $::INSTALLDIR/postscripts/ca/ca-cert.pem";
$outref = xCAT::Utils->runcmd("$cmd", 0);
2008-06-11 18:45:47 +00:00
if ($::RUNCMD_RC != 0)
2008-01-22 18:53:53 +00:00
{
2009-07-31 14:56:34 +00:00
xCAT::MsgUtils->message(
'E',
2010-04-23 18:06:29 +00:00
"$cmd failed"
2009-07-31 14:56:34 +00:00
);
2008-06-11 18:45:47 +00:00
}
else
{
2010-04-23 18:18:15 +00:00
verbose "$cmd succeeded.";
2008-01-22 18:53:53 +00:00
}
2009-07-31 14:56:34 +00:00
if ((!-d "/etc/xcat/cert") || $::FORCE || $::genCredentials)
{
my $cmd =
"echo 'y\ny\ny\ny' |$::XCATROOT/share/xcat/scripts/setup-server-cert.sh $hname";
2009-10-02 19:19:26 +00:00
verbose("Running $cmd");
2009-07-31 14:56:34 +00:00
my $rc = system($cmd);
if ($rc >> 8)
{
xCAT::MsgUtils->message('E',
2009-12-15 18:55:36 +00:00
"Could not create xCAT certificate in /etc/xcat/cert.");
2009-07-31 14:56:34 +00:00
}
else
{
2010-03-23 17:29:35 +00:00
if ($::genCredentials) { # if just generating new credentials
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('I', "Created xCAT certificate.");
2010-02-05 12:57:23 +00:00
my $chtabcmds =
2010-03-23 17:33:27 +00:00
"$::XCATROOT/sbin/chtab priority=1.2 policy.name=$hname policy.rule=trusted;";
2010-02-05 12:57:23 +00:00
my $outref = xCAT::Utils->runcmd("$chtabcmds", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E', "Could not create policy definition.$chtabcmds.");
}
2010-03-23 17:29:35 +00:00
}
2009-07-31 14:56:34 +00:00
}
}
2008-02-18 13:14:29 +00:00
2010-04-23 18:06:29 +00:00
# copy to postscript directory, no longer use cert directory
2010-04-27 20:44:09 +00:00
$cmd = "/bin/rm -rf $::INSTALLDIR/postscripts/cert >/dev/null 2>&1";
$outref = xCAT::Utils->runcmd("$cmd", 0);
2008-06-11 18:45:47 +00:00
2009-07-31 14:56:34 +00:00
if ((!-r "$::root/.xcat/client-key.pem") || $::FORCE || $::genCredentials)
{
2008-01-22 18:53:53 +00:00
2009-07-31 14:56:34 +00:00
my $cmd =
"echo 'y\ny\ny\ny' |$::XCATROOT/share/xcat/scripts/setup-local-client.sh root";
2009-10-02 19:19:26 +00:00
verbose("Running $cmd");
2009-07-31 14:56:34 +00:00
my $rc = system($cmd);
if ($rc >> 8)
{
2009-12-15 18:55:36 +00:00
xCAT::MsgUtils->message('E',
"Could not create xCAT certificate in /.xcat/client-key.pem.");
2009-07-31 14:56:34 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('I', "Created xCAT certificate.");
2009-07-31 14:56:34 +00:00
}
}
# copy to postscript directory
2010-04-27 20:44:09 +00:00
$cmd = "/bin/rm -rf $::INSTALLDIR/postscripts/_xcat >/dev/null 2>&1";
$outref = xCAT::Utils->runcmd("$cmd", 0);
2010-10-27 10:38:13 +00:00
$cmd = "/bin/mkdir -m 755 -p $::INSTALLDIR/postscripts/_xcat";
2010-04-27 20:44:09 +00:00
$outref = xCAT::Utils->runcmd("$cmd", 0);
2009-07-31 14:56:34 +00:00
if ($::RUNCMD_RC != 0)
2008-01-22 18:53:53 +00:00
{
2008-06-11 18:45:47 +00:00
xCAT::MsgUtils->message('E',
2010-02-24 08:43:40 +00:00
"Could not create $::INSTALLDIR/postscripts/_xcat directory.");
2009-07-31 14:56:34 +00:00
}
else
{
2010-02-24 08:43:40 +00:00
verbose("Created $::INSTALLDIR/postscripts/_xcat directory.");
2009-07-31 14:56:34 +00:00
}
2010-04-27 20:44:09 +00:00
$cmd = "/bin/cp -p $::root/.xcat/ca.pem $::INSTALLDIR/postscripts/_xcat/ca.pem";
$outref = xCAT::Utils->runcmd("$cmd", 0);
2009-07-31 14:56:34 +00:00
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message(
'E',
2010-04-23 18:06:29 +00:00
"Could not copy $::root/.xcat/ca.pem to $::INSTALLDIR/postscripts/_xcat directory."
2009-07-31 14:56:34 +00:00
);
2008-06-11 18:45:47 +00:00
}
else
{
2010-04-23 18:18:15 +00:00
verbose "Copied $::root/.xcat/ca.pem to $::INSTALLDIR/postscripts/_xcat directory.";
2008-01-22 18:53:53 +00:00
}
}
2008-06-11 18:45:47 +00:00
2009-07-31 14:56:34 +00:00
#-----------------------------------------------------------------------------
2008-10-09 14:13:56 +00:00
2009-11-27 08:36:35 +00:00
=head3 setupAIXIPMITool
Set AIX IPMI Tool
=cut
2009-12-15 18:55:36 +00:00
2009-11-27 08:36:35 +00:00
#-----------------------------------------------------------------------------
sub setupAIXIPMITool
2009-12-15 18:55:36 +00:00
2009-11-27 08:36:35 +00:00
{
if (!-f "/usr/bin/ipmitool")
{
2010-12-15 14:21:04 +00:00
my $cmd = "ln -sf /opt/freeware/bin/ipmitool /usr/bin/ipmitool";
my $outref = xCAT::Utils->runcmd("$cmd", 0);
2009-11-27 08:36:35 +00:00
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message(
'E',
"Could not ln -sf /opt/freeware/bin/ipmitool /usr/bin/ipmitool."
);
}
else
{
verbose("ln -sf /opt/freeware/bin/ipmitool /usr/bin/ipmitool.");
}
}
}
#-----------------------------------------------------------------------------
2009-07-31 14:56:34 +00:00
#-----------------------------------------------------------------------------
=head3 setupAIXexports
2012-05-22 10:58:07 +00:00
Set AIX exports
2009-07-31 14:56:34 +00:00
=cut
#-----------------------------------------------------------------------------
sub setupAIXexports
2008-01-22 18:53:53 +00:00
2008-11-19 15:22:21 +00:00
{
2012-05-22 10:58:07 +00:00
# check if /install/postscripts is exported
2010-06-01 05:40:46 +00:00
my $lsnfsexpcmd =
"/usr/sbin/lsnfsexp -d $::INSTALLDIR/postscripts 2>&1";
my $outref = xCAT::Utils->runcmd("$lsnfsexpcmd", -1);
if (($::RUNCMD_RC != 0) || ($outref !~ /-vers=3:4/))
2009-04-03 16:08:31 +00:00
{
2009-05-02 21:21:40 +00:00
2010-06-01 05:40:46 +00:00
# if not exported for both NFS version 3 and version 4,
# make sure it is exported with -vers=3:4
2012-05-22 10:58:07 +00:00
my $rmnfsexpcmd = "/usr/sbin/rmnfsexp -d $::INSTALLDIR/postscripts 2>&1";
2010-06-01 05:40:46 +00:00
xCAT::Utils->runcmd("$rmnfsexpcmd", -1);
my $mknfsexpcmd =
2012-05-22 10:58:07 +00:00
"mknfsexp -d $::INSTALLDIR/postscripts '-B' -v '3,4' -t 'ro'";
2010-06-01 05:40:46 +00:00
my $outref2 = xCAT::Utils->runcmd("$mknfsexpcmd", -1);
2009-05-02 21:21:40 +00:00
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
2012-05-22 10:58:07 +00:00
"Could not export directory $::INSTALLDIR/postscripts.");
2009-04-03 16:08:31 +00:00
}
}
2008-11-19 15:22:21 +00:00
}
2009-07-31 14:56:34 +00:00
#-----------------------------------------------------------------------------
=head3 setupLinuxexports
Set Linux exports
=cut
#-----------------------------------------------------------------------------
sub setupLinuxexports
2008-06-11 18:45:47 +00:00
{
2009-07-31 14:56:34 +00:00
my $changed_exports = 0;
2008-06-11 18:45:47 +00:00
2009-07-31 14:56:34 +00:00
#
# add tftpboot to /etc/exports - if needed
#
2010-02-24 08:43:40 +00:00
my $cmd = "/bin/cat /etc/exports | grep '$::TFTPDIR'";
2009-07-31 14:56:34 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", -1);
if ($::RUNCMD_RC != 0)
2008-06-11 18:45:47 +00:00
{
2009-07-31 14:56:34 +00:00
# ok - then add this entry
#SECURITY: this has potential for sharing private host/user keys
my $cmd =
2010-04-01 13:24:20 +00:00
"/bin/echo '$::TFTPDIR *(rw,no_root_squash,sync,no_subtree_check)' >> /etc/exports";
2009-07-31 14:56:34 +00:00
2008-06-11 18:45:47 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
2009-12-15 18:55:36 +00:00
"Could not update the /etc/exports file.");
2008-06-11 18:45:47 +00:00
}
else
{
2010-02-24 08:43:40 +00:00
verbose("Added $::TFTPDIR to the /etc/exports file.");
2009-07-31 14:56:34 +00:00
$changed_exports++;
2008-06-11 18:45:47 +00:00
}
}
2009-07-31 14:56:34 +00:00
#
# add /install to /etc/exports - if needed
#
2010-04-27 20:44:09 +00:00
$cmd = "/bin/cat /etc/exports | grep '$::INSTALLDIR'";
$outref = xCAT::Utils->runcmd("$cmd", -1);
2009-07-31 14:56:34 +00:00
if ($::RUNCMD_RC != 0)
{
# ok - then add this entry
#SECURITY: this has potential for sharing private host/user keys
my $cmd =
2010-04-01 13:24:20 +00:00
"/bin/echo '$::INSTALLDIR *(rw,no_root_squash,sync,no_subtree_check)' >> /etc/exports";
2009-07-31 14:56:34 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
2009-12-15 18:55:36 +00:00
"Could not update the /etc/exports file.");
2009-07-31 14:56:34 +00:00
}
else
{
2010-02-24 08:43:40 +00:00
verbose("Added $::INSTALLDIR to the /etc/exports file.");
2009-07-31 14:56:34 +00:00
$changed_exports++;
}
}
if ($changed_exports)
{
# restart nfs
my $cmd = "/sbin/service nfs restart";
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "Could not restart NFS.");
2009-07-31 14:56:34 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('I', "NFS has been restarted.");
2009-07-31 14:56:34 +00:00
}
2010-04-27 20:44:09 +00:00
$cmd = "/sbin/chkconfig nfs on";
$outref = xCAT::Utils->runcmd("$cmd", 0);
2009-07-31 14:56:34 +00:00
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "Could not enable NFS.");
2009-07-31 14:56:34 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
verbose("NFS has been enabled.");
2009-07-31 14:56:34 +00:00
}
2010-04-27 20:44:09 +00:00
$cmd = "/usr/sbin/exportfs -a";
$outref = xCAT::Utils->runcmd("$cmd", 0);
2009-07-31 14:56:34 +00:00
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "Error with $cmd.");
2009-07-31 14:56:34 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
verbose("Ran $cmd.");
2009-07-31 14:56:34 +00:00
}
}
}
#-----------------------------------------------------------------------------
=head3 mknb
creates a network boot root image on Linux
=cut
#-----------------------------------------------------------------------------
sub mknb
{
2009-03-26 22:38:47 +00:00
if ($::arch eq "x86_64" || $::arch eq "x86")
{
2012-04-30 16:24:11 +00:00
foreach my $ar (qw(x86_64))
2009-05-02 21:21:40 +00:00
{
2012-05-16 12:25:49 +00:00
my $cmd = "XCATBYPASS=Y $::XCATROOT/sbin/mknb $ar";
2009-05-02 21:21:40 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
if ($::RUNCMD_RC != 0)
{
xCAT::MsgUtils->message('E',
2009-12-15 18:55:36 +00:00
"The mknb $ar command returned error: $::RUNCMD_RC.");
2009-05-02 21:21:40 +00:00
}
else
{
xCAT::MsgUtils->message('I',
2009-12-15 18:55:36 +00:00
"The mknb $ar command completed successfully.");
2009-05-02 21:21:40 +00:00
}
}
2008-06-11 18:45:47 +00:00
}
2009-07-31 14:56:34 +00:00
}
#-----------------------------------------------------------------------------
=head3 makenetworks
2011-04-15 14:17:42 +00:00
Runs makenetworks on AIX and Linux
2009-07-31 14:56:34 +00:00
=cut
#-----------------------------------------------------------------------------
sub makenetworks
{
2008-06-11 18:45:47 +00:00
# run makenetworks
2012-05-16 12:25:49 +00:00
my $cmd = "XCATBYPASS=Y $::XCATROOT/sbin/makenetworks";
2008-01-22 18:53:53 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
2008-06-11 18:45:47 +00:00
if ($::RUNCMD_RC != 0)
{
2011-07-01 14:58:53 +00:00
verbose("The makenetworks command returned error: $::RUNCMD_RC");
2008-06-11 18:45:47 +00:00
}
else
{
2011-07-01 14:58:53 +00:00
verbose("The makenetworks command was run with no error.");
2008-06-11 18:45:47 +00:00
}
2011-04-15 14:17:42 +00:00
}
#-----------------------------------------------------------------------------
=head3 setuphttp
initializes http on Linux
=cut
#-----------------------------------------------------------------------------
sub setuphttp
{
my $cmd;
2008-06-11 18:45:47 +00:00
# restart httpd
2009-05-02 21:21:40 +00:00
if (-e "/etc/init.d/apache2")
{ #for sles
2009-02-16 10:33:01 +00:00
$cmd = "/etc/init.d/apache2 stop; /etc/init.d/apache2 start";
2009-05-02 21:21:40 +00:00
}
else
{
2009-02-16 10:33:01 +00:00
$cmd = "/etc/init.d/httpd stop; /etc/init.d/httpd start";
}
2010-07-29 11:16:03 +00:00
2011-04-15 14:17:42 +00:00
my $outref = xCAT::Utils->runcmd("$cmd", 0);
2008-06-11 18:45:47 +00:00
if ($::RUNCMD_RC != 0)
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "Could not restart httpd.");
2008-06-11 18:45:47 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('I', "httpd has been restarted.");
2008-06-11 18:45:47 +00:00
}
# enable httpd
2009-05-02 21:21:40 +00:00
if (-e "/etc/init.d/apache2")
{ #for sles
2009-02-16 10:33:01 +00:00
$cmd = "/sbin/chkconfig apache2 on";
2009-05-02 21:21:40 +00:00
}
else
{
2009-02-16 10:33:01 +00:00
$cmd = "/sbin/chkconfig httpd on";
}
2010-04-27 20:44:09 +00:00
$outref = xCAT::Utils->runcmd("$cmd", 0);
2008-06-11 18:45:47 +00:00
if ($::RUNCMD_RC != 0)
2008-01-22 18:53:53 +00:00
{
2009-10-02 19:19:26 +00:00
xCAT::MsgUtils->message('E', "Could not enable httpd.");
2008-06-11 18:45:47 +00:00
}
else
{
2009-10-02 19:19:26 +00:00
verbose("httpd has been enabled.");
2008-01-22 18:53:53 +00:00
}
}
2011-12-20 10:53:50 +00:00
#-----------------------------------------------------------------------------
=head3 cleanupPSTable
Any line in the postscripts table that has the following
entry will have xcatserver,xcatclient remove because they
are not called by servicenode
..."servicenode,xcatserver,xcatclient.."...
=cut
#-----------------------------------------------------------------------------
sub cleanupPSTable
{
my $rc=0;
my $tab;
if ($tab = xCAT::Table->new("postscripts")) {
my @tableentries = $tab->getAllAttribs('node','postscripts');
foreach my $entry (@tableentries) {
2012-05-17 17:04:36 +00:00
my $changeit=0;
2011-12-20 10:53:50 +00:00
my $node=$entry->{'node'};
my $pslist=$entry->{'postscripts'};
if ($pslist) {
my $servicenode=0;
2012-01-03 19:45:17 +00:00
my $newpslist ="\'";
2011-12-20 10:53:50 +00:00
my @ps= split(",", $pslist);
# now check is servicenode and xcatclient and/or xcatserver in the list
foreach my $pscript (@ps) {
2012-01-03 19:45:17 +00:00
if ($pscript =~ /(^|\|)servicenode($|\|)/i) { # found servicenode ps
2011-12-20 10:53:50 +00:00
$newpslist .=$pscript;
$newpslist .=",";
$servicenode=1;
} else{ # no service node just put entry on new table
if ($servicenode == 0) {
$newpslist .=$pscript;
$newpslist .=",";
} else { # servicenode found, do not keep xcatserver/xcatclient
2012-01-03 19:45:17 +00:00
if (($pscript =~ /(^|\|)xcatserver($|\|)/i) ||($pscript =~ /(^|\|)xcatclient($|\|)/i)) {
2012-05-17 17:04:36 +00:00
$changeit=1; # had to remove xcatserver/xcatclient
2011-12-20 10:53:50 +00:00
next;
} else {
$newpslist .=$pscript;
$newpslist .=",";
}
}
}
}
chop $newpslist;
2012-01-03 19:45:17 +00:00
$newpslist .="\'";
2012-05-17 17:04:36 +00:00
if ($changeit == 1) { # we had to modify the line
my $chtabcmds .=
"$::XCATROOT/sbin/chtab node=$node postscripts.postscripts=$newpslist;";
my $outref = xCAT::Utils->runcmd("$chtabcmds", 0);
if ($::RUNCMD_RC != 0)
{
2011-12-20 10:53:50 +00:00
xCAT::MsgUtils->message('E',
"Could not modify postscripts definition for $node.");
2012-05-17 17:04:36 +00:00
}
}
2011-12-20 10:53:50 +00:00
}
}
}
else
{
xCAT::MsgUtils->message("E", " Could not open the postscripts table\n");
return 1;
}
return $rc
}