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() { ...@@ -33,10 +33,9 @@ usage() {
echo 'options:' echo 'options:'
echo ' -h: this help' >&2 echo ' -h: this help' >&2
echo ' -r: restart services' >&2 echo ' -r: restart services' >&2
echo ' -l: list systemd commands to execute' >&2
echo ' -R: reload services' >&2 echo ' -R: reload services' >&2
echo " -n: don't call systemd daemon-reload" >&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 echo " -v: verbose mode" >&2
exit 1 exit 1
} }
...@@ -45,8 +44,8 @@ while getopts 'hrlRnv' opt; do ...@@ -45,8 +44,8 @@ while getopts 'hrlRnv' opt; do
case $opt in case $opt in
r) systemd_cmd='restart';; r) systemd_cmd='restart';;
R) systemd_cmd='reload';; R) systemd_cmd='reload';;
n) daemon_reload=false;; n) no_reload=1;;
N) show_failed=false;; N) no_status=1;;
l) list=true;; l) list=true;;
v) verbose=true;; v) verbose=true;;
*) usage;; *) usage;;
...@@ -55,18 +54,21 @@ done ...@@ -55,18 +54,21 @@ done
shift $((OPTIND - 1)); shift $((OPTIND - 1));
(( $# > 0 )) && usage (( $# > 0 )) && usage
[[ -n "$systemd_cmd" || -n "$list" ]] || usage # reload units list
[[ -z $no_reload ]] && systemctl --system daemon-reload
[[ $daemon_reload ]] || systemctl --system daemon-reload
# list of running services # list of running services
declare -a services declare -a services
services=($(systemctl -t service --full|grep \.service|grep running|sed -rn 's/^(.*\.service).*/\1/p')) 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 for svc in "${services[@]}"; do
pid=$(systemctl show "$svc"|sed -nr 's/^MainPID=(.*)/\1/p') 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) deleted=$(grep '(deleted)' "/proc/$pid/maps"|sed -nr 's|^\S+ ..x. \S+ \S+ \S+ \s+||p'|sort|uniq)
if [[ -n $deleted ]]; then if [[ -n $deleted ]]; then
needy+=("$svc")
if [[ $verbose ]]; then if [[ $verbose ]]; then
echo "${c_title}Service:${c_svc} $svc${c_rst}" echo "${c_title}Service:${c_svc} $svc${c_rst}"
echo "${c_title}Pid:${c_rst} $pid" echo "${c_title}Pid:${c_rst} $pid"
...@@ -84,7 +86,15 @@ for svc in "${services[@]}"; do ...@@ -84,7 +86,15 @@ for svc in "${services[@]}"; do
done done
wait wait
# show failed units # show units status
[[ $systemd_cmd && $show_failed ]] && systemctl --failed --all 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 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