-
Notifications
You must be signed in to change notification settings - Fork 0
/
servtoggle.sh
executable file
·35 lines (35 loc) · 1.04 KB
/
servtoggle.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh
# toggles all listed services with killall and exec
alias notify='notify-send -u normal -t 1000'
eval 'set -- '$(getopt -o 'qp' -- "$@")
while true; do
[ "$1" = "-q" ] && q=true && shift
[ "$1" = "-p" ] && pause=true && shift
[ "$1" = "--" ] && shift && break
done
i=1
if ! [ $pause ]; then
for service in "$@"; do
base="$(echo "$service" | cut -d ' ' -f 1)"
if pgrep -x "$base"; then
[ $q ] || notify -r $i "Killing $service ..." &
killall -s 1 "$base" && ( [ $q ] || notify -r $i "Killed:" "$service" )
else
[ $q ] || notify -r $i "Starting $service" &
exec $service &
fi
i=$(($i + 1))
done
else
for service in "$@"; do
base="$(echo "$service" | cut -d ' ' -f 1)"
if ps -o stat= $(pgrep -xn "$base") | grep '^T' >/dev/null; then
[ $q ] || notify -r $i "Resuming $service ..." &
killall -s CONT "$base" && ( [ $q ] || notify -r $i "Resumed:" "$service" )
else
[ $q ] || notify -r $i "Pausing $service" &
killall -s STOP "$base" && ( [ $q ] || notify -r $i "Paused:" "$service" )
fi
i=$(($i + 1))
done
fi