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


Groups > comp.lang.python > #77799

Re: Example of python service running under systemd?

Date 2014-09-12 08:18 +0200
From Ervin Hegedüs <airween@gmail.com>
Subject Re: Example of python service running under systemd?
References (1 earlier) <CAMw+j7+LQL_+77ejCFVSqWap7Rk9gS_Wu5d3y0gT1UpB8hiZAA@mail.gmail.com> <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> <5412548A.1090507@gmail.com> <CAPTjJmq4fYOs-qvko9q9S=M7PNGOLPBTDiPZ6R0PvMrAULC=3g@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.13961.1410502584.18130.python-list@python.org> (permalink)

Show all headers | View raw


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.

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


Thread

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

csiph-web