Start Sinatra app in the background with stdout and stderr redirected (append) to a file
Solution 1
Under bash, try:
nohup ruby app.rb >> /log/file 2>&1 &
Solution 2
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
.
Related videos on Youtube
letronje
Updated on September 17, 2022Comments
-
letronje almost 2 years
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. -
letronje over 13 years"2>&1" what does that mean ?
-
MadHatter over 13 years"Send STDERR to the same place you're sending STDOUT"
-
letronje over 13 yearsthnx a ton for the cmd :)
-
Nakilon over 10 yearsAnd what does the end
&
mean? -
MadHatter over 10 years"Run in the background", though please note that SF isn't a forum, and this might have been better asked as a separate question on unix.stackexchange.com (after some research, because I'm fairly sure this question will have been asked there before).
-
shevy about 5 yearsIt's perfectly fine to ask follow-up questions; visitors can understand more that way.
-
MadHatter about 5 years@shevy a followup question from the OP is reasonable, and I'd answered it. But the other question came three years later, from a third party. It would have been better asked as a separate question (and in any case, as I think I said, it's a pretty common one).