-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit-demon
38 lines (28 loc) · 1.01 KB
/
edit-demon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# Check if the correct number of arguments is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <service-name>"
exit 1
fi
# Assign the service name from the argument
SERVICE_NAME=$1
# Define the path to the systemd service file
SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"
# Check if the service file exists
if [ ! -f "$SERVICE_FILE" ]; then
echo "Error: The service '$SERVICE_NAME' does not exist."
exit 2
fi
# Open the systemd service file in a text editor (nano or vim)
echo "Opening the service file for editing: $SERVICE_FILE"
sudo nano $SERVICE_FILE
# After editing, reload systemd to apply the changes
echo "Reloading systemd..."
sudo systemctl daemon-reload
# Restart the service to apply the new configuration
echo "Restarting the service: $SERVICE_NAME"
sudo systemctl restart $SERVICE_NAME
# Check the status of the service after restart
echo "Checking service status..."
sudo systemctl status $SERVICE_NAME
echo "Daemon '$SERVICE_NAME' has been successfully edited and restarted."