I'm having issues in setting up services that run with my user in Red Hat Enterprise Linux 8. To debug it I created a small shell script with:
/home/d608771/my_service.sh
With file permissions set as:
-rwxrwxrwx. 1 d608771 d608771 135 Sep 4 12:55 q.sh
And the contents are:
#!/usr/bin/env bash
filename="/home/d608771/tmp/hello-$(date +"%Y_%m_%d_%H-%M-%S").txt"
touch $filename
echo "Hello World" > $filename
Then I created this service:
/usr/lib/systemd/system/my_service.service
With file permissions set as
-rw-r--r--. 1 root root 347 Jan 20 2022 my_service.service
And the contents are:
[Unit]
Description=Service
[Service]
ExecStart=/home/d608771/my_service.sh
Type=oneshot
[Install]
WantedBy=default.target
But when I try to start the service:
systemctl --user daemon-reload
systemctl --user enable my_service.service
I get the following:
Failed to enable unit: Unit file my_service.service does not exist.
And then with this:
systemctl --user start my_service.service
I get:
Failed to start my_service.service: Unit my_service.service not found.
I also tried with sudo
:
sudo systemctl daemon-reload
sudo systemctl enable my_service.service
sudo systemctl start my_service.service
And I get this:
Job for my_service.service failed because the control process exited with error code.
See "systemctl status my_service.service" and "journalctl -xe" for details.
And then this:
Sep 04 14:12:52 GBUKSDV-l608771 systemd[1]: my_service.service: Changed dead -> failed
Sep 04 14:12:59 GBUKSDV-l608771 systemd[1]: my_service.service: Trying to enqueue job my_service.service/start/replace
Sep 04 14:12:59 GBUKSDV-l608771 systemd[1]: my_service.service: Installed new job my_service.service/start as 1092842
Sep 04 14:12:59 GBUKSDV-l608771 systemd[1]: my_service.service: Enqueued job my_service.service/start as 1092842
Sep 04 14:12:59 GBUKSDV-l608771 systemd[1]: my_service.service: Failed to set blkio.weight: No such file or directory
Sep 04 14:12:59 GBUKSDV-l608771 systemd[1]: my_service.service: Passing 0 fds to service
Sep 04 14:12:59 GBUKSDV-l608771 systemd[1]: my_service.service: About to execute: /home/d608771/my_service.sh
Sep 04 14:12:59 GBUKSDV-l608771 systemd[1]: my_service.service: Forked /home/d608771/my_service.sh as 540558
Sep 04 14:12:59 GBUKSDV-l608771 systemd[1]: my_service.service: Changed failed -> start
Sep 04 14:12:59 GBUKSDV-l608771 systemd[1]: Starting my_service service...
Sep 04 14:12:59 GBUKSDV-l608771 systemd[540558]: my_service.service: Executing: /home/d608771/my_service.sh
Sep 04 14:12:59 GBUKSDV-l608771 systemd[540558]: my_service.service: Failed to execute command: Permission denied
Sep 04 14:12:59 GBUKSDV-l608771 systemd[540558]: my_service.service: Failed at step EXEC spawning /home/d608771/my_service.sh: Permission denied
Sep 04 14:12:59 GBUKSDV-l608771 systemd[1]: my_service.service: Child 540558 belongs to my_service.service.
Sep 04 14:12:59 GBUKSDV-l608771 systemd[1]: my_service.service: Main process exited, code=exited, status=203/EXEC
Sep 04 14:12:59 GBUKSDV-l608771 systemd[1]: my_service.service: Failed with result 'exit-code'.
Any idea what can be wrong?