Files
init.sh/lib/services.sh

88 lines
2.1 KiB
Bash

# ------------------------------------------------------------------------------
# Services manipulation functions
# This file is part of the init.sh project
# Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# ------------------------------------------------------------------------------
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# https://opensource.org/licenses/BSD-3-Clause
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Common code controling services scripts
# Syntax exec_serv svcname command
exec_serv()
{
if [[ $# -lt 2 ]]; then
prnt E "exec_serv(): Syntax error!"
exit 11
fi
local svcname=$1 command=$2
shift 2
local lineexec=$(echo $INIT_COM |
sed -e s/%srv%/$svcname/ \
-e s/%com%/$command/)
unset svcname command
prnt I "Launching command $command for the service $svcname"
$lineexec
return $?
unset lineexec
}
export exec_serv
# ------------------------------------------------------------------------------
# Start one or more service
svc_start()
{
local svc=
for svc in $@; do
exec_serv $svc start
done
unset svc
}
export -f svc_start
# ------------------------------------------------------------------------------
# Reload one or more services
svc_reload()
{
for svc in $@; do
exec_serv $svc reload
done
}
export -f svc_reload
# ------------------------------------------------------------------------------
# Restart one or more services
svc_restart()
{
local svc=
for svc in $@; do
exec_serv $svc restart
done
unset svc
}
export -f svc_restart
# ------------------------------------------------------------------------------
# Stop one or more services
svc_stop()
{
local svc=
for svc in $@; do
exec_serv $svc stop
done
unset svc
}
export -f svc_stop
# EOF