From 4dd188eba6c17e336ad130bf64712db4aa68dc11 Mon Sep 17 00:00:00 2001 From: Ben de Roo Date: Tue, 24 Mar 2026 19:59:19 +0100 Subject: [PATCH] Update src/killsw --- src/killsw | 69 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/src/killsw b/src/killsw index 803f492..890938c 100644 --- a/src/killsw +++ b/src/killsw @@ -1,18 +1,38 @@ #!/bin/bash -VERSION="1.0.1" +VERSION="1.1.0" cmd="$1" group="$2" +add_service_to_group() { + service="$1" + group="$2" + + # Maak de groep-target aan als die nog niet bestaat + if [[ ! -f "/etc/systemd/system/${group}.target" ]]; then + sudo tee "/etc/systemd/system/${group}.target" > /dev/null < + killsw [group] COMMANDS: - stop Stop all services linked to killswitch.target - start Start all services linked to killswitch.target - status Show the current status of the killswitch target - add [service] to [name] adds services to different groups. (not doing anything at the moment) + stop Stop all services linked to killswitch.target, or a specific group + start Start all services linked to killswitch.target, or a specific group + status Show the current status of killswitch.target or a group + add [service] to [group] Add a service to a group (creates group-target if needed) -h, --help Show this help message -v, --version Show version information ABOUT KILLSWITCH: What it does: - Stops all services that are linked to 'killswitch.target'. This allows - you to perform an emergency stop or centralized management of multiple - services. + Stops or starts services linked to 'killswitch.target'. Supports groups for partial control. - Why it's needed: - Useful for quickly stopping servers or services in case of maintenance, - emergency, or to prevent unsafe operations. - - How to enable it on your services: - 1) Create or edit your systemd service to link it to killswitch.target: - Add the following to your [Unit] section: - PartOf=killswitch.target - 2) Optionally, enable the service to start at boot: + How to link services: + 1) Edit your systemd service and add: + PartOf=.target + 2) Enable the service for boot: sudo systemctl enable .service - 3) Start/stop via this script: - killsw start - killsw stop + 3) Use killsw script to manage: + killsw start [group] + killsw stop [group] EOF ;; -v|--version) @@ -78,4 +95,4 @@ EOF *) echo "Ahoy, matey! No command provided. Check --help for guidance." ;; -esac +esac \ No newline at end of file