2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-30 09:36:41 +00:00

Merge pull request #1150 from immarvin/onubt16.04systemd

fix issue#1148@github, support service management with systemd on ubuntu16.04
This commit is contained in:
Xiaopeng Wang 2016-05-19 18:14:04 +08:00
commit f8cea1db80
2 changed files with 69 additions and 23 deletions

View File

@ -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;

View File

@ -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