mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-29 17:23:08 +00:00
fix issue#1148@github, support service management with systemd on ubuntu16.04
This commit is contained in:
parent
dbda4181ce
commit
fe79288298
@ -3896,30 +3896,55 @@ sub servicemap{
|
||||
my $path=undef;
|
||||
my $postfix="";
|
||||
my $retdefault=$svcname;
|
||||
my $svcmgrcmd;
|
||||
if($svcmgrtype == 0){
|
||||
#for sysvinit
|
||||
$path="/etc/init.d/";
|
||||
$svcmgrcmd="service";
|
||||
}elsif ($svcmgrtype == 1){
|
||||
$path="/usr/lib/systemd/system/";
|
||||
#for systemd
|
||||
#ubuntu 16.04 replace upstart with systemd,
|
||||
#all the service unit files are placed under /lib/systemd/system/ on ubuntu
|
||||
#all the service unit files are placed under /usr/lib/systemd/system/ on redhat and sles
|
||||
#$path delimited with space
|
||||
$path="/usr/lib/systemd/system/ /lib/systemd/system/";
|
||||
$postfix=".service";
|
||||
$svcmgrcmd="systemctl";
|
||||
# $retdefault=$svcname.".service";
|
||||
}elsif ($svcmgrtype == 2){
|
||||
$path="/etc/init/";
|
||||
$postfix=".conf";
|
||||
$svcmgrcmd="initctl";
|
||||
}
|
||||
|
||||
#check whether service management command is available
|
||||
system "type $svcmgrcmd >/dev/null 2>&1";
|
||||
if($? != 0){
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
my @paths=split(" ",$path);
|
||||
my $ret=undef;
|
||||
if($svchash{$svcname}){
|
||||
foreach my $file (@{$svchash{$svcname}}){
|
||||
if(-e $path.$file.$postfix ){
|
||||
$ret=$file;
|
||||
last;
|
||||
foreach my $file (@{$svchash{$svcname}}){
|
||||
foreach my $ipath (@paths){
|
||||
if(-e $ipath.$file.$postfix ){
|
||||
$ret=$file;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(defined $ret){
|
||||
last;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(-e $path.$retdefault.$postfix){
|
||||
$ret=$retdefault;
|
||||
}
|
||||
foreach my $ipath (@paths){
|
||||
if(-e $ipath.$retdefault.$postfix){
|
||||
$ret=$retdefault;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
@ -278,11 +278,11 @@ function servicemap {
|
||||
local svcmgrtype=$2
|
||||
local svclistname=
|
||||
|
||||
# if there are more than 1 possible service names for a service among
|
||||
# different os distributions and os releases, the service should be
|
||||
# specified with structure
|
||||
# INIT_(general service name) = "list of possible service names"
|
||||
#
|
||||
# if there are more than 1 possible service names for a service among
|
||||
# different os distributions and os releases, the service should be
|
||||
# specified with structure
|
||||
# INIT_(general service name) = "list of possible service names"
|
||||
#
|
||||
INIT_dhcp="dhcp3-server dhcpd isc-dhcp-server";
|
||||
|
||||
INIT_nfs="nfsserver nfs-server nfs nfs-kernel-server";
|
||||
@ -303,19 +303,37 @@ function servicemap {
|
||||
|
||||
local path=
|
||||
local postfix=""
|
||||
local svcmgrcmd=
|
||||
local retdefault=$svcname
|
||||
local svcvar=${svcname//[-.]/_}
|
||||
if [ "$svcmgrtype" = "0" ];then
|
||||
#for sysvinit
|
||||
path="/etc/init.d/"
|
||||
svcmgrcmd="service"
|
||||
elif [ "$svcmgrtype" = "1" ];then
|
||||
#for systemd
|
||||
#retdefault=$svcname.service
|
||||
path="/usr/lib/systemd/system/"
|
||||
#ubuntu 16.04 replace upstart with systemd,
|
||||
#all the service unit files are placed under /lib/systemd/system/ on ubuntu
|
||||
#all the service unit files are placed under /usr/lib/systemd/system/ on redhat and sles
|
||||
#path should be delimited with space
|
||||
path="/usr/lib/systemd/system/ /lib/systemd/system/"
|
||||
postfix=".service"
|
||||
svcmgrcmd="systemctl"
|
||||
elif [ "$svcmgrtype" = "2" ];then
|
||||
#for upstart
|
||||
path="/etc/init/"
|
||||
postfix=".conf"
|
||||
svcmgrcmd="initctl"
|
||||
fi
|
||||
|
||||
|
||||
#check whether the service management command exists
|
||||
type $svcmgrcmd >/dev/null 2>&1
|
||||
if [ $? -ne 0 ];then
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
|
||||
svclistname=INIT_$svcvar
|
||||
local svclist=$(eval echo \$$svclistname)
|
||||
|
||||
@ -325,12 +343,15 @@ function servicemap {
|
||||
|
||||
for name in `echo $svclist`
|
||||
do
|
||||
if [ -e "$path$name$postfix" ];then
|
||||
echo $name
|
||||
break
|
||||
fi
|
||||
for ipath in `echo $path`;do
|
||||
if [ -e "$ipath$name$postfix" ];then
|
||||
echo "$name"
|
||||
return
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
#some special services cannot be processed in sysVinit, upstart and systemd framework, should be process here...
|
||||
@ -466,7 +487,7 @@ function restartservice {
|
||||
elif [ -n "$svcjob" ];then
|
||||
initctl status $svcjob | grep stop
|
||||
if [ "$?" = "0" ];then
|
||||
cmd= "initctl start $svcjob"
|
||||
cmd="initctl start $svcjob"
|
||||
else
|
||||
cmd="initctl restart $svcjob"
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user