Okay, the systemctl status output indicates a problem with the execution of your script. Specifically, the (code=exited, status=203/EXEC) message means that the system couldn't find the executable specified in the ExecStart line of your service file. In this case, it's failing to find /usr/local/bin/dynamic_cpu_load.sh.
Here's how to troubleshoot and fix this:
Verify the script's location:
Double-check where you saved the script. Is it actually located at /usr/local/bin/dynamic_cpu_load.sh? Use ls -l /usr/local/bin/dynamic_cpu_load.sh to confirm. If it's not there, you'll need to move it to the correct location.
Check the service file:
Examine your service file (/etc/systemd/system/dynamic-cpu-loader.service). Make sure the ExecStart line correctly points to the script's location. It should look like this:
code
ExecStart=/usr/local/bin/dynamic_cpu_load.sh
Permissions:
Ensure the script has execute permissions. Run:
bash
sudo chmod +x /usr/local/bin/dynamic_cpu_load.sh
Shebang:
The script must start with a shebang line that tells the system how to execute it. Your script already has this:
bash
#!/bin/bash
Make sure this line is present and correct.
Reload systemd:
After making changes to the service file, reload systemd to apply the changes:
bash
sudo systemctl daemon-reload
Restart the service:
Finally, try restarting the service:
bash
sudo systemctl start dynamic-cpu-loader.service
Check the status again:
bash
sudo systemctl status dynamic-cpu-loader.service
Look for any errors in the output. If it still fails, the output might provide more clues.
Example Service File (/etc/systemd/system/dynamic-cpu-loader.service):
code
[Unit]
Description=Dynamic CPU Load Manager to Prevent OCI VM Deletion
After=network.target
[Service]
Type=simple
User=root # Or a less privileged user if appropriate
ExecStart=/usr/local/bin/dynamic_cpu_load.sh
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
Troubleshooting Steps if it still fails:
Check the system logs: Use journalctl -xe to view the system logs for more detailed error messages. Look for entries related to your service.
Run the script manually: Try running the script directly from the command line: sudo /usr/local/bin/dynamic_cpu_load.sh. This will help you identify any errors that occur during script execution. Pay attention to any error messages that are printed to the console.
Let me know if you've checked these steps and are still encountering problems. Provide the output of ls -l /usr/local/bin/dynamic_cpu_load.sh and the contents of your /etc/systemd/system/dynamic-cpu-loader.service file if you're still stuck.