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

serv: add --short support for lists

parent 6df9738b
......@@ -248,6 +248,9 @@ check_option()
--verbose) # HELPOPT: verbose mode
verbose=1
;;
--short) # HELPOPT: short mode
short=1
;;
--show-command-only) # HELPOPT: show command only, do not any action
show_command_only=1
;;
......
#!/bin/sh
#
# Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2012, 2016, 2021 Etersoft
# Copyright (C) 2012, 2016, 2021 Vitaly Lipatov <lav@etersoft.ru>
#
# 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
......@@ -20,7 +20,7 @@
# List running services
serv_list()
{
info "Running services:"
[ -n "$short" ] || info "Running services:"
case $SERVICETYPE in
# service-chkconfig)
# ;;
......@@ -31,7 +31,11 @@ serv_list()
sudocmd service --status-all
;;
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)
sudocmd rc-status
......
#!/bin/sh
#
# Copyright (C) 2012,2016 Etersoft
# Copyright (C) 2012,2016 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2012, 2016, 2021 Etersoft
# Copyright (C) 2012, 2016, 2021 Vitaly Lipatov <lav@etersoft.ru>
#
# 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
......@@ -22,22 +22,42 @@ serv_list_all()
{
case $SERVICETYPE in
service-chkconfig|service-upstart)
# service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$"
if [ -n "$short" ] ; then
# 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
sudocmd anyservice --quiet list
if [ -n "$short" ] ; then
sudocmd anyservice --quiet list | cut -f 1 -d" "
else
sudocmd anyservice --quiet list
fi
return
fi
;;
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)
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)
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"
......
......@@ -33,12 +33,11 @@ serv_list_failed()
*)
load_helper serv-list_startup
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
echo ; echo $i
serv_status $i
done
;;
esac
}
......@@ -32,15 +32,14 @@ serv_list_startup()
systemd)
#sudocmd systemctl list-unit-files
# TODO: native command? implement --short for list (only names)
for i in $(serv_list_all | cut -f 1 -d" " | grep "\.service$") ; do
is_service_autostart >/dev/null $i && echo $i
for i in $(short=1 serv_list_all) ; do
is_service_autostart >/dev/null 2>/dev/null $i && echo $i
done
;;
*)
for i in $(serv_list_all | cut -f 1 -d" ") ; do
is_service_autostart >/dev/null $i && echo $i
for i in $(short=1 serv_list_all) ; do
is_service_autostart >/dev/null 2>/dev/null $i && echo $i
done
;;
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