#!/usr/bin/perl # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html #egan@us.ibm.com #(C)IBM Corp # BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; } use lib "$::XCATROOT/lib/perl"; use File::Basename; use Getopt::Long; use xCAT::MsgUtils; use xCAT::Utils; #----------------------------------------------------------------------------- =head1 init_xcatdb This routine initializes a new database with the default values in the site table and necessary credentials for the xcatd daemon to run. =cut #----------------------------------------------------------------------------- my $rc = &init_db; exit $rc; #----------------------------------------------------------------------------- =head3 init_db =cut #----------------------------------------------------------------------------- sub init_db { my $rc = 0; my @timezone = `grep ZONE /etc/sysconfig/clock|cut -d= -f 2`; my $hostname = `hostname`; my $masterhost = `getent hosts $hostname`; my ($masterip, $mastername) = split ' ', $masterhost; my $domain = `hostname -d`; my @cmd = ( "chtab key=xcatdport site.value=3001", "chtab key=master site.value=$masterip", "chtab key=tftpdir site.value=/tftpboot", "chtab key=domain site.value=$domain", "chtab key=timezone site.value=$timezone[0]", "chtab key=installdir site.value=/install", "chtab priority=1 policy.name=root policy.rule=allow", "chtab priority=2 policy.commands=getbmcconfig policy.rule=allow", "chtab priority=3 policy.commands=nextdestiny policy.rule=allow", "chtab priority=4 policy.commands=getdestiny policy.rule=allow" ); foreach $cmd (@cmd) { my @output = xCAT::Utils->runcmd($cmd, 0); if ($::RUNCMD_RC != 0) { xCAT::MsgUtils->message("E", "Error from $cmd, @output"); } } # build /etc/xcat/cfgloc my @cfg; my $cfg2; my $dbinfo; my $configfile = "/etc/sysconfig/xcat"; if (-e ($configfile)) { open(CFGFILE, "<$configfile") or xCAT::MsgUtils->message( 'S', "Cannot open $configfile for DB access. Please create using information in the xCAT 2.0 Cookbook ( Setting up postgresql) and rerun this script.\n" ); foreach my $line () { if (grep /XCATCFG/, $line) { @cfg = split /XCATCFG=/, $line; @cfg2 = split /'/, $cfg[1]; chomp $cfg2[1]; $dbinfo = $cfg2[1]; close CFGFILE; last; } } if ($dbinfo) { `echo "$dbinfo" > /etc/xcat/cfgloc`; chmod 0600,"/etc/xcat/cfgloc"; } else { xCAT::MsgUtils->message("E", "The contents of $configfile is invalid\n"); } } else { xCAT::MsgUtils->message( "E", "$configfile does not exist, need to create and rerun the script\n" ); } $cmd = "service xcatd restart"; my @output = xCAT::Utils->runcmd($cmd, 0); if ($::RUNCMD_RC != 0) { xCAT::MsgUtils->message("E", "Error from $cmd, @output"); } return $rc; }