Skip to content
Snippets Groups Projects
Commit 1edbaf56 authored by Seblu's avatar Seblu
Browse files

checkservices: more systemd informations

parent 86b1ed43
No related branches found
No related tags found
No related merge requests found
......@@ -33,10 +33,9 @@ usage() {
echo 'options:'
echo ' -h: this help' >&2
echo ' -r: restart services' >&2
echo ' -l: list systemd commands to execute' >&2
echo ' -R: reload services' >&2
echo " -n: don't call systemd daemon-reload" >&2
echo " -N: don't display failed units after restart/reload" >&2
echo " -N: don't display status of restart/reload units" >&2
echo " -v: verbose mode" >&2
exit 1
}
......@@ -45,8 +44,8 @@ while getopts 'hrlRnv' opt; do
case $opt in
r) systemd_cmd='restart';;
R) systemd_cmd='reload';;
n) daemon_reload=false;;
N) show_failed=false;;
n) no_reload=1;;
N) no_status=1;;
l) list=true;;
v) verbose=true;;
*) usage;;
......@@ -55,18 +54,21 @@ done
shift $((OPTIND - 1));
(( $# > 0 )) && usage
[[ -n "$systemd_cmd" || -n "$list" ]] || usage
[[ $daemon_reload ]] || systemctl --system daemon-reload
# reload units list
[[ -z $no_reload ]] && systemctl --system daemon-reload
# list of running services
declare -a services
services=($(systemctl -t service --full|grep \.service|grep running|sed -rn 's/^(.*\.service).*/\1/p'))
# beggar count
declare -a needy=()
for svc in "${services[@]}"; do
pid=$(systemctl show "$svc"|sed -nr 's/^MainPID=(.*)/\1/p')
deleted=$(grep '(deleted)' "/proc/$pid/maps"|sed -nr 's|^\S+ ..x. \S+ \S+ \S+ \s+||p'|sort|uniq)
if [[ -n $deleted ]]; then
needy+=("$svc")
if [[ $verbose ]]; then
echo "${c_title}Service:${c_svc} $svc${c_rst}"
echo "${c_title}Pid:${c_rst} $pid"
......@@ -84,7 +86,15 @@ for svc in "${services[@]}"; do
done
wait
# show failed units
[[ $systemd_cmd && $show_failed ]] && systemctl --failed --all
# show units status
if [[ -z $no_status && $systemd_cmd && ${needy[*]} ]]; then
systemctl --lines=0 status "${needy[@]}"
fi
if [[ $verbose ]]; then
systemctl --failed --all --no-pager --full list-units
else
systemctl --failed --all --no-pager --no-legend --full list-units
fi
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment