1 |
# $Id$ |
# dummy include for transitional purposes only |
2 |
|
# |
3 |
|
# Will be removed in the near future, please use sysvinit.minc |
4 |
|
# or systemd.minc directly for new packages. |
5 |
|
# |
6 |
|
|
7 |
# adds services to runlevels and starts them |
minclude sysvinit |
8 |
# mstartservice service {/path/to/service_exec} |
minclude systemd |
|
mstartservice() |
|
|
{ |
|
|
local service="$1" |
|
|
local service_exec="$2" |
|
|
|
|
|
# only run if sysV init was found |
|
|
if [[ ! -f /etc/rc.d/init.d/functions ]] |
|
|
then |
|
|
echo "sysV init not found, not adding service ${service} to runlevels!" |
|
|
return |
|
|
fi |
|
|
|
|
|
# don't run if feature !autosvc was set |
|
|
if mqueryfeature "!autosvc" |
|
|
then |
|
|
echo "!autosvc detected; auto management of services disabled." |
|
|
return |
|
|
fi |
|
|
|
|
|
[[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
|
|
|
|
|
# add service to default runlevels |
|
|
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding ${service} to default runlevels ..." |
|
|
[[ -x ${MROOT}/etc/rc.d/init.d/${service} ]] && rc-config add ${service} &> /dev/null |
|
|
|
|
|
# do not start services on bootstrap or MROOT!=/ |
|
|
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
|
|
then |
|
|
# start service |
|
|
if [[ -n $(pidof ${service_exec}) ]] |
|
|
then |
|
|
# restart service |
|
|
/etc/init.d/${service} restart |
|
|
else |
|
|
# start service |
|
|
/etc/init.d/${service} start |
|
|
fi |
|
|
fi |
|
|
} |
|
|
|
|
|
# removes services from runlevels and stops them |
|
|
# mstopservice service {/path/to/service_exec} |
|
|
mstopservice() |
|
|
{ |
|
|
local service="$1" |
|
|
local service_exec="$2" |
|
|
|
|
|
# only run if sysV init was found |
|
|
if [[ ! -f /etc/rc.d/init.d/functions ]] |
|
|
then |
|
|
echo "sysV init not found, not adding service ${service} to runlevels!" |
|
|
return |
|
|
fi |
|
|
|
|
|
# don't run if feature !autosvc was set |
|
|
if mqueryfeature "!autosvc" |
|
|
then |
|
|
echo "!autosvc detected; auto management of services disabled." |
|
|
return |
|
|
fi |
|
|
|
|
|
if [[ -z ${service_exec} ]] |
|
|
then |
|
|
service_exec="$(which ${service})" |
|
|
elif [[ x$(basename ${service_exec}) = x${service_exec} ]] |
|
|
then |
|
|
# expand full path |
|
|
service_exec="$(which ${service_exec})" |
|
|
fi |
|
|
|
|
|
# only stop the service if ${service_exec} does not exist |
|
|
[[ -x ${MROOT}/${service_exec} ]] && return |
|
|
|
|
|
# del services from runlevel regardless if they exist or not |
|
|
echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing ${service} from default runlevels ..." |
|
|
rc-config del ${service} &> /dev/null |
|
|
|
|
|
# do not stop services on bootstrap or MROOT!=/ |
|
|
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
|
|
then |
|
|
# stop service if running |
|
|
if [[ -n $(pidof ${service_exec}) ]] |
|
|
then |
|
|
killall -15 ${service_exec} &> /dev/null |
|
|
sleep 1 |
|
|
killall -9 ${service_exec} &> /dev/null |
|
|
fi |
|
|
fi |
|
|
} |
|
|
|
|
|
# reloads a service if already running |
|
|
# mreloadservice service {/path/to/service_exec} |
|
|
mreloadservice() |
|
|
{ |
|
|
local service="$1" |
|
|
local service_exec="$2" |
|
|
|
|
|
# only run if sysV init was found |
|
|
if [[ ! -f /etc/rc.d/init.d/functions ]] |
|
|
then |
|
|
echo "sysV init not found, not adding service ${service} to runlevels!" |
|
|
return |
|
|
fi |
|
|
|
|
|
# don't run if feature !autosvc was set |
|
|
if mqueryfeature "!autosvc" |
|
|
then |
|
|
echo "!autosvc detected; auto management of services disabled." |
|
|
return |
|
|
fi |
|
|
|
|
|
[[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
|
|
|
|
|
# do not stop services on bootstrap or MROOT!=/ |
|
|
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
|
|
then |
|
|
# only reload the service if running |
|
|
if [[ -n $(pidof ${service_exec}) ]] |
|
|
then |
|
|
/etc/init.d/${service} reload |
|
|
fi |
|
|
fi |
|
|
} |
|
|
|
|
|
# adds systemd units to runlevels and starts them |
|
|
# mstartunit service {/path/to/service_exec} |
|
|
mstartunit() |
|
|
{ |
|
|
local service="$1" |
|
|
local service_exec="$2" |
|
|
local opts |
|
|
|
|
|
# only run if systemd was found |
|
|
if [[ ! -x /bin/systemctl ]] && [[ ! -x /usr/bin/systemctl ]] |
|
|
then |
|
|
echo "systemd not found, not adding unit ${service} to runlevels!" |
|
|
return |
|
|
fi |
|
|
|
|
|
# don't run if feature !autosvc was set |
|
|
if mqueryfeature "!autosvc" |
|
|
then |
|
|
echo "!autosvc detected; auto management of services disabled." |
|
|
return |
|
|
fi |
|
|
|
|
|
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
|
|
then |
|
|
opts="--root ${MROOT}" |
|
|
fi |
|
|
|
|
|
if [[ -z ${service_exec} ]] |
|
|
then |
|
|
case ${service} in |
|
|
*.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;; |
|
|
*.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;; |
|
|
*.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;; |
|
|
*.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;; |
|
|
*) service_exec="$(which ${service} 2> /dev/null)" ;; |
|
|
esac |
|
|
fi |
|
|
|
|
|
# add service to default runlevels |
|
|
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..." |
|
|
# reload daemon to honor changed unit files |
|
|
systemctl ${opts} daemon-reload |
|
|
systemctl ${opts} enable ${service} |
|
|
|
|
|
# do not start services on bootstrap or MROOT!=/ |
|
|
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
|
|
then |
|
|
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} starting unit ${service} ..." |
|
|
# start or restart the service |
|
|
# dont use try-restart, works only with active services! |
|
|
systemctl restart ${service} |
|
|
fi |
|
|
} |
|
|
|
|
|
# removes systemd units from runlevels and stops them |
|
|
# mstopunit service {/path/to/service_exec} |
|
|
mstopunit() |
|
|
{ |
|
|
local service="$1" |
|
|
local service_exec="$2" |
|
|
local opts |
|
|
|
|
|
# only run if systemd was found |
|
|
if [[ ! -x /bin/systemctl ]] && [[ ! -x /usr/bin/systemctl ]] |
|
|
then |
|
|
echo "systemd not found, not removing unit ${service} from runlevels!" |
|
|
return |
|
|
fi |
|
|
|
|
|
# don't run if feature !autosvc was set |
|
|
if mqueryfeature "!autosvc" |
|
|
then |
|
|
echo "!autosvc detected; auto management of services disabled." |
|
|
return |
|
|
fi |
|
|
|
|
|
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
|
|
then |
|
|
opts="--root ${MROOT}" |
|
|
fi |
|
|
|
|
|
if [[ -z ${service_exec} ]] |
|
|
then |
|
|
case ${service} in |
|
|
*.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;; |
|
|
*.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;; |
|
|
*.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;; |
|
|
*.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;; |
|
|
*) service_exec="$(which ${service} 2> /dev/null)" ;; |
|
|
esac |
|
|
elif [[ x$(basename ${service_exec}) = x${service_exec} ]] |
|
|
then |
|
|
# expand full path |
|
|
service_exec="$(which ${service_exec})" |
|
|
fi |
|
|
|
|
|
# only stop the service if ${service_exec} does not exist |
|
|
[[ -x ${MROOT}/${service_exec} ]] && return |
|
|
|
|
|
# del services from runlevel regardless if they exist or not |
|
|
echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..." |
|
|
# reload daemon to honor changed unit files |
|
|
systemctl ${opts} daemon-reload |
|
|
systemctl ${opts} disable ${service} |
|
|
|
|
|
# do not stop services on bootstrap or MROOT!=/ |
|
|
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
|
|
then |
|
|
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} stopping unit ${service} ..." |
|
|
systemctl stop ${service} |
|
|
# try harder |
|
|
if [[ -n $(pidof ${service_exec}) ]] |
|
|
then |
|
|
killall -15 ${service_exec} &> /dev/null |
|
|
sleep 1 |
|
|
killall -9 ${service_exec} &> /dev/null |
|
|
fi |
|
|
fi |
|
|
} |
|
|
|
|
|
# reloads a systemd unit if already running |
|
|
# mreloadunit service {/path/to/service_exec} |
|
|
mreloadunit() |
|
|
{ |
|
|
local service="$1" |
|
|
local service_exec="$2" |
|
|
local opts |
|
|
|
|
|
# only run if systemd was found |
|
|
if [[ ! -x /bin/systemctl ]] && [[ ! -x /usr/bin/systemctl ]] |
|
|
then |
|
|
echo "systemd not found, not removing unit ${service} from runlevels!" |
|
|
return |
|
|
fi |
|
|
|
|
|
# don't run if feature !autosvc was set |
|
|
if mqueryfeature "!autosvc" |
|
|
then |
|
|
echo "!autosvc detected; auto management of services disabled." |
|
|
return |
|
|
fi |
|
|
|
|
|
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
|
|
then |
|
|
opts="--root ${MROOT}" |
|
|
fi |
|
|
|
|
|
if [[ -z ${service_exec} ]] |
|
|
then |
|
|
case ${service} in |
|
|
*.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;; |
|
|
*.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;; |
|
|
*.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;; |
|
|
*.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;; |
|
|
*) service_exec="$(which ${service} 2> /dev/null)" ;; |
|
|
esac |
|
|
fi |
|
|
|
|
|
# reload daemon to honor changed unit files |
|
|
systemctl ${opts} daemon-reload |
|
|
|
|
|
# do not stop services on bootstrap or MROOT!=/ |
|
|
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
|
|
then |
|
|
# only reload the service if running |
|
|
systemctl reload-or-try-restart ${service} |
|
|
fi |
|
|
} |
|