Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76836

Re: Halfway point between interactive and daemon?

Date 2014-08-23 12:09 +1000
From Cameron Simpson <cs@zip.com.au>
Subject Re: Halfway point between interactive and daemon?
References <3DBE5DB0-3FA8-43BB-947C-9F6C265D0699@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.13321.1408759809.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 22Aug2014 12:27, Travis Griggs <travisgriggs@gmail.com> wrote:
>I’m curious if there’s a technique one could use to get half way there.  
>Basically, with minimal modifications, I’d like to get it running at startup.  
>So I can put a line like this in rc.local
>
>nohup python3 myMain.py 2>&1 > /var/log/mylog.log &

Just to this. You have your redirections backwards. They are applied left to 
right. So, first "2>&1": sending stderr to where stdout currently goes 
(probably the system console if this runs from rc.local). Then, "> 
/var/log/mylog.log": sending current stdout to the log file. Importantly, _not_ 
attaching stderr to the log file.

You want to write this:

   command >log 2>&1

As others have remarked, you do not need to daemonise a process started from 
rc.local.

And as others have remarked, if you want it to start/stop under external 
conrol, or restart after a program abort etc, you may be better adding it as to 
the configuration of something like systemd or init.

That said, I start a bunch of things in rc.local. It is quick and easy, and 
also handy for stuff that shouldn't be restarted automatically if it dies.

>Then I can “check” on it when I need to with a tail -f /var/log/mylog.log. But 
>then I have the problem of managing the log size. And also I either have to 
>wait for stdout to flush, or insert sys.stdout.flush() after any of my 
>print()’s.

Log messages should be going to stderr anyway, which by default is unbuffered.

Cheers,
Cameron Simpson <cs@zip.com.au>

You can't have everything...  where would you put it?
         - Charles Robinson, cr0100@medtronic.com

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Halfway point between interactive and daemon? Cameron Simpson <cs@zip.com.au> - 2014-08-23 12:09 +1000

csiph-web