Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'debug': 0.07; 'none:': 0.07; 'parser': 0.07; 'args)': 0.09; 'executable': 0.09; 'try:': 0.09; 'way:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'background.': 0.14; 'chris,': 0.16; 'elsewhere,': 0.16; 'mode,': 0.16; 'operation,': 0.16; 'subject:under': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'app': 0.19; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'cc:2**0': 0.24; "i've": 0.25; 'script': 0.25; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'michael': 0.29; 'chris': 0.29; 'thus': 0.29; 'mode': 0.30; 'strongly': 0.30; 'comments': 0.31; 'easier': 0.31; 'sep': 0.31; 'file': 0.32; 'handled': 0.32; 'run': 0.32; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'false': 0.36; 'instances': 0.36; 'subject:service': 0.36; 'done': 0.36; 'doing': 0.36; 'thanks': 0.36; "i'll": 0.36; 'subject:?': 0.36; 'so,': 0.37; 'easily': 0.37; 'skip:o 20': 0.38; 'others.': 0.38; 'pm,': 0.38; '12,': 0.39; 'itself': 0.39; 'skip:p 20': 0.39; 'from:charset:utf-8': 0.61; 'simple': 0.61; 'content- disposition:inline': 0.62; 'making': 0.63; 'skip:n 10': 0.64; 'to:addr:gmail.com': 0.65; 'life': 0.66; 'here': 0.66; 'on...': 0.68; 'fact,': 0.69; 'forks': 0.84; 'received:86': 0.91; 'received:hu': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=0P6e3wBA/fYXa8afIJ3RtuVJRQp+5DO/1fjySlNvEFg=; b=wMTuRRAb1wlHdLSRoRSM8+XC+YKh24oBzN4dnrOPQQQHYiPigo8E+D++Z8NGwIESCd ig2jq5vApmIcYqOcH/PRoBMAoxUdSp5FkfFK+G4iW9EQGjIN21cQ/bmFPo/RIU9Sqv5I zv6tqsHIQilh29Ar0kQChAOWRjw7JRUi2x185YqcTWVPzTQ3DFnsZcEYpC6W5WdEfjLT hJzo9idL5nMebZBi1exr+sPesxQQtbCMiYrBzgbyM186/CiPKkIiZHHCn/Y/SZcTkgP4 fSWjk5PbCvuE9PEZYKVXaO6y6RqH+GiEDM4lqT0WbOAWMM+wDW6fSTRC7kJe+FOfOf/H IfSg== X-Received: by 10.194.243.230 with SMTP id xb6mr8391486wjc.100.1410502582157; Thu, 11 Sep 2014 23:16:22 -0700 (PDT) Date: Fri, 12 Sep 2014 08:18:06 +0200 From: Ervin =?utf-8?Q?Heged=C3=BCs?= To: Chris Angelico Subject: Re: Example of python service running under systemd? References: <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> <5412548A.1090507@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1410502584 news.xs4all.nl 2920 [2001:888:2000:d::a6]:42068 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77799 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 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.