0

I created a worker service in .net core 6 like example here and deployed it in Centos. its unit is like

[Unit]
Description=my test app

[Service]
Type=notify
ExecStart=/usr/bin/DaneshAfzar

[Install]
WantedBy=multi-user.target

systemctl start DaneshAfzar.service raises an error : Job for DaneshAfzar.service failed because the control process exited with error code. see "systemctl status DaneshAfzar.service" and "journalctl -xe" for details

output of journalctl -xe : Failed at step EXEC spawning /usr/bin/DaneshAfzar: Permission Denied

I used chmod 777 for the whole directory but error persists.

  • Try to start the process from `/usr/local/bin` (copy binaries to there instead of `/usr/bin`). – Maroun Mar 30 '22 at 07:58
  • @Maroun No change. I still get the error – Ehsan Sadeghi Mar 30 '22 at 08:10
  • 1
    what do you mean by *chmod 777 for the whole directory*? Type the exact command you used. Side note: It would be better to do `sudo chmod 755 /usr/bin/DaneshAfzar` – Andy Mar 30 '22 at 22:49

1 Answers1

1

Let's asume the service ist called myservice. I think it is better to deploy your .net service to the /opt/myservice directory or to /usr/local/myservice .

Then the structure would look like this:

# Folder path
/opt/myservice

# path of the executable
/opt/myservice/myservice 
# or 
/opt/myservice/myservice.dll

only the file /opt/myservice/myservice.dll must be executable

A service file then could be like this:

[Unit]
Description=IG Render Service

[Service]
WorkingDirectory=/opt/myservice
ExecStart=/usr/bin/dotnet myservice.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=myservice
# Optionaly define a specific user to run the service
# User=someuser
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

hope this helps.

frank
  • 1,217
  • 2
  • 10
  • 18