Production server goes down after a while in ssh

I have an app and I start the server with _build/prod/rel/app/bin/app start (mix releases) in a remote host. Ok, but after a while my connection with the ssh goes down and the server also dies. Athought i can increase my ssh time, how do we “stick” the command to the terminal and the server to be active even if my ssh is client_loop: send disconnect: Broken pipe ?

Take care, redpoll

Usually you do not start your application from a terminal/shell session, rather you use your init system to start and monitor the application. For example with Systemd you would write a unit file and instruct Systemd to start your application at startup using that unit file.

If you really want to start your application from an SSH session, use something like tmux that keeps your command running even if you close the SSH session.


What you try to do is very easy to achieve. Instead of:

_build/prod/rel/app/bin/app start


_build/prod/rel/app/bin/app daemon

On a Freebsd system it starts the server in the background as a daemon which will stay alive when you end your ssh connection. I don’t know, though, if this is also the way to go on a Linux system.


Yes. It works exactly the same on Linux.


It is also possible on Linux to detach the command from the console by adding & at the end of the command.

Don’t do this for production purposes, however, there are many ways to keep a remote shell from dying:

For the record, you should use an init system (most probably you will have systemd). This is the correct way. Go learn this and you will have a much easier life later on.

You can use tmux or screen to keep your app running. Start an SSH session, run a tmux or screen session inside it, run your app inside it and detach from the tmux or screen session.

Also, as the dirtiest way:

_build/prod/rel/app/bin/app start >/dev/null 2>&1 &
disown %1

& at the end start the command in background, and redirection to /dev/null is for safety measures. Some apps will just crash if their “output” screen is closed. You can replace /dev/null with a file name so you can see your logs.

disown makes your background app detached from your current shell, so when you close your SSH session, your background app won’t be killed.