I have a Golang application which already compiled on local and pushed to production server, but when I tried to set it up with systemd service it keeps getting permission denied error, even though I’m using root user and is the owner of the whole application folder and subfolders.
My application is on folder path “/home/my-user/app/src/my-app-api” which consists of the compiled app “my_api” (unix executable file) and an .env.
/etc/systemd/system/my_api.service
[Unit]
Description=APP API
After=network.target
[Service]
User=root
Group=root
ExecStart=/home/my-user/app/src/my-app-api/my_api
WorkingDirectory=/home/my-user/app/src/my-app-api
EnvironmentFile=/home/my-user/app/src/my-app-api/.env
[Install]
WantedBy=multi-user.target
when I ran “sudo systemctl start my_api.service” it always returns this error in “systemctl status my_api.service”
May 17 06:07:57 websitename systemd[1]: my_api.service: Failed to load environment files: Permission denied
May 17 06:07:57 websitename systemd[1]: my_api.service: Failed to run 'start' task: Permission denied
May 17 06:07:57 websitename systemd[1]: my_api.service: Failed with result 'resources'.
May 17 06:07:57 websitename systemd[1]: Failed to start APP API.
I have used chmod 777 -R to the app folder and contents and .env and the my_api.service file. Tried using sudo or non sudo, with root user or other user, folder and files belong to user root and group root, but still experiencing this error. What is possibly causing this and how to fix this? Thank you in advance.