Update src/killsw
This commit is contained in:
67
src/killsw
67
src/killsw
@@ -1,18 +1,38 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
VERSION="1.0.1"
|
VERSION="1.1.0"
|
||||||
|
|
||||||
cmd="$1"
|
cmd="$1"
|
||||||
group="$2"
|
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 <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=Group target $group
|
||||||
|
PartOf=killswitch.target
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Zorg dat de .wants map bestaat
|
||||||
|
sudo mkdir -p "/etc/systemd/system/${group}.target.wants"
|
||||||
|
|
||||||
|
# Voeg de service toe aan de groep
|
||||||
|
sudo ln -sf "/etc/systemd/system/${service}.service" "/etc/systemd/system/${group}.target.wants/${service}.service"
|
||||||
|
|
||||||
|
echo "Added service '$service' to group '$group'."
|
||||||
|
}
|
||||||
|
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
stop)
|
stop)
|
||||||
if [[ -n "$group" ]]; then
|
if [[ -n "$group" ]]; then
|
||||||
# Alleen die groep stoppen
|
|
||||||
systemctl stop "$group".target
|
systemctl stop "$group".target
|
||||||
echo "Killswitch activated: stopped group '$group'."
|
echo "Killswitch activated: stopped group '$group'."
|
||||||
else
|
else
|
||||||
# Geen groep, alles stoppen
|
|
||||||
systemctl stop killswitch.target
|
systemctl stop killswitch.target
|
||||||
echo "Killswitch activated: all linked services have been stopped."
|
echo "Killswitch activated: all linked services have been stopped."
|
||||||
fi
|
fi
|
||||||
@@ -27,11 +47,15 @@ case "$cmd" in
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
status)
|
status)
|
||||||
systemctl status killswitch.target
|
if [[ -n "$group" ]]; then
|
||||||
|
systemctl status "$group".target
|
||||||
|
else
|
||||||
|
systemctl status killswitch.target
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
add)
|
add)
|
||||||
if [[ -n "$2" && "$3" == "to" && -n "$4" ]]; then
|
if [[ -n "$2" && "$3" == "to" && -n "$4" ]]; then
|
||||||
echo "Adding service '$2' to group '$4'..."
|
add_service_to_group "$2" "$4"
|
||||||
else
|
else
|
||||||
echo "Usage: killsw add [service] to [group]"
|
echo "Usage: killsw add [service] to [group]"
|
||||||
fi
|
fi
|
||||||
@@ -41,35 +65,28 @@ case "$cmd" in
|
|||||||
KillSwitch CLI Tool - v$VERSION
|
KillSwitch CLI Tool - v$VERSION
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
killsw <command>
|
killsw <command> [group]
|
||||||
|
|
||||||
COMMANDS:
|
COMMANDS:
|
||||||
stop Stop all services linked to killswitch.target
|
stop Stop all services linked to killswitch.target, or a specific group
|
||||||
start Start all services linked to killswitch.target
|
start Start all services linked to killswitch.target, or a specific group
|
||||||
status Show the current status of the killswitch target
|
status Show the current status of killswitch.target or a group
|
||||||
add [service] to [name] adds services to different groups. (not doing anything at the moment)
|
add [service] to [group] Add a service to a group (creates group-target if needed)
|
||||||
-h, --help Show this help message
|
-h, --help Show this help message
|
||||||
-v, --version Show version information
|
-v, --version Show version information
|
||||||
|
|
||||||
ABOUT KILLSWITCH:
|
ABOUT KILLSWITCH:
|
||||||
What it does:
|
What it does:
|
||||||
Stops all services that are linked to 'killswitch.target'. This allows
|
Stops or starts services linked to 'killswitch.target'. Supports groups for partial control.
|
||||||
you to perform an emergency stop or centralized management of multiple
|
|
||||||
services.
|
|
||||||
|
|
||||||
Why it's needed:
|
How to link services:
|
||||||
Useful for quickly stopping servers or services in case of maintenance,
|
1) Edit your systemd service and add:
|
||||||
emergency, or to prevent unsafe operations.
|
PartOf=<group>.target
|
||||||
|
2) Enable the service for boot:
|
||||||
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:
|
|
||||||
sudo systemctl enable <your-service>.service
|
sudo systemctl enable <your-service>.service
|
||||||
3) Start/stop via this script:
|
3) Use killsw script to manage:
|
||||||
killsw start
|
killsw start [group]
|
||||||
killsw stop
|
killsw stop [group]
|
||||||
EOF
|
EOF
|
||||||
;;
|
;;
|
||||||
-v|--version)
|
-v|--version)
|
||||||
|
|||||||
Reference in New Issue
Block a user