diff options
author | Jouke Witteveen <j.witteveen@gmail.com> | 2012-12-29 22:04:52 +0100 |
---|---|---|
committer | Jouke Witteveen <j.witteveen@gmail.com> | 2012-12-29 22:04:52 +0100 |
commit | 7ae917a0ea8517ff0ffe03d3884aee64cd7dcfcd (patch) | |
tree | 38d2274ac4856cde5f736a3385a6abe6faeeb6e5 /src | |
parent | f3861be3d170e5c29f764285f6ad10ef317b0261 (diff) | |
download | netctl-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.
Diffstat (limited to 'src')
-rwxr-xr-x | src/netctl | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -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" } |