Commit b9dbd9ab authored by Vitaly Lipatov's avatar Vitaly Lipatov

serv: replace tab with 4 spaces

parent f204e69b
...@@ -46,18 +46,18 @@ check_tty ...@@ -46,18 +46,18 @@ check_tty
# FIXME: add upstart support (Ubuntu?) # FIXME: add upstart support (Ubuntu?)
set_service_type() set_service_type()
{ {
local CMD local CMD
set_distro_info set_distro_info
set_target_pkg_env set_target_pkg_env
case "$DISTRCONTROL" in case "$DISTRCONTROL" in
sysvinit) sysvinit)
CMD="service-chkconfig" CMD="service-chkconfig"
;; ;;
systemd) systemd)
CMD="systemd" CMD="systemd"
;; ;;
esac esac
# override system control detection result # override system control detection result
...@@ -72,16 +72,16 @@ ANYSERVICE=$(print_command_path anyservice) ...@@ -72,16 +72,16 @@ ANYSERVICE=$(print_command_path anyservice)
# TODO: done it on anyservice part # TODO: done it on anyservice part
is_anyservice() is_anyservice()
{ {
[ -n "$ANYSERVICE" ] || return [ -n "$ANYSERVICE" ] || return
[ -n "$1" ] || return [ -n "$1" ] || return
# check if anyservice is exists and checkd returns true # check if anyservice is exists and checkd returns true
$ANYSERVICE "$1" checkd 2>/dev/null $ANYSERVICE "$1" checkd 2>/dev/null
} }
phelp() phelp()
{ {
echo "$Descr echo "$Descr
$Usage $Usage
Commands: Commands:
$(get_help HELPCMD) $(get_help HELPCMD)
......
...@@ -19,23 +19,23 @@ ...@@ -19,23 +19,23 @@
serv_cat() serv_cat()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
systemd) systemd)
docmd systemctl cat "$SERVICE" "$@" docmd systemctl cat "$SERVICE" "$@"
;; ;;
*) *)
case $BASEDISTRNAME in case $BASEDISTRNAME in
"alt") "alt")
local INITFILE=/etc/init.d/$SERVICE local INITFILE=/etc/init.d/$SERVICE
[ -r "$INITFILE" ] || fatal "Can't find init file $INITFILE" [ -r "$INITFILE" ] || fatal "Can't find init file $INITFILE"
docmd cat $INITFILE docmd cat $INITFILE
return ;; return ;;
*) *)
fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE" fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE"
;; ;;
esac esac
esac esac
} }
...@@ -20,31 +20,31 @@ ...@@ -20,31 +20,31 @@
# Common call service # Common call service
serv_common() serv_common()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
fatal "Have no idea how to call anyservice service with args" fatal "Have no idea how to call anyservice service with args"
fi fi
sudocmd service $SERVICE "$@" sudocmd service $SERVICE "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd $INITDIR/$SERVICE "$@" sudocmd $INITDIR/$SERVICE "$@"
;; ;;
systemd) systemd)
# run init script directly (for nonstandart commands) # run init script directly (for nonstandart commands)
if [ -x $INITDIR/$SERVICE ] ; then if [ -x $INITDIR/$SERVICE ] ; then
sudocmd $INITDIR/$SERVICE "$@" sudocmd $INITDIR/$SERVICE "$@"
else else
sudocmd systemctl "$@" $SERVICE sudocmd systemctl "$@" $SERVICE
fi fi
;; ;;
runit) runit)
sudocmd sv $SERVICE "$@" sudocmd sv $SERVICE "$@"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
...@@ -23,32 +23,32 @@ load_helper serv-status ...@@ -23,32 +23,32 @@ load_helper serv-status
# Enable service by default # Enable service by default
serv_disable() serv_disable()
{ {
local SERVICE="$1" local SERVICE="$1"
is_service_autostart $1 || { info "Service $1 already disabled for startup" && return ; } is_service_autostart $1 || { info "Service $1 already disabled for startup" && return ; }
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE off sudocmd anyservice $SERVICE off
return return
fi fi
sudocmd chkconfig $1 off sudocmd chkconfig $1 off
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd update-rc.d $1 remove sudocmd update-rc.d $1 remove
;; ;;
systemd) systemd)
sudocmd systemctl disable $1 sudocmd systemctl disable $1
;; ;;
openrc) openrc)
sudocmd rc-update del $1 default sudocmd rc-update del $1 default
;; ;;
runit) runit)
sudocmd rm -fv /var/service/$SERVICE sudocmd rm -fv /var/service/$SERVICE
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
...@@ -19,15 +19,15 @@ ...@@ -19,15 +19,15 @@
serv_edit() serv_edit()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
systemd) systemd)
sudocmd systemctl edit "$@" "$SERVICE" sudocmd systemctl edit "$@" "$SERVICE"
;; ;;
*) *)
fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE" fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE"
;; ;;
esac esac
} }
...@@ -23,39 +23,39 @@ load_helper serv-status ...@@ -23,39 +23,39 @@ load_helper serv-status
# Enable service by default # Enable service by default
serv_enable() serv_enable()
{ {
local SERVICE="$1" local SERVICE="$1"
is_service_autostart $1 && info "Service $1 is already enabled for startup" && return is_service_autostart $1 && info "Service $1 is already enabled for startup" && return
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig) service-chkconfig)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE on sudocmd anyservice $SERVICE on
return return
fi fi
sudocmd chkconfig --add $1 || return sudocmd chkconfig --add $1 || return
sudocmd chkconfig $1 on sudocmd chkconfig $1 on
;; ;;
service-upstart) service-upstart)
sudocmd chkconfig --add $1 || return sudocmd chkconfig --add $1 || return
sudocmd chkconfig $1 on sudocmd chkconfig $1 on
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd update-rc.d $1 defaults sudocmd update-rc.d $1 defaults
;; ;;
systemd) systemd)
sudocmd systemctl enable $1 sudocmd systemctl enable $1
;; ;;
openrc) openrc)
sudocmd rc-update add $1 default sudocmd rc-update add $1 default
;; ;;
runit) runit)
assure_exists $SERVICE assure_exists $SERVICE
[ -r "/etc/sv/$SERVICE" ] || fatal "Can't find /etc/sv/$SERVICE" [ -r "/etc/sv/$SERVICE" ] || fatal "Can't find /etc/sv/$SERVICE"
sudocmd ln -s /etc/sv/$SERVICE /var/service/ sudocmd ln -s /etc/sv/$SERVICE /var/service/
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
...@@ -19,23 +19,23 @@ ...@@ -19,23 +19,23 @@
serv_exists() serv_exists()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
systemd) systemd)
# too direct way: test -s /lib/systemd/system/dm.service # too direct way: test -s /lib/systemd/system/dm.service
docmd systemctl cat "$SERVICE" "$@" >/dev/null 2>/dev/null docmd systemctl cat "$SERVICE" "$@" >/dev/null 2>/dev/null
;; ;;
*) *)
case $BASEDISTRNAME in case $BASEDISTRNAME in
"alt") "alt")
local INITFILE=/etc/init.d/$SERVICE local INITFILE=/etc/init.d/$SERVICE
[ -r "$INITFILE" ] || return [ -r "$INITFILE" ] || return
return ;; return ;;
*) *)
fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE" fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE"
;; ;;
esac esac
esac esac
} }
...@@ -20,34 +20,34 @@ ...@@ -20,34 +20,34 @@
# List running services # List running services
serv_list() serv_list()
{ {
[ -n "$short" ] || info "Running services:" [ -n "$short" ] || info "Running services:"
case $SERVICETYPE in case $SERVICETYPE in
# service-chkconfig) # service-chkconfig)
# ;; # ;;
service-upstart) service-upstart)
sudocmd initctl list sudocmd initctl list
;; ;;
service-update) service-update)
sudocmd service --status-all sudocmd service --status-all
;; ;;
systemd) systemd)
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
docmd systemctl list-units --type=service "$@" | grep '\.service' | sed -e 's|\.service.*||' -e 's|^ *||' docmd systemctl list-units --type=service "$@" | grep '\.service' | sed -e 's|\.service.*||' -e 's|^ *||'
else else
docmd systemctl list-units --type=service "$@" docmd systemctl list-units --type=service "$@"
fi fi
;; ;;
openrc) openrc)
sudocmd rc-status sudocmd rc-status
;; ;;
*) *)
# hack to improve list speed # hack to improve list speed
[ "$UID" = 0 ] || { sudocmd $PROGDIR/serv --quiet list ; return ; } [ "$UID" = 0 ] || { sudocmd $PROGDIR/serv --quiet list ; return ; }
load_helper serv-list_all load_helper serv-list_all
load_helper serv-status load_helper serv-status
for i in $(quiet=1 serv_list_all) ; do for i in $(quiet=1 serv_list_all) ; do
is_service_running $i >/dev/null && echo $i is_service_running $i >/dev/null && echo $i
done done
;; ;;
esac esac
} }
...@@ -20,47 +20,47 @@ ...@@ -20,47 +20,47 @@
# List all available services # List all available services
serv_list_all() serv_list_all()
{ {
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
# service --status-all for Ubuntu/Fedora # service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$" | cut -f 1 -d" " sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$" | cut -f 1 -d" "
else else
# service --status-all for Ubuntu/Fedora # service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$" sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$"
fi fi
if [ -n "$ANYSERVICE" ] ; then if [ -n "$ANYSERVICE" ] ; then
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
sudocmd anyservice --quiet list | cut -f 1 -d" " sudocmd anyservice --quiet list | cut -f 1 -d" "
else else
sudocmd anyservice --quiet list sudocmd anyservice --quiet list
fi fi
return return
fi fi
;; ;;
service-initd|service-update) service-initd|service-update)
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
sudocmd ls $INITDIR/ | grep -v README | cut -f 1 -d" " sudocmd ls $INITDIR/ | grep -v README | cut -f 1 -d" "
else else
sudocmd ls $INITDIR/ | grep -v README sudocmd ls $INITDIR/ | grep -v README
fi fi
;; ;;
systemd) systemd)
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
docmd systemctl list-unit-files --type=service "$@" | sed -e 's|\.service.*||' | grep -v 'unit files listed' | grep -v '^$' docmd systemctl list-unit-files --type=service "$@" | sed -e 's|\.service.*||' | grep -v 'unit files listed' | grep -v '^$'
else else
docmd systemctl list-unit-files --type=service "$@" docmd systemctl list-unit-files --type=service "$@"
fi fi
;; ;;
openrc) openrc)
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
sudocmd rc-service -l | cut -f 1 -d" " sudocmd rc-service -l | cut -f 1 -d" "
else else
sudocmd rc-service -l sudocmd rc-service -l
fi fi
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
...@@ -19,25 +19,25 @@ ...@@ -19,25 +19,25 @@
serv_list_failed() serv_list_failed()
{ {
case $SERVICETYPE in case $SERVICETYPE in
# service-chkconfig|service-upstart) # service-chkconfig|service-upstart)
# # service --status-all for Ubuntu/Fedora # # service --status-all for Ubuntu/Fedora
# #sudocmd chkconfig --list | cut -f1 # #sudocmd chkconfig --list | cut -f1
# ;; # ;;
# service-initd|service-update) # service-initd|service-update)
# sudocmd ls -1 /etc/init.d/* | sed -e "s|/etc/init.d/||g" | grep -v README # sudocmd ls -1 /etc/init.d/* | sed -e "s|/etc/init.d/||g" | grep -v README
# ;; # ;;
systemd) systemd)
sudocmd systemctl --failed sudocmd systemctl --failed
;; ;;
*) *)
load_helper serv-list_startup load_helper serv-list_startup
load_helper serv-status load_helper serv-status
for i in $(short=1 serv_list_startup) ; do for i in $(short=1 serv_list_startup) ; do
is_service_running >/dev/null $i && continue is_service_running >/dev/null $i && continue
echo ; echo $i echo ; echo $i
serv_status $i serv_status $i
done done
;; ;;
esac esac
} }
...@@ -19,27 +19,27 @@ ...@@ -19,27 +19,27 @@
serv_list_startup() serv_list_startup()
{ {
load_helper serv-list_all load_helper serv-list_all
load_helper serv-status load_helper serv-status
case $SERVICETYPE in case $SERVICETYPE in
# service-chkconfig|service-upstart) # service-chkconfig|service-upstart)
# # service --status-all for Ubuntu/Fedora # # service --status-all for Ubuntu/Fedora
# #sudocmd chkconfig --list | cut -f1 # #sudocmd chkconfig --list | cut -f1
# ;; # ;;
# service-initd|service-update) # service-initd|service-update)
# sudocmd ls -1 /etc/init.d/* | sed -e "s|/etc/init.d/||g" | grep -v README # sudocmd ls -1 /etc/init.d/* | sed -e "s|/etc/init.d/||g" | grep -v README
# ;; # ;;
systemd) systemd)
#sudocmd systemctl list-unit-files #sudocmd systemctl list-unit-files
# TODO: native command? implement --short for list (only names) # TODO: native command? implement --short for list (only names)
for i in $(short=1 serv_list_all) ; do for i in $(short=1 serv_list_all) ; do
is_service_autostart >/dev/null 2>/dev/null $i && echo $i is_service_autostart >/dev/null 2>/dev/null $i && echo $i
done done
;; ;;
*) *)
for i in $(short=1 serv_list_all) ; do for i in $(short=1 serv_list_all) ; do
is_service_autostart >/dev/null 2>/dev/null $i && echo $i is_service_autostart >/dev/null 2>/dev/null $i && echo $i
done done
;; ;;
esac esac
} }
...@@ -19,47 +19,47 @@ ...@@ -19,47 +19,47 @@
__serv_log_altlinux() __serv_log_altlinux()
{ {
local SERVICE="$1" local SERVICE="$1"
local PRG="less" local PRG="less"
[ "$2" = "-f" ] && PRG="tail -f" [ "$2" = "-f" ] && PRG="tail -f"
case "$SERVICE" in case "$SERVICE" in
postfix) postfix)
sudocmd $PRG /var/log/mail/all /var/log/mail/errors sudocmd $PRG /var/log/mail/all /var/log/mail/errors
;; ;;
sshd) sshd)
sudocmd $PRG /var/log/auth/all sudocmd $PRG /var/log/auth/all
;; ;;
cups) cups)
sudocmd $PRG /var/log/cups/access_log /var/log/cups/error_log sudocmd $PRG /var/log/cups/access_log /var/log/cups/error_log
;; ;;
fail2ban) fail2ban)
sudocmd $PRG /var/log/$SERVICE.log sudocmd $PRG /var/log/$SERVICE.log
;; ;;
*) *)
fatal "Have no suitable for $SERVICE service" fatal "Have no suitable for $SERVICE service"
;; ;;
esac esac
} }
serv_log() serv_log()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
systemd) systemd)
sudocmd journalctl -b -u "$SERVICE" "$@" sudocmd journalctl -b -u "$SERVICE" "$@"
;; ;;
*) *)
case $BASEDISTRNAME in case $BASEDISTRNAME in
"alt") "alt")
FF="" ; [ "$1" = "-f" ] && FF="-f" FF="" ; [ "$1" = "-f" ] && FF="-f"
__serv_log_altlinux "$SERVICE" $FF __serv_log_altlinux "$SERVICE" $FF
return ;; return ;;
*) *)
fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE" fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE"
;; ;;
esac esac
esac esac
} }
...@@ -24,9 +24,9 @@ load_helper serv-status ...@@ -24,9 +24,9 @@ load_helper serv-status
# Enable service by default # Enable service by default
serv_off() serv_off()
{ {
local SERVICE="$1" local SERVICE="$1"
is_service_running $1 && { serv_stop $1 || return ; } is_service_running $1 && { serv_stop $1 || return ; }
is_service_autostart $1 || { info "Service $1 already disabled for startup" && return ; } is_service_autostart $1 || { info "Service $1 already disabled for startup" && return ; }
serv_disable $SERVICE serv_disable $SERVICE
} }
...@@ -23,8 +23,8 @@ load_helper serv-status ...@@ -23,8 +23,8 @@ load_helper serv-status
serv_on() serv_on()
{ {
serv_enable "$1" || return serv_enable "$1" || return
# start if need # start if need
is_service_running $1 && info "Service $1 is already running" && return is_service_running $1 && info "Service $1 is already running" && return
serv_start $1 serv_start $1
} }
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
serv_print() serv_print()
{ {
echo "Detected init system: $SERVICETYPE" echo "Detected init system: $SERVICETYPE"
[ -n "$ANYSERVICE" ] && echo "anyservice is detected too" [ -n "$ANYSERVICE" ] && echo "anyservice is detected too"
} }
...@@ -22,27 +22,27 @@ load_helper serv-status ...@@ -22,27 +22,27 @@ load_helper serv-status
# Reload service (try send SIGHUP or so on to reread config) # Reload service (try send SIGHUP or so on to reread config)
serv_reload() serv_reload()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE reload sudocmd anyservice $SERVICE reload
return return
fi fi
sudocmd service $SERVICE reload "$@" sudocmd service $SERVICE reload "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd $INITDIR/$SERVICE reload "$@" sudocmd $INITDIR/$SERVICE reload "$@"
;; ;;
systemd) systemd)
sudocmd systemctl reload $SERVICE "$@" sudocmd systemctl reload $SERVICE "$@"
;; ;;
*) *)
info "Fallback to restart..." info "Fallback to restart..."
load_helper serv-restart load_helper serv-restart
serv_restart "$SERVICE" "$@" serv_restart "$SERVICE" "$@"
;; ;;
esac esac
} }
...@@ -22,31 +22,31 @@ load_helper serv-status ...@@ -22,31 +22,31 @@ load_helper serv-status
# Restart service (start if it was not running) # Restart service (start if it was not running)
serv_restart() serv_restart()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE restart sudocmd anyservice $SERVICE restart
return return
fi fi
sudocmd service $SERVICE restart "$@" sudocmd service $SERVICE restart "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd $INITDIR/$SERVICE restart "$@" sudocmd $INITDIR/$SERVICE restart "$@"
;; ;;
systemd) systemd)
sudocmd systemctl restart $SERVICE "$@" sudocmd systemctl restart $SERVICE "$@"
;; ;;
runit) runit)
sudocmd sv restart "$SERVICE" sudocmd sv restart "$SERVICE"
;; ;;
openrc) openrc)
sudocmd rc-service restart "$SERVICE" sudocmd rc-service restart "$SERVICE"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
...@@ -20,31 +20,31 @@ ...@@ -20,31 +20,31 @@
# Start service # Start service
serv_start() serv_start()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE start sudocmd anyservice $SERVICE start
return return
fi fi
sudocmd service $SERVICE start "$@" sudocmd service $SERVICE start "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd $INITDIR/$SERVICE start "$@" sudocmd $INITDIR/$SERVICE start "$@"
;; ;;
systemd) systemd)
sudocmd systemctl start "$SERVICE" "$@" sudocmd systemctl start "$SERVICE" "$@"
;; ;;
runit) runit)
sudocmd sv up "$SERVICE" sudocmd sv up "$SERVICE"
;; ;;
openrc) openrc)
sudocmd rc-service start "$SERVICE" sudocmd rc-service start "$SERVICE"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
...@@ -20,91 +20,91 @@ ...@@ -20,91 +20,91 @@
# FIXME: sudo ask password, but we do not print command before # FIXME: sudo ask password, but we do not print command before
is_service_running() is_service_running()
{ {
local SERVICE="$1" local SERVICE="$1"
local OUTPUT local OUTPUT
# TODO: real status can be checked only with grep output # TODO: real status can be checked only with grep output
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $1 ; then if is_anyservice $1 ; then
OUTPUT="$(sudorun anyservice $1 status 2>/dev/null)" || return 1 OUTPUT="$(sudorun anyservice $1 status 2>/dev/null)" || return 1
echo "$OUTPUT" | grep -q "is stopped" && return 1 echo "$OUTPUT" | grep -q "is stopped" && return 1
return 0 return 0
fi fi
OUTPUT="$(sudorun service $1 status 2>/dev/null)" || return 1 OUTPUT="$(sudorun service $1 status 2>/dev/null)" || return 1
echo "$OUTPUT" | grep -q "is stopped" && return 1 echo "$OUTPUT" | grep -q "is stopped" && return 1
return 0 return 0
;; ;;
service-initd|service-update) service-initd|service-update)
sudorun $INITDIR/$1 status >/dev/null 2>/dev/null sudorun $INITDIR/$1 status >/dev/null 2>/dev/null
;; ;;
systemd) systemd)
a='' systemctl status $1 >/dev/null 2>/dev/null a='' systemctl status $1 >/dev/null 2>/dev/null
;; ;;
runit) runit)
sudorun sv status "$SERVICE" >/dev/null 2>/dev/null sudorun sv status "$SERVICE" >/dev/null 2>/dev/null
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
# FIXME: sudo ask password, but we do not print command before # FIXME: sudo ask password, but we do not print command before
is_service_autostart() is_service_autostart()
{ {
local SERVICE="$1" local SERVICE="$1"
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE; then if is_anyservice $SERVICE; then
$ANYSERVICE $SERVICE isautostarted $ANYSERVICE $SERVICE isautostarted
return return
fi fi
# FIXME: check for current runlevel # FIXME: check for current runlevel
LANG=C sudorun chkconfig $1 --list | grep -q "[35]:on" LANG=C sudorun chkconfig $1 --list | grep -q "[35]:on"
;; ;;
service-initd|service-update) service-initd|service-update)
test -L "$(echo /etc/rc5.d/S??$1)" test -L "$(echo /etc/rc5.d/S??$1)"
;; ;;
systemd) systemd)
a='' systemctl is-enabled $1 a='' systemctl is-enabled $1
;; ;;
runit) runit)
test -L "/var/service/$SERVICE" test -L "/var/service/$SERVICE"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
serv_status() serv_status()
{ {
is_service_autostart $1 && echo "Service $1 is scheduled to run on startup" || echo "Service $1 will NOT run on startup" is_service_autostart $1 && echo "Service $1 is scheduled to run on startup" || echo "Service $1 will NOT run on startup"
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE status sudocmd anyservice $SERVICE status
return return
fi fi
sudocmd service $SERVICE status "$@" sudocmd service $SERVICE status "$@"
;; ;;
service-update) service-update)
sudocmd $INITDIR/$SERVICE status "$@" sudocmd $INITDIR/$SERVICE status "$@"
;; ;;
systemd) systemd)
docmd systemctl -l status $SERVICE "$@" docmd systemctl -l status $SERVICE "$@"
;; ;;
runit) runit)
sudocmd sv status "$SERVICE" sudocmd sv status "$SERVICE"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
...@@ -20,31 +20,31 @@ ...@@ -20,31 +20,31 @@
# Stop service # Stop service
serv_stop() serv_stop()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE stop sudocmd anyservice $SERVICE stop
return return
fi fi
sudocmd service $SERVICE stop "$@" sudocmd service $SERVICE stop "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd $INITDIR/$SERVICE stop "$@" sudocmd $INITDIR/$SERVICE stop "$@"
;; ;;
systemd) systemd)
sudocmd systemctl stop $SERVICE "$@" sudocmd systemctl stop $SERVICE "$@"
;; ;;
runit) runit)
sudocmd sv down "$SERVICE" sudocmd sv down "$SERVICE"
;; ;;
openrc) openrc)
sudocmd rc-service stop "$SERVICE" sudocmd rc-service stop "$SERVICE"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
...@@ -19,31 +19,31 @@ ...@@ -19,31 +19,31 @@
serv_test() serv_test()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICE in case $SERVICE in
cups|cupsd) cups|cupsd)
docmd cupsd -t docmd cupsd -t
;; ;;
nginx) nginx)
docmd nginx -t docmd nginx -t
;; ;;
sshd) sshd)
docmd sshd -t docmd sshd -t
;; ;;
httpd2|httpd|apache|apache2) httpd2|httpd|apache|apache2)
if is_command httpd2 ; then if is_command httpd2 ; then
docmd httpd2 -t docmd httpd2 -t
elif is_command apache2 ; then elif is_command apache2 ; then
docmd apache2 -t docmd apache2 -t
fi fi
;; ;;
postfix) postfix)
docmd /etc/init.d/postfix check docmd /etc/init.d/postfix check
;; ;;
*) *)
fatal "$SERVICE is not supported yet. Please report if you know how to test" fatal "$SERVICE is not supported yet. Please report if you know how to test"
;; ;;
esac esac
} }
...@@ -22,18 +22,18 @@ load_helper serv-status ...@@ -22,18 +22,18 @@ load_helper serv-status
# Try restart service (if it is running) # Try restart service (if it is running)
serv_try_restart() serv_try_restart()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
systemd) systemd)
sudocmd systemctl try-restart $SERVICE "$@" sudocmd systemctl try-restart $SERVICE "$@"
;; ;;
*) *)
info "Fallback to restart..." info "Fallback to restart..."
is_service_running $SERVICE || { info "Service $SERVICE is not running, restart skipping…" ; return 0 ; } is_service_running $SERVICE || { info "Service $SERVICE is not running, restart skipping…" ; return 0 ; }
load_helper serv-restart load_helper serv-restart
serv_restart "$SERVICE" "$@" serv_restart "$SERVICE" "$@"
;; ;;
esac esac
} }
...@@ -19,31 +19,31 @@ ...@@ -19,31 +19,31 @@
_print_additional_usage() _print_additional_usage()
{ {
echo "serv addition usage: {on|off|try-restart|usage}" echo "serv addition usage: {on|off|try-restart|usage}"
} }
# Print usage of the service # Print usage of the service
serv_usage() serv_usage()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
# CHECKME: many services print out usage in stderr, it conflicts with printout command # CHECKME: many services print out usage in stderr, it conflicts with printout command
#sudocmd service $SERVICE 2>&1 #sudocmd service $SERVICE 2>&1
sudorun service $SERVICE 2>&1 sudorun service $SERVICE 2>&1
;; ;;
service-initd|service-update) service-initd|service-update)
#sudocmd /etc/init.d/$SERVICE 2>&1 #sudocmd /etc/init.d/$SERVICE 2>&1
sudorun service $SERVICE 2>&1 sudorun service $SERVICE 2>&1
;; ;;
systemd) systemd)
sudocmd systemctl $SERVICE 2>&1 sudocmd systemctl $SERVICE 2>&1
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
_print_additional_usage _print_additional_usage
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment