Commit 5d473d09 authored by Vitaly Lipatov's avatar Vitaly Lipatov

serv: add --short support for lists

parent 6df9738b
...@@ -248,6 +248,9 @@ check_option() ...@@ -248,6 +248,9 @@ check_option()
--verbose) # HELPOPT: verbose mode --verbose) # HELPOPT: verbose mode
verbose=1 verbose=1
;; ;;
--short) # HELPOPT: short mode
short=1
;;
--show-command-only) # HELPOPT: show command only, do not any action --show-command-only) # HELPOPT: show command only, do not any action
show_command_only=1 show_command_only=1
;; ;;
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012, 2016 Etersoft # Copyright (C) 2012, 2016, 2021 Etersoft
# Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016, 2021 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
# List running services # List running services
serv_list() serv_list()
{ {
info "Running services:" [ -n "$short" ] || info "Running services:"
case $SERVICETYPE in case $SERVICETYPE in
# service-chkconfig) # service-chkconfig)
# ;; # ;;
...@@ -31,7 +31,11 @@ serv_list() ...@@ -31,7 +31,11 @@ serv_list()
sudocmd service --status-all sudocmd service --status-all
;; ;;
systemd) systemd)
sudocmd systemctl list-units $@ if [ -n "$short" ] ; then
docmd systemctl list-units --type=service "$@" | grep '\.service' | sed -e 's|\.service.*||' -e 's|^ *||'
else
docmd systemctl list-units --type=service "$@"
fi
;; ;;
openrc) openrc)
sudocmd rc-status sudocmd rc-status
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012,2016 Etersoft # Copyright (C) 2012, 2016, 2021 Etersoft
# Copyright (C) 2012,2016 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016, 2021 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -22,22 +22,42 @@ serv_list_all() ...@@ -22,22 +22,42 @@ serv_list_all()
{ {
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
# service --status-all for Ubuntu/Fedora if [ -n "$short" ] ; then
sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$" # service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$" | cut -f 1 -d" "
else
# service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$"
fi
if [ -n "$ANYSERVICE" ] ; then if [ -n "$ANYSERVICE" ] ; then
sudocmd anyservice --quiet list if [ -n "$short" ] ; then
sudocmd anyservice --quiet list | cut -f 1 -d" "
else
sudocmd anyservice --quiet list
fi
return return
fi fi
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd ls $INITDIR/ | grep -v README if [ -n "$short" ] ; then
sudocmd ls $INITDIR/ | grep -v README | cut -f 1 -d" "
else
sudocmd ls $INITDIR/ | grep -v README
fi
;; ;;
systemd) systemd)
sudocmd systemctl list-unit-files $@ if [ -n "$short" ] ; then
docmd systemctl list-unit-files --type=service "$@" | sed -e 's|\.service.*||' | grep -v 'unit files listed' | grep -v '^$'
else
docmd systemctl list-unit-files --type=service "$@"
fi
;; ;;
openrc) openrc)
sudocmd rc-service -l if [ -n "$short" ] ; then
sudocmd rc-service -l | cut -f 1 -d" "
else
sudocmd rc-service -l
fi
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
......
...@@ -33,12 +33,11 @@ serv_list_failed() ...@@ -33,12 +33,11 @@ serv_list_failed()
*) *)
load_helper serv-list_startup load_helper serv-list_startup
load_helper serv-status load_helper serv-status
for i in $(serv_list_startup | cut -f 1 -d" ") ; 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
} }
...@@ -32,15 +32,14 @@ serv_list_startup() ...@@ -32,15 +32,14 @@ serv_list_startup()
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 $(serv_list_all | cut -f 1 -d" " | grep "\.service$") ; do for i in $(short=1 serv_list_all) ; do
is_service_autostart >/dev/null $i && echo $i is_service_autostart >/dev/null 2>/dev/null $i && echo $i
done done
;; ;;
*) *)
for i in $(serv_list_all | cut -f 1 -d" ") ; do for i in $(short=1 serv_list_all) ; do
is_service_autostart >/dev/null $i && echo $i is_service_autostart >/dev/null 2>/dev/null $i && echo $i
done done
;; ;;
esac esac
} }
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