0

I'm running a ASP.net Core 2.0 on my raspberry Pi, called IoTServer, for homeautomation.

It runs fine, on port 5003, when I start it manually.

> pi@raspberrypi:~/Programs/iotserver $ ./IoTServer Hosting environment:
> Production Content root path: /home/pi/Programs/iotserver Now
> listening on: http://[::]:5003 Application started. Press Ctrl+C to
> shut down.

However, once I move it to a service, it still seems to start up fine, without any errors, but it can no longer be reached on 127.0.0.1:5003 or via LAN.

How can I debug this? I've tried different user pi and root, but no difference.

I use the systemmd style of running it.

[Unit]
Description=IoTServer
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/home/pi/Programs/iotserver
ExecStart=/home/pi/Programs/iotserver/IoTServer
Restart=always

[Install]
WantedBy=multi-user.target

When I check the status of the service it shows:

   pi@raspberrypi:~ $ service iotserver status
● iotserver.service - IoTserver
   Loaded: loaded (/etc/systemd/system/iotserver.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-08-16 19:09:18 CEST; 4min 40s ago
 Main PID: 445 (IoTServer)
   CGroup: /system.slice/iotserver.service
           └─445 /home/pi/Programs/iotserver/IoTServer

Aug 16 19:10:11 raspberrypi IoTServer[445]: info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
Aug 16 19:10:11 raspberrypi IoTServer[445]:       User profile is available. Using '/root/.local/share/ASP.NET/DataProtection-Keys' as key repository; keys wil
Aug 16 19:10:17 raspberrypi IoTServer[445]: Hosting environment: Production
Aug 16 19:10:17 raspberrypi IoTServer[445]: Content root path: /
Aug 16 19:10:17 raspberrypi IoTServer[445]: Now listening on: http://[::]:5003
Aug 16 19:10:17 raspberrypi IoTServer[445]: Application started. Press Ctrl+C to shut down.
Aug 16 19:13:38 raspberrypi IoTServer[445]: info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Aug 16 19:13:38 raspberrypi IoTServer[445]:       Request starting HTTP/1.1 GET http://192.168.1.100:5003/
Aug 16 19:13:40 raspberrypi IoTServer[445]: info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Aug 16 19:13:40 raspberrypi IoTServer[445]:       Request finished in 1975.3237ms 404

Edit: It does seem to receive and process the request, but it is not fed back to the requestor.

  • 2
    You seem to run it as user pi from the command line, but as root when using the service. That could mean an different environment. Try User=pi and Group=pi in the service file – Dirk Aug 16 '18 at 7:12
  • Thank you - but that does not seem to change it, alas. Seems it's not allowed to receive webcalls, or it doesn't register the port, when running as service – Vincent Aug 16 '18 at 16:12
1

You should add the statement to the [Unit] section:

Wants=network.target

If it does not help instead you can try to use:

Wants=network-online.target
After=network-online.target

But this should only be used if really needed because it may slow down bootup.

I have just answered a question why you should use Wants=: Service failing to wait for internet connection.

When using systemd you should also use its native commands, e.g. for the status:

rpi ~$ systemctl status iotserver.service
rpi ~$ journalctl --unit=iotserver.service

or just everything with:

rpi ~$ journalctl -e -x   # you may omit -x

Because the server is running but without connection I suppose it initializes its interfaces on startup and doesn't care if they are working later.

  • Thank you for the suggestion. I’ve tried all variations, and no joy yet. Not sure if network availability is the problem, as it does seem to receive the requests. – Vincent Aug 17 '18 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.