Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Under bash, try:

nohup ruby app.rb >> /log/file 2>&1 &
share|improve this answer
    
"2>&1" what does that mean ? –  letronje Dec 20 '10 at 6:27
2  
"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
    
And what does the end & mean? –  Nakilon Oct 10 '13 at 16:57

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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