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.
Under bash, try:
screen -L -dmS somename ruby app.rb
This will start a screen process with the name of 'somename', with all output from the program being logged to screenlog.0 in the current working directory.
If you ever want to get back the application's console for some reason, you can do
screen -r somename
.