mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-30 09:36:41 +00:00
Merge pull request #4921 from robin2008/multi-user-openbmc
Support mutiple openbmc commands in the same time
This commit is contained in:
commit
b6241689b9
@ -26,6 +26,11 @@ class AgentShell(object):
|
||||
"with the client",
|
||||
default='/var/run/xcat/agent.sock',
|
||||
type=str)
|
||||
parser.add_argument('--lockfile',
|
||||
help="The lock file to communicate "
|
||||
"with the xcat",
|
||||
default='/var/lock/xcat/agent.lock',
|
||||
type=str)
|
||||
return parser
|
||||
|
||||
def do_help(self, args):
|
||||
@ -38,7 +43,8 @@ class AgentShell(object):
|
||||
if options.help:
|
||||
self.do_help(options)
|
||||
return 0
|
||||
s = server.Server(options.sock, options.standalone)
|
||||
|
||||
s = server.Server(options.sock, options.standalone, options.lockfile)
|
||||
s.start()
|
||||
|
||||
class HelpFormatter(argparse.HelpFormatter):
|
||||
|
@ -14,7 +14,7 @@ from xcatagent import base as xcat_manager
|
||||
|
||||
MSG_TYPE = 'message'
|
||||
DB_TYPE = 'db'
|
||||
LOCK_FILE = '/var/lock/xcat/agent.lock'
|
||||
#LOCK_FILE = '/var/lock/xcat/agent.lock'
|
||||
|
||||
|
||||
class XCATMessager(utils.Messager):
|
||||
@ -50,7 +50,7 @@ class XCATMessager(utils.Messager):
|
||||
|
||||
|
||||
class Server(object):
|
||||
def __init__(self, address, standalone):
|
||||
def __init__(self, address, standalone=True, lockfile=None):
|
||||
try:
|
||||
os.unlink(address)
|
||||
except OSError:
|
||||
@ -58,6 +58,7 @@ class Server(object):
|
||||
raise
|
||||
self.address = address
|
||||
self.standalone = standalone
|
||||
self.lockfile = lockfile
|
||||
self.server = StreamServer(self._serve(), self._handle)
|
||||
|
||||
def _serve(self):
|
||||
@ -117,7 +118,7 @@ class Server(object):
|
||||
|
||||
def keep_peer_alive(self):
|
||||
def acquire():
|
||||
fd = open(LOCK_FILE, "r+")
|
||||
fd = open(self.lockfile, "r+")
|
||||
fcntl.flock(fd.fileno(), fcntl.LOCK_EX)
|
||||
# if reach here, parent process may exit
|
||||
print("xcat process exit unexpectedly.", file=sys.stderr)
|
||||
|
@ -25,8 +25,8 @@ use xCAT_monitoring::monitorctrl;
|
||||
use xCAT::TableUtils;
|
||||
|
||||
my $LOCK_DIR = "/var/lock/xcat/";
|
||||
my $LOCK_PATH = "/var/lock/xcat/agent.lock";
|
||||
my $AGENT_SOCK_PATH = "/var/run/xcat/agent.sock";
|
||||
my $LOCK_PATH = "/var/lock/xcat/agent-$$.lock";
|
||||
my $AGENT_SOCK_PATH = "/var/run/xcat/agent-$$.sock";
|
||||
my $PYTHON_LOG_PATH = "/var/log/xcat/agent.log";
|
||||
my $PYTHON_AGENT_FILE = "/opt/xcat/lib/python/agent/agent.py";
|
||||
my $MSG_TYPE = "message";
|
||||
@ -76,32 +76,43 @@ sub exists_python_agent {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
sub python_agent_reaper {
|
||||
unlink($LOCK_PATH);
|
||||
unlink($AGENT_SOCK_PATH);
|
||||
}
|
||||
sub start_python_agent {
|
||||
|
||||
if (!defined(acquire_lock())) {
|
||||
xCAT::MsgUtils->message("S", "start_python_agent() Error: Failed to acquire lock");
|
||||
return undef;
|
||||
}
|
||||
|
||||
my $fd;
|
||||
open($fd, '>', $AGENT_SOCK_PATH) && close($fd);
|
||||
my $pid = fork;
|
||||
if (!defined $pid) {
|
||||
xCAT::MsgUtils->message("S", "start_python_agent() Error: Unable to fork process");
|
||||
return undef;
|
||||
} elsif ($pid){
|
||||
|
||||
open($fd, '>', $AGENT_SOCK_PATH) && close($fd);
|
||||
$SIG{INT} = $SIG{TERM} = \&python_agent_reaper;
|
||||
return $pid;
|
||||
}
|
||||
|
||||
$SIG{CHLD} = 'DEFAULT';
|
||||
if (!$pid) {
|
||||
# child
|
||||
open($fd, ">>", $PYTHON_LOG_PATH) && close($fd);
|
||||
open(STDOUT, '>>', $PYTHON_LOG_PATH) or die("open: $!");
|
||||
open(STDERR, '>>&', \*STDOUT) or die("open: $!");
|
||||
my $ret = exec ($PYTHON_AGENT_FILE);
|
||||
my @args = ( "$PYTHON_AGENT_FILE --sock $AGENT_SOCK_PATH --lockfile $LOCK_PATH" );
|
||||
my $ret = exec @args;
|
||||
if (!defined($ret)) {
|
||||
xCAT::MsgUtils->message("S", "start_python_agent() Error: Failed to start the xCAT Python agent.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
return $pid;
|
||||
|
||||
}
|
||||
|
||||
sub handle_message {
|
||||
@ -201,6 +212,7 @@ sub wait_agent {
|
||||
xCAT::MsgUtils->message("E", { data => ["Agent exited unexpectedly. See $PYTHON_LOG_PATH for details."] }, $callback);
|
||||
xCAT::MsgUtils->message("I", { data => ["To revert to Perl framework: chdef -t site clustersite openbmcperl=ALL"] }, $callback);
|
||||
}
|
||||
python_agent_reaper();
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user