0

I have an executable file on a server which is a full-fledged standalone web application. When I login to a server via ssh and run the file, the website become visible in the internet. Obviously, because it's run via ssh by me, when I disconnect the website goes down.

What's the idiomatic and easy way to run that file 24/7 and preferably re-launch when it goes down?

It's Ubuntu 15 but my question isn't only about it.

I don't want to use any third-party solutions or web services, only the standard Linux tools and applications.

Should I create a service for systemd?

1

3 Answers 3

1

Yes, you need to make the full-fledged web server executable a service. Prefer a non-root account for the service — I'd even say it's mandatory — to limit damages in cases the web server gets compromised. I think1 systemd is well documented enough to guide you through the required steps.


1 I don't run systemd, in case the question arises...

0

On old-style init systems you can use good old start-stop-daemon application, which takes care of restarting the process if it dies. Just do something like:

start-stop-daemon --start --background --exec /path/to/your/executable

It also allows to set scheduling priority, IO priority etc. for the process you are running.

On a systemd enabled system you can also (or even better) create a systemd service unit as you mention. It will do the same thing, but using systemd functionality instead of a separate start-stop-daemon call. See e.g. here for details: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Unit_Files.html

1
  • Hi, welcome to the Unix StackExchange site. We normally prefer answers to provide detail rather than just link to an offsite resource (even if, in this case, it looks like it might be there a while). That way, it's easier for people to update answers if they become out of date, and doesn't rely on the link working for ever. Commented Apr 15, 2016 at 13:33
0
  • The simple way

create a script (for example /home/user/start_service.sh) with the follow content:

#!/bin/sh
while true; do
    path/to/service/executable
done

And add it to /etc/rc.local:

#!/bin/sh -e
su user -c '/home/user/start_service.sh' &
exit 0

Then start script manually:

/home/user/start_service.sh

So you can forget about your web application. It will start automatically on system start.

  • Right way:

Use tools like systemd and upstart to create a service from your application.

Not the answer you're looking for? Browse other questions tagged .