Deploy Standalone Webapp with Systemctl (Debian)

  1. 2 months ago
    Edited 2 months ago

    Hi all,

    I am trying to deploy a standalone web app by adding it as a service with Systemctl on Debian 9.9. My app works fine in standalone mode when I start it using the ./WebApp command. In the terminal when I start as a service using

    systemctl start webapp

    command it starts and shows me following status when I use status command:

    Loaded: Loaded (from location...)
    Active: Deactivating (stop-sigterm)
    Process : number (code = exited)
    Main PID: number (code = exited, status=0/success)

    My systemctl service configuration is located in /etc/systemctl/system and looks like the following:

    [Unit] 
    Description = ManageStoneInternal App
    After=network.target
    StartLimitIntervalSec=0
    
    [Service]
    Type=simple
    ExecStart=/home/nick/StoneInternal/StoneInternal
    Restart=always
    RestartSec=3
    
    [Install]
    WantedBy=default.target

    It looks as if the service is exiting right away .. if I run ps aux I don't see my service on that list. Has anyone used systemctl to have a standalone app restart automatically?

    Figured it out, had to use Type=forking instead of simple.

  2. Derk J

    Sep 16 Pre-Release Testers, Xojo Pro

    Look in systemctl -u servicename.service
    See if you get errors.

  3. Edited 2 months ago

    @Derk J Look in systemctl -u servicename.service
    See if you get errors.

    Do you mean enter that as a command? Because it tells me -u is an invalid option

    Edit: Entering as --u I get Unknown Operation webapp.service

  4. Nick C

    is not verified Sep 16 Answer New York

    Figured it out, had to use Type=forking instead of simple.

  5. Derk J

    Sep 16 Pre-Release Testers, Xojo Pro

    @Nick C Do you mean enter that as a command? Because it tells me -u is an invalid option

    Edit: Entering as --u I get Unknown Operation webapp.service

    I meant use terminal and enter:

    sudo journalctl -u servicename.service

    Rplace “servicename” with the name of your service. Youll see all errors that systemd and your app generated.

  6. Derk J

    Sep 16 Pre-Release Testers, Xojo Pro

    @Nick C Figured it out, had to use Type=forking instead of simple.

    If it crashes i might not restart with type=forking
    Be sure you need such type or create a cli application that manages/starts/stops the webapplication.

  7. Edited 2 months ago

    @Derk J If it crashes i might not restart with type=forking
    Be sure you need such type or create a cli application that manages/starts/stops the webapplication.

    Thanks for the advice. I changed my settings back to type=simple and checked journalctl, it says Started Service but it is not in the list of processes and doesn't work.. I made a bash script and tried to use that for the ExecStart parameter but it also doesn't get started as a service with same log outputs. Not really sure, may just install something specifically for this purpose.

  8. Derk J

    Sep 17 Pre-Release Testers, Xojo Pro
    Edited 2 months ago

    @Nick C Thanks for the advice. I changed my settings back to type=simple and checked journalctl, it says Started Service but it is not in the list of processes and doesn't work.. I made a bash script and tried to use that for the ExecStart parameter but it also doesn't get started as a service with same log outputs. Not really sure, may just install something specifically for this purpose.

    Do you daemonize the process or not?

    I start Daemons using (you can start any process from this one):

    Type=forking

    You can safely use this type for any process, it will NOT hold systemd from directly starting other processes as it will ignore the return code from these processes. Systemd will not accept or execute any "Restart=always" or other types of restarts for "Type=forking".

    i start the "main" applications that should be kept alive at all times using:

    Type=oneshot

    These kind of programs stop (hold back future processes) all futher systemd processes that are "After=" this service from being run. They
    will run when this "main" application is stopped (or crashed).

    Sourced from systemd docs:

    If set to simple (the default if ExecStart= is specified but neither Type= nor BusName= are), the service manager will consider the unit started immediately after the main service process has been forked off. It is expected that the process configured with ExecStart= is the main process of the service. In this mode, if the process offers functionality to other processes on the system, its communication channels should be installed before the service is started up (e.g. sockets set up by systemd, via socket activation), as the service manager will immediately proceed starting follow-up units, right after creating the main service process, and before executing the service's binary. Note that this means systemctl start command lines for simple services will report success even if the service's binary cannot be invoked successfully (for example because the selected User= doesn't exist, or the service binary is missing).

or Sign Up to reply!