itinero / routing-api

An API based on Itinero.
MIT License
13 stars 16 forks source link

Host API behind Apache #9

Closed jbelien closed 6 years ago

jbelien commented 6 years ago

Hello,

I followed those steps to run the API behind Apache : https://docs.microsoft.com/en-us/aspnet/core/publishing/apache-proxy

No problem at all to configure Apache (even though I didn't follow the guide at all) ! But I can't manage to create a service that starts :P

Here is my routing-api.service file ; what did I miss ?

[Unit]
Description=Routing .NET Web API Application running on Debian

[Service]
WorkingDirectory=/home/debian/routing-api/src/Itinero.API/bin/Debug/netcoreapp2.0/
ExecStart=/usr/bin/dotnet /home/debian/routing-api/src/Itinero.API/bin/Debug/netcoreapp2.0/Itinero.API.dll
Restart=always
RestartSec=10
SyslogIdentifier=dotnet-routing-api
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Development

[Install]
WantedBy=multi-user.target
xivk commented 6 years ago

I haven't tried to use apache, only a standalone service running behind NGINX. Any logging available on this?

jbelien commented 6 years ago

No, not really. It's not linked to Apache (could be NGINX), just on creating a service that runs the API.

EDIT: it is the standalone service that I didn't succeed to start.

xivk commented 6 years ago

The working directory maybe, where is your data directory? That's where your working directory should be.

jbelien commented 6 years ago

Nope, apparently not. I fixed the path for WorkingDirectory but didn't work either.

Here is the log :

Sep 15 14:28:04 routing-api systemd[1]: routing-api.service: Main process exited, code=exited, status=140/n/a
Sep 15 14:28:04 routing-api systemd[1]: routing-api.service: Unit entered failed state.
Sep 15 14:28:04 routing-api systemd[1]: routing-api.service: Failed with result 'exit-code'.
Sep 15 14:28:14 routing-api systemd[1]: routing-api.service: Service hold-off time over, scheduling restart.
Sep 15 14:28:14 routing-api systemd[1]: Stopped Routing .NET Web API Application running on Debian.
Sep 15 14:28:14 routing-api systemd[1]: Started Routing .NET Web API Application running on Debian.
Sep 15 14:28:14 routing-api dotnet-routing-api[25973]: Error:
Sep 15 14:28:14 routing-api dotnet-routing-api[25973]:   An assembly specified in the application dependencies manifest (Itinero.API.deps.json) was no
t found:
Sep 15 14:28:14 routing-api dotnet-routing-api[25973]:     package: 'Microsoft.AspNetCore.Diagnostics.Abstractions', version: '1.0.2'
Sep 15 14:28:14 routing-api dotnet-routing-api[25973]:     path: 'lib/netstandard1.0/Microsoft.AspNetCore.Diagnostics.Abstractions.dll'
xivk commented 6 years ago

Try deleting the output folder and rebuilding. Does the process run when you start it manually?

jbelien commented 6 years ago

Yes, everything works when I run ./run.sh manually ! It's just an issue with the creation (and start) of the service.

jbelien commented 6 years ago

No better luck with trying to do so on Ubuntu 16.04

jbelien commented 6 years ago

I tried to use Supervisor according to https://developingsoftware.com/aspnetcore-ubuntu/

The application seems to work : I can display http://localhost:5000/ (without running ./run.sh) but no instance is loaded ...

Any idea ?

xivk commented 6 years ago

The only reason I can think of for it not loading the data is again an issue with the paths, it either can't find the settings file or the data directory.

Any logging you can see? Perpaps I can improve the code to log some basics to the console when it starts, like paths, settings file loaded and stuff like that?

xivk commented 6 years ago

Also, I can try the Supervisor thing myself, can you give me your configuration file?

jbelien commented 6 years ago

Does not seem to have any error message when I'm trying to start the service on Ubuntu 16.04. On Debian 9, I had this error message :

Sep 15 14:28:14 routing-api dotnet-routing-api[25973]: Error:
Sep 15 14:28:14 routing-api dotnet-routing-api[25973]:   An assembly specified in the application dependencies manifest (Itinero.API.deps.json) was no
t found:
Sep 15 14:28:14 routing-api dotnet-routing-api[25973]:     package: 'Microsoft.AspNetCore.Diagnostics.Abstractions', version: '1.0.2'
Sep 15 14:28:14 routing-api dotnet-routing-api[25973]:     path: 'lib/netstandard1.0/Microsoft.AspNetCore.Diagnostics.Abstractions.dll'

For Supervisor, here is my configuration file :

[group:routing]
programs=routing

[program:routing]
directory=/home/ubuntu/routing-api/src/Itinero.API/bin/Debug/netcoreapp2.0
command=/usr/bin/dotnet Itinero.API.dll
autostart=true
autorestart=true
stderr_logfile=/var/log/routing.err.log
stdout_logfile=/var/log/routing.out.log
user=ubuntu
stopsignal=INT
stopasgroup=true
jbelien commented 6 years ago

How do you do to make your API run (as a daemon) even when you're not connected ?

xivk commented 6 years ago

Ah I see what's wrong now I think. I got the supervisor thing running by first trying to get the 'command' part to run. You need to be in the same directory as the appsettings.json file:

[group:hellomvc]
programs=hellomvcapp

[program:hellomvcapp]
directory=/home/xivk/work/itinero/routing-api/src/Itinero.API/
command=/usr/bin/dotnet ./bin/Debug/netcoreapp2.0/Itinero.API.dll
autostart=true
autorestart=true
stderr_logfile=/var/log/hellomvc.err.log
stdout_logfile=/var/log/hellomvc.out.log
user=xivk
stopsignal=INT
stopasgroup=true

Your setup might also work when you mode the appsettings.json file into the output folder:

/home/ubuntu/routing-api/src/Itinero.API/bin/Debug/netcoreapp2.0

xivk commented 6 years ago

I use docker so it's a bit different in the way I setup all this.

jbelien commented 6 years ago

Yes ! It works \o/

[group:routing]
programs=routing

[program:routing]
directory=/home/ubuntu/routing-api/src/Itinero.API
command=/usr/bin/dotnet ./bin/Debug/netcoreapp2.0/Itinero.API.dll
autostart=true
autorestart=true
stderr_logfile=/var/log/routing.err.log
stdout_logfile=/var/log/routing.out.log
user=ubuntu
stopsignal=INT
stopasgroup=true

👍 👍 👍

xivk commented 6 years ago

Yay! 🥇 👍

jbelien commented 6 years ago

Thanks a lot ! :)

magiak commented 5 years ago

Hi :) Thanks so much! In my case i had to change ExecStart from home/pi/Repos/myWebApp/bin/Development/netcoreapp2.2/linux-arm/myWebApp.dll to home/pi/Repos/myWebApp/bin/Development/netcoreapp2.2/linux-arm/publish/myWebApp.dll and it'running.