Ivolution
Ivolution

Reputation: 21

How can i create a Service for a dotnet application

I need help to create a service for a aspnetcore application on linux. I developed and created a app which runs when i start it with ./Application. But if I create a Service it fails.

Status results in:

● alphabot.service - AlphaBot Service
     Loaded: loaded (/etc/systemd/system/alphabot.service; enabled; vendor preset: enabled)
     Active: failed (Result: core-dump) since Tue 2021-06-29 18:03:32 UTC; 1s ago
    Process: 5014 ExecStart=/home/alphabot/AlphaBot (code=dumped, signal=ABRT)
   Main PID: 5014 (code=dumped, signal=ABRT)

Jun 29 18:03:31 rootserver AlphaBot[5014]:    at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
Jun 29 18:03:31 rootserver AlphaBot[5014]:    at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
Jun 29 18:03:31 rootserver AlphaBot[5014]:    at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
Jun 29 18:03:31 rootserver AlphaBot[5014]:    at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
Jun 29 18:03:31 rootserver AlphaBot[5014]:    at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
Jun 29 18:03:31 rootserver AlphaBot[5014]:    at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
Jun 29 18:03:31 rootserver AlphaBot[5014]:    at Microsoft.Extensions.Hosting.HostBuilder.Build()
Jun 29 18:03:31 rootserver AlphaBot[5014]:    at AlphaBot.Program.Main(String[] args) in /root/TeamCity/buildAgent/work/f2d58114a4881b14/AlphaBot/Program.cs:line 10
Jun 29 18:03:32 rootserver systemd[1]: alphabot.service: Main process exited, code=dumped, status=6/ABRT
Jun 29 18:03:32 rootserver systemd[1]: alphabot.service: Failed with result 'core-dump'.

alphabot.service:

[Unit]
Description=AlphaBot Service

[Service]
Type=simple
ExecStart=/home/alphabot/AlphaBot

[Install]
WantedBy=multi-user.target

Upvotes: 1

Views: 1938

Answers (2)

Husseinfo
Husseinfo

Reputation: 492

Service is working fine, but your application is throwing an error itself.

Run journalctl -u alphabot -f, restart service and watch the terminal. It might be a busy port, config file...

Upvotes: 1

Ivolution
Ivolution

Reputation: 21

[Unit]
Description=AlphaBot Service

[Service]
Type=simple
ExecStart=/usr/bin/dotnet /home/alphabot/AlphaBot.dll

[Install]
WantedBy=multi-user.target

results in

● alphabot.service - AlphaBot Service
     Loaded: loaded (/etc/systemd/system/alphabot.service; enabled; vendor preset: enabled)
     Active: failed (Result: core-dump) since Tue 2021-06-29 18:15:28 UTC; 872ms ago
    Process: 5257 ExecStart=/usr/bin/dotnet /home/alphabot/AlphaBot.dll (code=dumped, signal=ABRT)
   Main PID: 5257 (code=dumped, signal=ABRT)

Jun 29 18:15:27 rootserver dotnet[5257]:    at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
Jun 29 18:15:27 rootserver dotnet[5257]:    at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
Jun 29 18:15:27 rootserver dotnet[5257]:    at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
Jun 29 18:15:27 rootserver dotnet[5257]:    at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
Jun 29 18:15:27 rootserver dotnet[5257]:    at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
Jun 29 18:15:27 rootserver dotnet[5257]:    at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
Jun 29 18:15:27 rootserver dotnet[5257]:    at Microsoft.Extensions.Hosting.HostBuilder.Build()
Jun 29 18:15:27 rootserver dotnet[5257]:    at AlphaBot.Program.Main(String[] args) in /root/TeamCity/buildAgent/work/f2d58114a4881b14/AlphaBot/Program.cs:line 10
Jun 29 18:15:28 rootserver systemd[1]: alphabot.service: Main process exited, code=dumped, status=6/ABRT
Jun 29 18:15:28 rootserver systemd[1]: alphabot.service: Failed with result 'core-dump'.

Upvotes: 1

Related Questions