gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
Make concise instructions for how to have a script be run by systemd in Debian right…
- User
Make concise instructions for how to have a script be run by systemd in Debian right before shutting down.
- Assistant
To have a script run by systemd in Debian right before shutting down, follow these concise instructions:
-
Create a systemd service unit file:
- Open a terminal.
- Use a text editor (e.g., nano, vim) to create a new service unit file:
sudo nano /etc/systemd/system/script.service
-
Add the following lines to the newly created service unit file:
[Unit] Description=Run script before shutting down DefaultDependencies=no Before=shutdown.target [Service] Type=oneshot ExecStart=/path/to/your/script.sh RemainAfterExit=true [Install] WantedBy=shutdown.targetReplace
/path/to/your/script.shwith the actual path of your script. -
Save the changes to the service unit file and exit the text editor.
-
Reload systemd daemon and enable the new service:
sudo systemctl daemon-reload sudo systemctl enable script.service -
Test the service by manually shutting down your system, or you can simulate a shutdown using the command:
sudo systemctl start shutdown.target
-