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


Groups > comp.lang.python > #76822

Re: Halfway point between interactive and daemon?

References (1 earlier) <CAPTjJmrO7fER7Wjgo6qNO9qHNJgkJ7Y3BFWBf1L=t-bOv4JV7w@mail.gmail.com> <53F634E5.4020206@m4x.org> <mailman.13263.1408667169.18130.python-list@python.org> <0f0ef37d-7d09-483f-8f9b-c63c444f1ea7@googlegroups.com> <3DBE5DB0-3FA8-43BB-947C-9F6C265D0699@gmail.com>
Date 2014-08-23 06:32 +1000
Subject Re: Halfway point between interactive and daemon?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.13308.1408739570.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Aug 23, 2014 at 5:27 AM, 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.

Okay, hold on a minute there. There are two quite separate things
here: daemonization, and starting on system startup.

Daemonization is actually unnecessary to the latter, if you use a
modern init system. Just write your program to never fork, and either
Upstart or systemd will happily monitor it. Just create a unit file,
something like this:

[Unit]
Description=Yosemite Project
[Service]
Environment=DISPLAY=:0.0
User=whichever_user_to_run_as
ExecStart=/usr/bin/python /path/to/your/script
# If the network isn't available yet, restart until it is.
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target

$ systemctl --system daemon-reload
$ systemctl enable yos.service
$ systemctl start yos.service

(Feel free to steal that for your own purposes. It came from my
MIT-licensed videos server project "Yosemite".)

Daemonization should be optional. The above unit file works fine for
something that doesn't fork itself away. (I'm not sure how systemd
works with daemonizing processes, never tried. In any case, it's
unnecessary.) If you do need it (so the user can start your program
from the command line), I strongly recommend picking up a module off
PyPI; there are actually a lot of little details that people will
expect you to have gotten right. May as well bury it all away in a
little daemonize() call :)

ChrisA

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


Thread

Re: Python vs C++ Chris Angelico <rosuav@gmail.com> - 2014-08-22 10:26 +1000
  Re: Python vs C++ CHIN Dihedral <dihedral88888@gmail.com> - 2014-08-22 12:00 -0700
    Halfway point between interactive and daemon? Travis Griggs <travisgriggs@gmail.com> - 2014-08-22 12:27 -0700
      Re: Halfway point between interactive and daemon? Marko Rauhamaa <marko@pacujo.net> - 2014-08-22 22:49 +0300
    Re: Halfway point between interactive and daemon? Chris Angelico <rosuav@gmail.com> - 2014-08-23 06:32 +1000

csiph-web