CodexBloom - Programming Q&A Platform

Strange behavior with systemd service not starting after reboot on Debian 11

πŸ‘€ Views: 97 πŸ’¬ Answers: 1 πŸ“… Created: 2025-05-31
systemd debian linux bash

I'm deploying to production and I can't seem to get I'm converting an old project and I've been working on this all day and This might be a silly question, but I'm experiencing an scenario where my custom systemd service doesn't start automatically after a reboot on my Debian 11 server....... I've created a service file located at `/etc/systemd/system/my-service.service` with the following content: ```ini [Unit] Description=My Custom Service After=network.target [Service] ExecStart=/usr/bin/my-script.sh Restart=always User=myuser [Install] WantedBy=multi-user.target ``` I ran `systemctl daemon-reload` after creating the service file, and I enabled it using `systemctl enable my-service`. However, after rebooting the server, I noticed that the service is not running. When I check the status with `systemctl status my-service`, I see the following behavior message: ``` ● my-service.service - My Custom Service Loaded: loaded (/etc/systemd/system/my-service.service; enabled; vendor preset: enabled) Active: inactive (dead) since Thu 2023-10-01 10:00:00 UTC; 5s ago Process: 1234 ExecStart=/usr/bin/my-script.sh (code=exited, status=203/EXEC) ``` The exit status `203/EXEC` indicates that the executable could not be executed. I confirmed that the script `/usr/bin/my-script.sh` exists and is executable (permissions are `rwxr-xr-x`). I also tried running the script manually and it executes without issues. To troubleshoot further, I checked the logs with `journalctl -u my-service` and found: ``` Oct 01 10:00:00 my-server systemd[1]: Started My Custom Service. Oct 01 10:00:00 my-server my-service[1234]: /usr/bin/my-script.sh: line 1: syntax behavior: unexpected token ``` It seems like there’s some scenario with the environment when the script runs as a service. My script uses `bash`, but the shebang at the top is `#!/bin/bash`. I’ve also tried adding `Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin` under the `[Service]` section and it still doesn't work. Is there any missing configuration or detail I'm overlooking that might be causing my service to unexpected result on startup? Any guidance would be greatly appreciated. Any ideas what could be causing this? Any ideas how to fix this? Is there a simpler solution I'm overlooking? Am I missing something obvious? How would you solve this? I'm working with Bash in a Docker container on Windows 11. Is there a simpler solution I'm overlooking?