1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #!/usr/bin/perl use strict; #main() my $updateSWConf; my $pid; my @children; # 命令行参数解析 if ($ARGV[0] eq "-c") { $updateSWConf = $ARGV[1]; if( $updateSWConf eq "" ) { $updateSWConf = "/etc/updateSW.conf"; } } # 检查是否指定需要进行更新的节点 if ( ($ARGV[2] ne "-n") || ($ARGV[2] eq "") || ($ARGV[3] eq "") ) { print "pls specify the updated nodes with – n.\n"; } my $argLine = $ARGV[3]; chomp($argLine); my @nodeNameArray = split ",", $argLine; my %confHash = parseSWConf($updateSWConf); # 对节点列表进行轮循 foreach my $nodeName (@nodeNameArray) { if ($nodeName eq "") continue; FORK: { # 针对每个节点创建多进程 if ($pid = fork) { #parent, store pid in array push(@children, $pid); } elsif (defined $pid) { # 针对需要安装的包列表,进行轮循 foreach my $SWPkgName (keys %confHash) { my $location = $confHash{$SWPkgName}{"loc"}; my $bndLocation = $confHash{$SWPkgName}{"bnd"}; my $bundleName = $SWPkgName . "_bundle"; my %failNodes = {}; my $tmpVal = 0; # 定义类型为 lpp_source 的资源 runCmd("nim -o define -t lpp_source -a server=master -a \ location=$location $SWPkgName"); $tmpVal = $::RETVAL; goto ERROR1 if $tmpVal; # 定义类型为 installp_bundle 的资源 runCmd("nim -o define -t installp_bundle -a server=master -a \ location=$bndLocation $bundleName"); $tmpVal = $tmpVal || $::RETVAL; goto ERROR2 if $tmpVal; # 分配资源 runCmd("nim -o allocate -a lpp_source=$SWPkgName -a \ installp_bundle=$bundleName $nodeName"); $tmpVal = $tmpVal || $::RETVAL; goto ERROR3 if $tmpVal # 进行节点更新 runCmd("nim -o update $nodeName"); $tmpVal = $tmpVal || $::RETVAL; goto ERROR4 if $tmpVal; print "Successfully update $SWPkgName on $nodeName.\n"; next; # 根据实际情况,进行错误处理 ERROR4: runCmd("nim -o deallocate $nodeName"); ERROR3: runCmd("nim -o remove $SWPkgName"); ERROR2: runCmd("nim -o remove $SWPkgName"); ERROR1: print " Fail to update $SWPkgName on $nodeName.\n"; exit $tmpVal; } exit 0; } else { #couldn't fork, can't use msg catalog since no # procs are available. printf "updateLinuxSW: Unable to fork child process.\n"; } }#end of the fork } #wait until all children processes have ended. foreach $pid (@children) { waitpid($pid, 0); } undef @children; exit 0; |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |