On 22Aug2014 12:27, Travis Griggs <travisgri...@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 <c...@zip.com.au>
You can't have everything... where would you put it?
- Charles Robinson, cr0...@medtronic.com
--
https://mail.python.org/mailman/listinfo/python-list