2013-06-30 04:22:22 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
# This script is used to configure the mics on the host.
|
|
|
|
# This script is run by xdsh from MN/SN to the host
|
|
|
|
# parameters
|
|
|
|
# -m xcatmaster
|
|
|
|
# -p the path of the mic configuration file. Generally, it's /tftpboot/xcat/miccfg/miccfg.hostname
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use IO::Socket;
|
|
|
|
|
|
|
|
use File::Path;
|
|
|
|
use File::Copy;
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
# enable the autoflush of stdout
|
|
|
|
select STDOUT;
|
|
|
|
$| = 1;
|
|
|
|
|
|
|
|
my $tmppath = "/tmp/mictmp";
|
|
|
|
my $logpath = "/var/log/xcat/";
|
|
|
|
my $logfile = "$logpath/configmic.log";
|
2013-11-03 14:36:55 +00:00
|
|
|
my $micmnt = "/var/mpss/mnt";
|
2013-06-30 04:22:22 +00:00
|
|
|
|
|
|
|
mkpath $tmppath;
|
|
|
|
mkpath $micmnt;
|
|
|
|
#open the log file
|
|
|
|
open (LOG, ">>$logfile") or die "Error: cannot open $logfile\n";
|
|
|
|
print LOG "\n\n====================================================\nStart mic configuratoin: ".`date`."\n";
|
|
|
|
|
|
|
|
my ($master, $cfgpath);
|
|
|
|
GetOptions ('m=s'=>\$master, 'p=s'=>\$cfgpath);
|
|
|
|
unless ($master && $cfgpath) {
|
|
|
|
outputmsg("Error: the -m master and -p path arguments must be specified for configmic.\n", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
# get the correct host name for the host
|
2013-08-08 17:00:37 +00:00
|
|
|
my ($nodename, $nodename_short);
|
2013-06-30 04:22:22 +00:00
|
|
|
my $masterip = `getent hosts $master | awk {'print \$1'}`;
|
2013-08-08 17:00:37 +00:00
|
|
|
if ($masterip) {
|
|
|
|
chomp($masterip);
|
|
|
|
my $myip = `ip route get $masterip| head -n 1 | sed 's/^.*src//g' | awk {'print \$1'}`;
|
|
|
|
if ($myip) {
|
|
|
|
my $myipinfo =`getent hosts $myip`;
|
|
|
|
|
|
|
|
if ($myipinfo && $myipinfo =~ /([^\s]+)\s+([^\s]+)\s+([^\s]+)/) {
|
|
|
|
my $n1 = $2;
|
|
|
|
my $n2 = $3;
|
|
|
|
if (length($n1) > length($n2)) {
|
|
|
|
$nodename_short = $n2;
|
|
|
|
} else {
|
|
|
|
$nodename = $n1;
|
|
|
|
}
|
|
|
|
} elsif ($myipinfo && $myipinfo =~ /([^\s]+)\s+([^\s]+)/) {
|
|
|
|
$nodename_short = $2;
|
|
|
|
}
|
2013-06-30 04:22:22 +00:00
|
|
|
}
|
2013-08-08 17:00:37 +00:00
|
|
|
}
|
|
|
|
unless ($nodename) {
|
|
|
|
$nodename = `hostname`;
|
|
|
|
chomp($nodename);
|
|
|
|
}
|
|
|
|
unless ($nodename_short) {
|
|
|
|
$nodename_short = `hostname -s`;
|
|
|
|
chomp($nodename_short);
|
2013-06-30 04:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# download the mic configuration file from master
|
2013-08-08 17:00:37 +00:00
|
|
|
my $cmd = "wget -N --waitretry=10 --random-wait -T 60 http://$master/$cfgpath/miccfg.$nodename_short -P $tmppath";
|
|
|
|
my ($rc, $output) = runsyscmd ($cmd);
|
|
|
|
if ($rc) {
|
|
|
|
$cmd = "wget -N --waitretry=10 --random-wait -T 60 http://$master/$cfgpath/miccfg.$nodename -P $tmppath";
|
|
|
|
runsyscmd ($cmd, "Error: failed to download mic configuration file from $master\n", 3);
|
|
|
|
}
|
2013-06-30 04:22:22 +00:00
|
|
|
|
|
|
|
unless (-r "$tmppath/miccfg.$nodename") {
|
|
|
|
runsyscmd ("Error: cannot get the mic configuration file from http://$master/$cfgpath/miccfg.$nodename\n", 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
# parse the configuration file
|
|
|
|
unless (open (CFGFILE, "<$tmppath/miccfg.$nodename")) {
|
|
|
|
runsyscmd ("Error: cannot open $tmppath/miccfg.$nodename\n", 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
# the configureation file should have the following format
|
|
|
|
#miclist=mic0
|
|
|
|
#0:ip=10.10.10.1|br=mybr0|name=host1-mic0|onboot=yes|vlog=no
|
|
|
|
#imgpath=/install/mpss3.1
|
|
|
|
#overlay=ol1
|
|
|
|
|
|
|
|
my %miccfg;
|
|
|
|
my $miclist;
|
|
|
|
my $overlay;
|
|
|
|
my $ospath;
|
2013-11-03 14:36:55 +00:00
|
|
|
my $brgname;
|
|
|
|
my $brgip;
|
|
|
|
my $brgtype;
|
2013-06-30 04:22:22 +00:00
|
|
|
while (<CFGFILE>) {
|
|
|
|
if (/(\d+):(.*)/) {
|
|
|
|
my $deviceid = $1;
|
|
|
|
my @params = split (/\|/, $2);
|
|
|
|
foreach (@params) {
|
2013-11-06 12:08:10 +00:00
|
|
|
my ($n, $v) = split (/=/, $_, 2);
|
2013-06-30 04:22:22 +00:00
|
|
|
$miccfg{$deviceid}{$n} = $v;
|
2013-11-03 14:36:55 +00:00
|
|
|
if ($n eq 'br') {
|
|
|
|
$brgname = $v;
|
|
|
|
}
|
2013-06-30 04:22:22 +00:00
|
|
|
}
|
|
|
|
} elsif (/^miclist=(.*)/) {
|
|
|
|
$miclist = $1;
|
|
|
|
} elsif (/^overlay=(.*)/) {
|
|
|
|
$overlay = $1;
|
|
|
|
} elsif (/^imgpath=(.*)/) {
|
2013-11-03 14:36:55 +00:00
|
|
|
$ospath = $1;
|
|
|
|
} elsif (/^brgip=(.*)/) {
|
|
|
|
$brgip = $1;
|
|
|
|
} elsif (/^brgtype=(.*)/) {
|
|
|
|
$brgtype = $1;
|
|
|
|
} elsif (/^micmount=(.+)/) {
|
|
|
|
if ($1 =~ /(.+):(.+)/) {
|
|
|
|
$miccfg{'micmount'}{$1} = $2;
|
|
|
|
}
|
2013-06-30 04:22:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close (CFGFILE);
|
|
|
|
|
|
|
|
$miclist =~ s/,/ /g;
|
|
|
|
|
|
|
|
# add the mount entry for mounting of root fs from master to /etc/fstab
|
2013-11-03 14:36:55 +00:00
|
|
|
# e.g. mount $master:/install/mpss3 /var/mpss/mnt
|
|
|
|
$cmd = "grep \'$master:$ospath \' $micmnt /etc/fstab ";
|
2013-06-30 04:22:22 +00:00
|
|
|
($rc, $output) = runsyscmd ($cmd);
|
|
|
|
if ($rc) {
|
|
|
|
# not found the exact mount entry
|
|
|
|
$cmd = "grep $micmnt /etc/fstab";
|
|
|
|
($rc, $output) = runsyscmd ($cmd);
|
|
|
|
if (!$rc) {
|
|
|
|
# found the mount to $micmnt with another master or directory, remove the entry and umount it
|
|
|
|
my $trans = $micmnt;
|
|
|
|
$trans =~ s/\//\\\//g;
|
|
|
|
$cmd = "sed \"/$trans/d\" /etc/fstab > $tmppath/fstab.tmp";
|
|
|
|
runsyscmd ($cmd, "Error: failed to configure fstab.\n", 6);
|
|
|
|
copy ("$tmppath/fstab.tmp", "/etc/fstab");
|
|
|
|
$cmd = "umount -l -f $micmnt";
|
|
|
|
runsyscmd ($cmd, "Error: failed to run umount -l -f $micmnt\n", 7);
|
|
|
|
}
|
|
|
|
$cmd = "echo \"$master:$ospath $micmnt nfs timeo=14,intr 1 2\" >>/etc/fstab";
|
|
|
|
runsyscmd ($cmd);
|
|
|
|
$cmd = "mount -a";
|
|
|
|
runsyscmd ($cmd);
|
2013-07-11 06:45:27 +00:00
|
|
|
} else {
|
|
|
|
# run mount -a anyway
|
|
|
|
$cmd = "mount -a";
|
|
|
|
runsyscmd ($cmd);
|
2013-06-30 04:22:22 +00:00
|
|
|
}
|
|
|
|
|
2013-11-03 14:36:55 +00:00
|
|
|
# the dir structure in mount opint 'mnt'
|
|
|
|
# |--mnt
|
|
|
|
# | `--system (files for system boot)
|
|
|
|
# | |--common.filelist
|
|
|
|
# | `--common
|
|
|
|
# | `--overlay
|
|
|
|
# | `--overlay
|
|
|
|
# | `--rpm
|
|
|
|
# | `--simple
|
|
|
|
# | |--simple.cfg (the file must be multiple lines of 'a->b' format; 'a' is dir name in simple/, 'b' is the path on mic for 'a'
|
2013-11-21 10:17:23 +00:00
|
|
|
# | `--package (2.8.3) / rootimg (2.8.4 and later)
|
2013-11-03 14:36:55 +00:00
|
|
|
# | |--the base file for fs
|
|
|
|
# | `--opt/mic
|
|
|
|
# | |--yy.filelist
|
|
|
|
# | `--yy
|
|
|
|
# | |--xx.filelist
|
|
|
|
# | `--xx
|
|
|
|
|
2013-06-30 04:22:22 +00:00
|
|
|
# make sure the remote files are accessable
|
2013-11-03 14:36:55 +00:00
|
|
|
unless (-r "$micmnt/common.filelist") {
|
|
|
|
outputmsg("Error: cannot access the $micmnt/common.filelist\n", 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
# initialize mic card if it has not been
|
|
|
|
if (! -f "/etc/mpss/default.conf") {
|
|
|
|
$cmd = "micctrl --initdefaults";
|
|
|
|
runsyscmd ($cmd, "Error: failed to initiate the mic configuration file.\n", 200)
|
2013-06-30 04:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# start to configure the mic
|
|
|
|
# stop the mpss service first
|
|
|
|
$cmd = "service mpss stop";
|
|
|
|
runsyscmd ($cmd, "Error: failed to stop mpss service.\n", 100);
|
|
|
|
|
|
|
|
# make sute the mpss has been stopped
|
|
|
|
my $i = 5;
|
|
|
|
while ($i > 0) {
|
|
|
|
$cmd = "service mpss status";
|
|
|
|
($rc, $output) = runsyscmd ($cmd);
|
|
|
|
if (grep /mpss is stopped/, @$output) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
sleep 2;
|
|
|
|
$i--;
|
|
|
|
}
|
|
|
|
|
2013-11-03 14:36:55 +00:00
|
|
|
# remove the mic configuration files and source files for ramfs, them will be recreated base on setting
|
|
|
|
unlink ("/etc/mpss/default.conf");
|
2013-06-30 04:22:22 +00:00
|
|
|
foreach my $mic (split (/ /, $miclist)) {
|
2013-11-03 14:36:55 +00:00
|
|
|
unlink ("/etc/mpss/$mic.conf");
|
|
|
|
unlink ("/var/mpss/$mic.filelist");
|
|
|
|
rmtree ("/var/mpss/$mic");
|
2013-06-30 04:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# reset the configuration to default
|
|
|
|
$cmd = "micctrl --initdefaults $miclist";
|
|
|
|
runsyscmd ($cmd, "Error: failed to initiate the mic devices.\n", 200);
|
|
|
|
|
|
|
|
# configure the base dir
|
2013-11-03 14:36:55 +00:00
|
|
|
#$cmd = "micctrl --basedir=/opt/intel/mic/mnt/opt/intel/mic/filesystem/base --list=/opt/intel/mic/mnt/opt/intel/mic/filesystem/base.filelist $miclist";
|
|
|
|
#runsyscmd ($cmd, "Error: failed to change the base dir for mic file system..\n", 101);
|
2013-06-30 04:22:22 +00:00
|
|
|
|
|
|
|
# configure the commondir
|
2013-11-03 14:36:55 +00:00
|
|
|
$cmd = "micctrl --commondir=$micmnt/common --list=$micmnt/common.filelist $miclist";
|
|
|
|
runsyscmd ($cmd, "Error: failed to set the common dir for mic file system.\n", 102);
|
2013-06-30 04:22:22 +00:00
|
|
|
|
2013-11-03 14:36:55 +00:00
|
|
|
# configure the overlay file system
|
2013-06-30 04:22:22 +00:00
|
|
|
my @ols = split (/,/, $overlay);
|
|
|
|
foreach (@ols) {
|
2013-11-03 14:36:55 +00:00
|
|
|
if (/^filelist:(.+)/) {
|
|
|
|
$cmd = "micctrl --overlay=Filelist --source=$micmnt/overlay/$1/ --target=$micmnt/overlay/$1.filelist --state=on $miclist";
|
2013-11-21 10:17:23 +00:00
|
|
|
} elsif (/^ofilelist:(.+)/) { # for 2.8.4 and later
|
|
|
|
$cmd = "micctrl --overlay=Filelist --source=$micmnt/overlay/rootimg/ --target=$micmnt/overlay/rootimg/opt/mic/$1.filelist --state=on $miclist";
|
|
|
|
} elsif (/^pfilelist:(.+)/) { # only for 2.8.3
|
2013-11-03 14:36:55 +00:00
|
|
|
$cmd = "micctrl --overlay=Filelist --source=$micmnt/overlay/package/ --target=$micmnt/overlay/package/opt/mic/$1.filelist --state=on $miclist";
|
|
|
|
} elsif (/^rpm:(.+)/) {
|
|
|
|
$cmd = "micctrl --overlay=RPM --source=$micmnt/overlay/rpm/ --state=on $miclist";
|
|
|
|
} elsif (/^simple:(.+)->(.+)/) {
|
|
|
|
$cmd = "micctrl --overlay=Simple --source=$micmnt/overlay/simple/$1 --target=$2 --state=on $miclist";
|
|
|
|
}
|
|
|
|
|
|
|
|
runsyscmd ($cmd, "Error: failed to set the overlay dir for mic file system.\n", 103);
|
|
|
|
}
|
|
|
|
|
|
|
|
# configure bridge for mic
|
|
|
|
my ($netbit, $brc, $mtu);
|
|
|
|
if ($brgtype && $brgtype =~ /Internal/i) {
|
|
|
|
$cmd = "micctrl --addbridge=$brgname --type=Internal --ip=$brgip";
|
|
|
|
runsyscmd ($cmd, "Error: failed to add bridge for mic.\n", 111);
|
|
|
|
} else {
|
|
|
|
# for External bridge, it must has been set up correctly
|
|
|
|
# get the ip of the bridge
|
|
|
|
$cmd = "ip -4 addr show";
|
|
|
|
($rc, $output) = runsyscmd ($cmd);
|
|
|
|
$cmd = "ip -4 route show";
|
|
|
|
my ($rc2, $output2) = runsyscmd ($cmd);
|
|
|
|
foreach (@$output) {
|
|
|
|
if (/inet\s+([\d\.]+)\/(\d+)\s+brd\s+([\d\.]+) scope global $brgname/) {
|
|
|
|
$brgip = $1;
|
|
|
|
$netbit = $2;
|
|
|
|
$brc = $3;
|
|
|
|
last;
|
|
|
|
} elsif (/\d+:\s+$brgname:.*mtu\s+(\d+)/) {
|
|
|
|
$mtu = $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unless ($brgip && $netbit && $brc) {
|
|
|
|
outputmsg("Error: failed to get ip for the bridge $brgname.\n", 110);
|
|
|
|
}
|
|
|
|
|
|
|
|
# add the bridge to mic configuration
|
|
|
|
# since the micctrl --addbridge=<brgname> --type=external --ip=<ip of brg> --netbits=8 does not
|
|
|
|
# work with '--netbis=8', the bridge configuration has been done by changing cfg file directly.
|
|
|
|
#$cmd = "echo \"Bridge $brg External $brip $netbit $mtu\" >> /etc/sysconfig/mic/default.conf";
|
|
|
|
#runsyscmd ($cmd);
|
|
|
|
$cmd = "micctrl --addbridge=$brgname --type=external --ip=$brgip --netbits=$netbit --mtu=$mtu";
|
|
|
|
runsyscmd ($cmd, "Error: failed to add bridge for mic.\n", 111);
|
2013-06-30 04:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# do the mic specific configuration
|
|
|
|
foreach my $micid (keys %miccfg) {
|
2013-11-03 14:36:55 +00:00
|
|
|
if ($micid !~ /^\d*$/) {
|
|
|
|
# not mic specific, return
|
|
|
|
next;
|
|
|
|
}
|
2013-06-30 04:22:22 +00:00
|
|
|
my $micname = $miccfg{$micid}{'name'};
|
|
|
|
# set the boot device to be staticramfs so that the osimage don't need to generated for every boot
|
2013-11-03 14:36:55 +00:00
|
|
|
#$cmd = "micctrl --rootdev=StaticRamFS --target=/opt/intel/mic/filesystem/$micname.image mic$micid";
|
|
|
|
#runsyscmd ($cmd, "Error: failed to set root image for mic.\n", 104);
|
2013-06-30 04:22:22 +00:00
|
|
|
|
|
|
|
# set the linux kernel location
|
2013-11-03 14:36:55 +00:00
|
|
|
#$cmd = "micctrl --osimage=$micmnt/lib/firmware/mic/uos.img mic$micid";
|
|
|
|
#runsyscmd ($cmd, "Error: failed to linux kernle location for mic.\n", 105);
|
2013-06-30 04:22:22 +00:00
|
|
|
|
|
|
|
# set the autoboot
|
|
|
|
if ($miccfg{$micid}{'onboot'} =~ /no/i) {
|
|
|
|
$cmd = "micctrl --autoboot=no mic$micid";
|
2013-11-06 12:08:10 +00:00
|
|
|
runsyscmd ($cmd, "Error: failed to set the autoboot for mic.\n", 106);
|
2013-06-30 04:22:22 +00:00
|
|
|
} elsif($miccfg{$micid}{'onboot'} =~ /yes/i) {
|
|
|
|
$cmd = "micctrl --autoboot=yes mic$micid";
|
2013-11-06 12:08:10 +00:00
|
|
|
runsyscmd ($cmd, "Error: failed to set the autoboot for mic.\n", 106);
|
2013-06-30 04:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# set the hostname
|
2013-11-03 14:36:55 +00:00
|
|
|
$cmd = "sed \"s/Hostname .*/Hostname \"$micname\"/\" /etc/mpss/mic$micid.conf > $tmppath/mic$micid.conf";
|
2013-06-30 04:22:22 +00:00
|
|
|
runsyscmd ($cmd, "Error: failed to set hostname for mic.\n", 107);
|
2013-11-03 14:36:55 +00:00
|
|
|
copy ("$tmppath/mic$micid.conf", "/etc/mpss/mic$micid.conf");
|
2013-06-30 04:22:22 +00:00
|
|
|
|
|
|
|
# configure the Verbose log
|
|
|
|
if ($miccfg{$micid}{'vlog'} =~ /yes/i) {
|
2013-11-03 14:36:55 +00:00
|
|
|
$cmd = "sed \"s/VerboseLogging .*/VerboseLogging \"Enabled\"/\" /etc/mpss/mic$micid.conf > $tmppath/mic$micid.conf";
|
2013-06-30 04:22:22 +00:00
|
|
|
runsyscmd ($cmd, "Error: failed to set Verbose log for mic.\n", 108);
|
2013-11-03 14:36:55 +00:00
|
|
|
copy ("$tmppath/mic$micid.conf", "/etc/mpss/mic$micid.conf");
|
2013-06-30 04:22:22 +00:00
|
|
|
}
|
|
|
|
|
2013-11-06 12:08:10 +00:00
|
|
|
# configure the power management
|
|
|
|
if (defined ($miccfg{$micid}{'powermgt'})) {
|
|
|
|
$cmd = "micctrl --pm=set ";
|
|
|
|
foreach my $item (split (/!/, $miccfg{$micid}{'powermgt'})) {
|
|
|
|
$cmd .= " --$item ";
|
|
|
|
}
|
|
|
|
$cmd .= " mic$micid";
|
|
|
|
runsyscmd ($cmd, "Error: failed to set power management for mic.\n", 109);
|
|
|
|
}
|
|
|
|
|
2013-11-03 14:36:55 +00:00
|
|
|
# configure network for each mic
|
|
|
|
$cmd = "micctrl --network=static --bridge=".$miccfg{$micid}{br}." --ip=".$miccfg{$micid}{ip}." mic$micid";
|
|
|
|
runsyscmd ($cmd, "Error: failed to generate IP configuration for mic.\n", 104);
|
2013-06-30 04:22:22 +00:00
|
|
|
|
2013-11-03 14:36:55 +00:00
|
|
|
# configure nfs mount for each mic
|
|
|
|
foreach my $msrc (keys %{$miccfg{'micmount'}}) {
|
2013-11-06 12:08:10 +00:00
|
|
|
my $mntsrc;
|
|
|
|
if (defined $miccfg{$micid}{'statemnt'}) {
|
|
|
|
if ($miccfg{$micid}{'statemnt'} =~ /:/) {
|
|
|
|
# for 'statemnt' is a nfs server plus dir like 192.168.1:/nfs
|
|
|
|
$mntsrc = $miccfg{$micid}{'statemnt'}."/$msrc";
|
|
|
|
} else {
|
|
|
|
# for 'statemnt' is a nfs server ip 192.168.0.1
|
|
|
|
$mntsrc = $miccfg{$micid}{'statemnt'}.":/$msrc";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$mntsrc = "$brgip:/$msrc";
|
|
|
|
}
|
|
|
|
$cmd = "micctrl --addnfs=$mntsrc --dir=$miccfg{micmount}{$msrc} mic$micid";
|
2013-11-03 14:36:55 +00:00
|
|
|
runsyscmd ($cmd, "Error: failed to add nfs mount for mic.\n", 104);
|
2013-11-06 12:08:10 +00:00
|
|
|
|
|
|
|
# since there's a bug that nfsserver cannot be set, just manully change it
|
|
|
|
if ($mntsrc =~ /^(.+):/) {
|
|
|
|
if ($1 ne $brgip) {
|
|
|
|
$cmd = "sed -i \'s/$brgip/$1/g\' /var/mpss/mic$micid/etc/fstab";
|
|
|
|
runsyscmd ($cmd, "Error: failed to hack nfs mount for mic.\n", 104);
|
|
|
|
}
|
|
|
|
}
|
2013-06-30 04:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# take the configuration to effect
|
|
|
|
$cmd = "micctrl --resetconfig mic$micid";
|
|
|
|
runsyscmd ($cmd, "Error: failed to spread the configuration.\n", 201);
|
|
|
|
|
2013-11-03 14:36:55 +00:00
|
|
|
# back up the /etc/passwd and /etc/shadow which generated by 'micctrl --initdefaults'
|
|
|
|
system ("/bin/cp -rf /var/mpss/mic$micid/etc/passwd /tmp/mictmp/passwd");
|
|
|
|
system ("/bin/cp -rf /var/mpss/mic$micid/etc/shadow /tmp/mictmp/shadow");
|
2013-06-30 04:22:22 +00:00
|
|
|
|
|
|
|
# copy the system files which generated by genimage to the micdir
|
|
|
|
# e.g. /etc/hosts /etc/passwd ...
|
2013-11-03 14:36:55 +00:00
|
|
|
my $src = "$micmnt/system/*";
|
|
|
|
my $dst = "/var/mpss/mic$micid";
|
|
|
|
|
2013-06-30 04:22:22 +00:00
|
|
|
$cmd = "/bin/cp -rf $src $dst";
|
|
|
|
runsyscmd ($cmd, "Error: failed to copy the overlay dir.\n", 300);
|
|
|
|
|
2013-11-03 14:36:55 +00:00
|
|
|
# append /etc/passwd and /etc/shadow which generated by 'micctrl --initdefaults'
|
|
|
|
system ("/bin/grep micuser /tmp/mictmp/passwd >> /var/mpss/mic$micid/etc/passwd");
|
|
|
|
system ("/bin/grep micuser /tmp/mictmp/shadow >> /var/mpss/mic$micid/etc/shadow");
|
|
|
|
|
2013-06-30 04:22:22 +00:00
|
|
|
# generate the static root file system in ramdisk format
|
|
|
|
$cmd = "micctrl --updateramfs mic$micid";
|
|
|
|
runsyscmd ($cmd, "Error: failed to generate the static ramfs.\n", 301);
|
|
|
|
}
|
|
|
|
|
|
|
|
# start the mpss service after the configuration
|
2013-07-11 06:45:27 +00:00
|
|
|
$cmd = "service mpss start >/dev/null 2>&1 </dev/null";
|
2013-06-30 04:22:22 +00:00
|
|
|
system($cmd);
|
|
|
|
|
|
|
|
$i = 5;
|
|
|
|
while ($i > 0) {
|
|
|
|
$cmd = "service mpss status";
|
|
|
|
($rc, $output) = runsyscmd ($cmd, "Error: failed to get the status of mpss.\n", 100);
|
|
|
|
if (grep /mpss is running/, @$output) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
sleep 2;
|
|
|
|
$i--;
|
|
|
|
}
|
|
|
|
|
|
|
|
# notice nodeset command, the configuratoin has been done
|
|
|
|
foreach my $micid (keys %miccfg) {
|
2013-11-03 14:36:55 +00:00
|
|
|
if ($micid !~ /^\d*$/) {
|
|
|
|
# not mic specific, return
|
|
|
|
next;
|
|
|
|
}
|
2013-06-30 04:22:22 +00:00
|
|
|
outputmsg ("MICMSG:$miccfg{$micid}{'name'}: Done\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
print LOG "mpss has been started\n";
|
|
|
|
print LOG "\nFinish the mic configuratoin: ".`date`."====================================================\n";
|
|
|
|
|
|
|
|
close (LOG);
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
# run command
|
|
|
|
sub runsyscmd {
|
|
|
|
my $cmd = shift;
|
|
|
|
my $errmsg = shift;
|
|
|
|
my $rc = shift;
|
|
|
|
|
|
|
|
print LOG "---------------------------------------------\n";
|
|
|
|
print LOG "Run command: $cmd\n";
|
|
|
|
|
|
|
|
if (!($cmd =~ /2>&1$/)) { $cmd .= ' 2>&1'; }
|
|
|
|
my @output = `$cmd`;
|
|
|
|
|
|
|
|
my $errcode = 0;
|
|
|
|
if ($?) {
|
|
|
|
$errcode = $? >> 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (@output) {
|
|
|
|
print LOG $_;
|
|
|
|
}
|
|
|
|
print LOG "---------------------------------------------\n";
|
|
|
|
|
|
|
|
if ($rc && $errcode) {
|
|
|
|
outputmsg($errmsg, $rc);
|
|
|
|
exit $rc;
|
|
|
|
}
|
|
|
|
return ($errcode, \@output);
|
|
|
|
}
|
|
|
|
|
|
|
|
# display the output message
|
|
|
|
sub outputmsg{
|
|
|
|
my $msg = shift;
|
|
|
|
my $rc =shift;
|
|
|
|
print LOG $msg;
|
|
|
|
print $msg;
|
|
|
|
if ($rc) {
|
|
|
|
exit $rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|