3
# Copyright (C) 2012-2013, 2016, 2020, 2021, 2023 Etersoft
4
# Copyright (C) 2012-2013, 2016, 2020, 2021, 2023 Vitaly Lipatov <lav@etersoft.ru>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
PROGDIR=$(dirname "$0")
21
PROGNAME=$(basename "$0")
22
[ -n "$EPMCURDIR" ] || export EPMCURDIR="$(pwd)"
24
# TODO: pwd for ./epm and which for epm
25
[ "$PROGDIR" = "." ] && PROGDIR="$EPMCURDIR"
26
if [ "$0" = "/dev/stdin" ] || [ "$0" = "sh" ] ; then
31
# will replaced with /usr/share/eepm during install
33
# will replaced with /etc/eepm during install
34
CONFIGDIR=$PROGDIR/../etc
38
# package, single (file), pipe, git
40
[ "$SHAREDIR" = "$PROGDIR" ] && EPMMODE="single"
41
[ "$EPMVERSION" = "@""VERSION""@" ] && EPMMODE="git"
42
[ "$PROGNAME" = "" ] && EPMMODE="pipe"
44
if [ "$EPMMODE" = "git" ] ; then
45
EPMVERSION=$(head $PROGDIR/../eepm.spec | grep "^Version: " | sed -e 's|Version: ||' )
51
local shieldname="loaded$(echo "$1" | sed -e 's|-||g')"
53
eval "test -n \"\$$shieldname\"" && debug "Already loaded $1" && return
55
local CMD="$SHAREDIR/$1"
56
# do not use fatal() here, it can be initial state
57
[ -r "$CMD" ] || { echo "FATAL: Have no $CMD helper file" ; exit 1; }
59
# shellcheck disable=SC1090
64
load_helper epm-sh-functions
68
PATH=$PATH:/sbin:/usr/sbin
74
#############################
76
# FIXME: detect by real init system
77
# FIXME: add upstart support (Ubuntu?)
84
case "$DISTRCONTROL" in
86
CMD="service-chkconfig"
93
# override system control detection result
94
[ -n "$SERV_BACKEND" ] && CMD="$SERV_BACKEND"
96
[ -n "$FORCESERVICE" ] && CMD="$FORCESERVICE"
100
ANYSERVICE=$(print_command_path anyservice)
104
# TODO: done it on anyservice part
107
[ -n "$ANYSERVICE" ] || return
108
[ -n "$1" ] || return
109
# check if anyservice is exists and checkd returns true
110
$ANYSERVICE "$1" checkd 2>/dev/null
128
local on_text="(host system)"
129
local virt="$($DISTRVENDOR -i)"
130
[ "$virt" = "(unknown)" ] || [ "$virt" = "(host system)" ] || on_text="(under $virt)"
131
echo "Service manager version $EPMVERSION https://wiki.etersoft.ru/Epm"
132
echo "Running on $DISTRNAME/$DISTRVERSION $on_text with $SERVICETYPE"
133
echo "Copyright (c) Etersoft 2012-2023"
134
echo "This program may be freely redistributed under the terms of the GNU AGPLv3."
139
Usage="Usage: $progname [options] [<service>] [<command>] [params]..."
140
Descr="serv - Service manager"
154
# load system wide config
155
[ -f /etc/eepm/serv.conf ] && . /etc/eepm/serv.conf
159
# do not override command
160
[ -z "$serv_cmd" ] || return
163
status) # HELPCMD: show service status
166
restart) # HELPCMD: restart service
169
reload) # HELPCMD: reload service
172
start) # HELPCMD: start service
175
stop) # HELPCMD: stop service
178
on) # HELPCMD: add service to run on startup and start it now
181
off) # HELPCMD: remove service to run on startup and stop it now
184
enable) # HELPCMD: add service to run on startup (see 'on' also)
187
disable) # HELPCMD: remove service to run on startup (see 'off' also)
190
log|journal) # HELPCMD: print log for the service (-f - follow, -r - reverse order)
193
cat) # HELPCMD: print out service file for the service
196
exists) # HELPCMD: check if the service is installed on the system
199
edit) # HELPCMD: edit service file overload (use --full to edit full file)
202
test|-t) # HELPCMD: test a config file of the service
205
list) # HELPCMD: list running services
209
list-all) # HELPCMD: list all available services
213
list-startup) # HELPCMD: list all services to run on startup
214
serv_cmd=list_startup
217
list-failed|--failed) # HELPCMD: list services failed on startup
221
print) # HELPCMD: print some info
225
try-restart|condrestart) # HELPCMD: Restart service if running
228
usage) # HELPCMD: print out usage of the service
242
-h|--help|help) # HELPOPT: this help
246
-v|--version) # HELPOPT: print version
250
--verbose) # HELPOPT: verbose mode
253
--short) # HELPOPT: short mode
256
--show-command-only) # HELPOPT: show command only, do not any action
259
--quiet) # HELPOPT: quiet mode (do not print commands before exec)
262
--auto) # HELPOPT: non interactive mode
273
check_command $opt && continue
274
check_option $opt && continue
275
[ -z "$service_name" ] && service_name=$opt && continue
276
params="$params $opt"
279
echover "service: $service_name"
280
echover "command: $serv_cmd"
282
# Just printout help if run without args
283
if [ -z "$withoutservicename" ] && [ -z "$service_name" ] ; then
286
fatal "Run $ $progname --help for get help"
289
# use common way if the command is unknown
290
if [ -z "$serv_cmd" ] ; then
294
# Run helper for command
295
load_helper serv-$serv_cmd
296
serv_$serv_cmd $service_name $params
297
# return last error code (from subroutine)