Start Sinatra app in the background with stdout and stderr redirected (append) to a file

backgroundbackground-processdaemonsinatrastderr

I have a Sinatra app which I run on my local machine using ruby app.rb. While deploying it on a remote machine via ssh, how do I run it in background and redirect stdout and stderr to a log file?

On a restart, I want to preserve the previous logs so that newer messages are appended to the existing log file, instead of truncating it.

What's the recommended way of running my web application as a daemon?

I've tried nohup ruby app.rb &, but that seems to be missing stderr and the log statements seem to be out of order in some cases.

Best Answer

Under bash, try:

nohup ruby app.rb >> /log/file 2>&1 &
Related Topic