Deploy Standalone Webapp with Systemctl (Debian)

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:

[code]
[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[/code]

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?

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

[quote=454451:@Derk Jochems]Look in systemctl -u servicename.service
See if you get errors.[/quote]

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

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

[quote=454453:@Nick Cabrera]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[/quote]

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.

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.

[quote=454505:@Derk Jochems]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.[/quote]

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: