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 webapp 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.

link|improve this question

feedback

2 Answers

up vote 1 down vote accepted

Under bash, try:

ruby app.rb >> /log/file 2>&1 &
link|improve this answer
"2>&1" what does that mean ? – letronje Dec 20 '10 at 6:27
"Send STDERR to the same place you're sending STDOUT" – MadHatter Dec 20 '10 at 6:56
thnx a ton for the cmd :) – letronje Dec 20 '10 at 12:13
you're welcome. – MadHatter Dec 20 '10 at 18:37
feedback

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'.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.