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


Groups > comp.lang.python > #77799 > unrolled thread

Re: Example of python service running under systemd?

Started byErvin Hegedüs <airween@gmail.com>
First post2014-09-12 08:18 +0200
Last post2014-09-12 08:18 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Example of python service running under systemd? Ervin Hegedüs <airween@gmail.com> - 2014-09-12 08:18 +0200

#77799 — Re: Example of python service running under systemd?

FromErvin Hegedüs <airween@gmail.com>
Date2014-09-12 08:18 +0200
SubjectRe: Example of python service running under systemd?
Message-ID<mailman.13961.1410502584.18130.python-list@python.org>
Hi Chris,

On Fri, Sep 12, 2014 at 12:29:27PM +1000, Chris Angelico wrote:
> On Fri, Sep 12, 2014 at 12:03 PM, Michael Torrie <torriem@gmail.com> wrote:
> >
> > Any executable file can be turned into a daemon service with systemd
> > (whether or not it forks itself into the background).  Thus any python
> > script can easily be run from systemd.
> 
> I strongly recommend making a non-daemonizing service. It's so much
> easier to debug - there's one mode of operation, the script just runs.
> You can then run that directly in a terminal, or via tmux, or via
> systemd - and I've done all three with Yosemite. In fact, I think I
> have instances here on the LAN that are doing all three, right now!

is there any other reason outside the debugging?

Of course, I've handled that in a simple way:

    parser = optparse.OptionParser()

    parser.add_option("-d",
                      "--debug",
                        action="count",
                        dest="debug_mode",
                        help="Start process in debug mode, not forking.")

    (options, args) = parser.parse_args()

    debug_mode = True
    if options.debug_mode is None:

        debug_mode = False
        try:
            pid = os.fork()
            if pid > 0:
               ....

And of course, I've handled the signals, logfiles and so on...

So, now I can run my app with -d, then it will not do the fork(),
I'll see all messages and feedbacks. Elsewhere, the process will
run in background.

Anyway, thanks all comments from others. May be the life is
easier with systemd, but that was my "5-minutes-finger-exercise"
:)


Thanks again,


a.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web