summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2012-12-29 22:04:52 +0100
committerJouke Witteveen <j.witteveen@gmail.com>2012-12-29 22:04:52 +0100
commit7ae917a0ea8517ff0ffe03d3884aee64cd7dcfcd (patch)
tree38d2274ac4856cde5f736a3385a6abe6faeeb6e5
parentf3861be3d170e5c29f764285f6ad10ef317b0261 (diff)
downloadnetctl-7ae917a0ea8517ff0ffe03d3884aee64cd7dcfcd.tar.gz
netctl-7ae917a0ea8517ff0ffe03d3884aee64cd7dcfcd.tar.xz
Don't call systemctl if there's nothing to do
When starting/stopping multiple profiles, check whether we don't try to start/stop no profiles at all.
-rwxr-xr-xsrc/netctl11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/netctl b/src/netctl
index 524d03b..897f648 100755
--- a/src/netctl
+++ b/src/netctl
@@ -44,15 +44,18 @@ store() {
restore() {
if [[ ! -r $STATE_FILE ]]; then
exit_error "Could not read state file '$STATE_FILE'"
+ elif [[ ! -s $STATE_FILE ]]; then
+ report_debug "No profiles to restore in state file '$STATE_FILE'"
+ else
+ mapfile -t Units < "$STATE_FILE"
+ do_debug systemctl start "${Units[@]}"
fi
- mapfile -t Units < "$STATE_FILE"
- do_debug systemctl start "${Units[@]}"
}
stop_all() {
# We cannot pipe to mapfile, as the end of a pipe is inside a subshell
mapfile -t Profiles < <(list_profiles)
- do_debug systemctl stop "${Profiles[@]/#/netctl@}" 2> \
+ [[ $Profiles ]] && do_debug systemctl stop "${Profiles[@]/#/netctl@}" 2> \
>(grep -Fv "not loaded" >&2)
}
@@ -70,7 +73,7 @@ switch_to() {
fi
mapfile -t AllProfiles < <(list_profiles)
mapfile -t Profiles < <(grep -Fl "$InterfaceLine" "${AllProfiles[@]}")
- do_debug systemctl stop "${Profiles[@]/#/netctl@}" 2> \
+ [[ $Profiles ]] && do_debug systemctl stop "${Profiles[@]/#/netctl@}" 2> \
>(grep -Fv "not loaded" >&2)
do_debug systemctl start "netctl@$1"
}