Reputation: 47
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.
Upvotes: 1
Views: 3622
Reputation: 1247
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.
Upvotes: 2