My systemd service logs the following line: pre-shutdown.service: Unable to locate executable '/usr/local/bin/pre-shutdown.sh': Permission denied
Assistant
This error indicates that systemd can't execute your /usr/local/bin/pre-shutdown.sh script due to permission issues. Here are the most likely causes and solutions:
Check if the file exists and has execute permissions:
bash
ls -la /usr/local/bin/pre-shutdown.sh
If the file exists but lacks execute permissions:
bash
sudo chmod +x /usr/local/bin/pre-shutdown.sh
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
If you're using SELinux, it might be blocking execution:
bash
sudo restorecon /usr/local/bin/pre-shutdown.sh
The filesystem might be mounted with noexec. Check with:
bash
mount | grep /usr/local
Verify your service file configuration:
Make sure your systemd service file has the correct path and that the ExecStart or ExecStop directive points to the right location.
What does ls -la /usr/local/bin/pre-shutdown.sh show you?
User
How do I create a systemd script that runs on shutdown/reboot and is awaited upon
Assistant
To create a systemd service that runs during shutdown/reboot and blocks the shutdown process until it completes, you'll need to create both the script and the service file.
1. Create your shutdown script:
bash
sudo nano /usr/local/bin/pre-shutdown.sh
Add your shutdown logic:
bash
#!/bin/bash
# Your shutdown tasks here
echo "Running pre-shutdown tasks..."
# Example: backup, cleanup, notifications, etc.
sleep 5 # Simulate work
echo "Pre-shutdown tasks completed"