diff --git a/cleanup.sh b/cleanup.sh index 8caf21d..056fd26 100755 --- a/cleanup.sh +++ b/cleanup.sh @@ -3,11 +3,10 @@ set -ue -o pipefail run_launchd() { - FILEPATH="$HOME/Library/LaunchAgents/com.hetzner.cloud.k8sdev.registry-port-forward.plist" - launchctl unload "$FILEPATH" 2> /dev/null || true - rm -f "$FILEPATH" + label="k8s-registry-port-forward" + launchctl remove "$label" 2> /dev/null || true } -if which launchctl > /dev/null; then +if command -v launchctl > /dev/null; then run_launchd fi diff --git a/registry-port-forward.sh b/registry-port-forward.sh index 15c47d4..f9cf14c 100755 --- a/registry-port-forward.sh +++ b/registry-port-forward.sh @@ -18,50 +18,19 @@ run_systemd() { } run_launchd() { - FILEPATH="$HOME/Library/LaunchAgents/com.hetzner.cloud.k8sdev.registry-port-forward.plist" + label="k8s-registry-port-forward" - cat > "$FILEPATH" < - - - - Label - com.hetzner.cloud.k8sdev.registry-port-forward.plist - Program - $(which kubectl) - ProgramArguments - - kubectl - port-forward - -n - kube-system - svc/docker-registry - 30666:5000 - - EnvironmentVariables - - KUBECONFIG - $PWD/files/kubeconfig.yaml - - RunAtLoad - - KeepAlive - - SuccessfulExit - - - ThrottleInterval - 5 - - -EOF + launchctl remove "$label" 2> /dev/null || true - launchctl load "$FILEPATH" + launchctl submit \ + -l "$label" \ + -p "$(which kubectl)" \ + -- kubectl --kubeconfig="$PWD/files/kubeconfig.yaml" port-forward -n kube-system svc/docker-registry 30666:5000 } -if which systemctl > /dev/null; then +if command -v systemctl > /dev/null; then run_systemd -elif which launchctl > /dev/null; then +elif command -v launchctl > /dev/null; then run_launchd else echo "No supported init system found"