0
  1. I made a .sh file to run my c# service.
  2. Inside sh file folder setup is
#!/bin/bash
/usr/bin/dotnet /opt/aid-dotnet/publish/IncidentDetection.dll
  1. And My Service file is in

/etc/systemd/system

  1. Name of service is sharpradar.service
[Unit]
Description=CSHARPSERVICE

[Service]
Type=forking
ExecStart= dotnet IncidentDetection.dll
WorkingDirectory=/opt/aid-dotnet/netcoreapp3.1/
Restart=on-abort
RemainAfterExit=yes
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
Environment=AMQP_USERNAME=test
Environment=AMQP_PASSWORD=test123654
Environment=AMQP_HOST=192.168.2.181
Environment=AID_ID=3
Environment=ASPNETCORE_ENVIRONMENT=Development
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target
  1. But when I start my service I get this message
 systemctl status sharpradar.service

● cshradar.service - CSHARPSERVICE
     Loaded: loaded (/etc/systemd/system/cshradar.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Wed 2023-01-25 15:57:46 IST; 1h 22min ago
    Process: 20016 ExecStart=/usr/bin/dotnet IncidentDetection.dll (code=exited, status=0/SUCCESS)

Jan 25 15:56:37 aidmain-Standard-PC-i440FX-PIIX-1996 dotnet-example[20016]: 01/25/2023 15:56:37 [INF] Connected to
  configuration request queue.
Jan 25 15:56:37 aidmain-Standard-PC-i440FX-PIIX-1996 dotnet-example[20016]: 01/25/2023 15:56:37 [INF] Connected to
  congfiguraiton queue for AID_ID = 3.
Jan 25 15:56:37 aidmain-Standard-PC-i440FX-PIIX-1996 dotnet-example[20016]: 01/25/2023 15:56:37 [INF] Requesting
  configuration for AID_ID = 3.
Jan 25 15:56:37 aidmain-Standard-PC-i440FX-PIIX-1996 dotnet-example[20016]: 01/25/2023 15:56:37 [INF] Received new
  configuration.
Jan 25 15:56:37 aidmain-Standard-PC-i440FX-PIIX-1996 dotnet-example[20016]: 01/25/2023 15:56:37 [INF]
  {"printReceivedData":false,"ruleConstraints":{"SpeedTooHigh":{"MaximumAllowedSpeed":15>
Jan 25 15:56:37 aidmain-Standard-PC-i440FX-PIIX-1996 dotnet-example[20016]: 01/25/2023 15:56:37 [INF] Succesfully reloaded
  configuration.
Jan 25 15:56:38 aidmain-Standard-PC-i440FX-PIIX-1996 dotnet-example[20016]: 01/25/2023 15:56:38 [INF] Start waiting for
  data.
Jan 25 15:56:38 aidmain-Standard-PC-i440FX-PIIX-1996 systemd[1]: Started CSHARPSERVICE.
Jan 25 15:57:46 aidmain-Standard-PC-i440FX-PIIX-1996 systemd[1]: cshradar.service: Succeeded.
Jan 25 15:57:46 aidmain-Standard-PC-i440FX-PIIX-1996 systemd[1]: Stopped CSHARPSERVICE.
  1. The service becomes dead when my C# service wait for data and get freeze at http request.
  2. But if I run this code directly inside tmux then it run properly, but not with systemd, I am unable to understand this.
  3. I am attaching screenshot of running example using tmux(Sorry for attacing this screenshot because its not getting formatted on stack overflow)

Successfully Run Using tmux

  1. I tried multiple different aspects to run but still showing dead when I use systemd.
  • Is it because you have specified `forking` as the type? Maybe try `Type=oneshot`? – DavidG Jan 24 '23 at 10:12
  • No onshot I Tried and forking is to let service wait for data only – Utkarsh Mishra Jan 24 '23 at 10:28
  • Does your service _actually_ fork to background (daemonize)? It doesn't look like it does. In your PuTTY screenshot it stays in foreground, so Type=forking would not be suitable. – user1686 Feb 04 '23 at 13:11

0 Answers0