Making a Linux service - RopleyIT/GLRParser GitHub Wiki

Making your parser example start on Linux reboot

  1. NGINX will not start or stop the application when a client requests the URL. To make this happen automatically on your server, you will need to set it up as a service launched on system startup by default. The systemd daemon manages these services.

    Launch an editor to set up the new service's definition file:

    sudo nano /etc/systemd/system/kestrel-(ProjectName).service

    where (ProjectName) should be replaced with the name of your application.

    Paste the following into the editor. Note that (PublishPath) is the full path from the root of the filesystem to the folder containing the executable:

    [Unit]
    Description=(ProjectName) service running on Ubuntu

    [Service]
    WorkingDirectory=(PublishPath)/(ProjectName)
    ExecStart=(PublishPath)/(ProjectName)
    Restart=always
    # Restart service after 10 seconds if the dotnet service crashes:
    RestartSec=10
    KillSignal=SIGINT
    SyslogIdentifier=dotnet-example
    # www-data is the user that owns the service and its files.
    # Ensure that their UID has full rwx access to the files.
    User=www-data
    Environment=ASPNETCORE_ENVIRONMENT=Production
    Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

    [Install]
    WantedBy=multi-user.target
  1. Save the file away with ^O ^X, then enable the service:

    sudo systemctl enable kestrel-(ProjectName).service

  2. To start the service without waiting for a reboot, or to test that the service is running, use the commands:

    sudo systemctl start kestrel-(ProjectName).service sudo systemctl status kestrel-(ProjectName).service

    To subsequently inspect the service's operational log file entries, you can use the command:

    sudo journalctl -fu kestrel-(ProjectName).service

  3. You should now be able to use your application both from the local machine and over the network as a web application, even after server reboots.

⚠️ **GitHub.com Fallback** ⚠️