python 2.7 - Starting script using pyinotify as daemon process -


i have number of questions regarding starting script using pyinotify daemon.

i have code this:

#!/usr/bin/env python  import sys import pyinotify import shutil import glob  packages_dir = '/var/my-packages' packages_temp_dir = '/var/www-data/package_temp'  wm = pyinotify.watchmanager() mask = pyinotify.in_moved_to  class processpackages(pyinotify.processevent):     def process_in_moved_to(self, event):         directory in glob.glob(packages_temp_dir + '/*'):             shutil.move(directory, packages_dir)  handler = processpackages() notifier = pyinotify.notifier(wm, handler) wdd = wm.add_watch(packages_temp_dir, mask)  try:     notifier.loop(daemonize=true, pid_file='/tmp/packages.pid',  stdout='/tmp/stdout.txt') except pyinotify.notifiererror, err:     print >> sys.stderr, err 

my question if set daemonize parameter true mean whole script run daemon or pyinotify?

if pyinotify how go running entire script daemon process?

if run script daemon necessary make pyinotify daemon well?

my last question if pyinotify daemonized need callback? in case want script run forever , being killed on system reboot/restart.

the script should run standard startup script without manual intervention.

fyi,

i running ubuntu 12.04 server.

thanks in advance, nav

i run ipynotify-dependent process system service (which want, sound of things), using upstart - on ubuntu 12.04.

personally, didn't modify python script at all. made sure ran fine @ terminal, created upstart config file so:

/etc/init/myservice.conf:

description "myservice" author "my name"  start on runlevel [2345] stop on runlevel [!2345]  # automatically restart process if crashed #respawn  exec su myuser -c "/usr/bin/python /path/to/myscript.py > /tmp/myscript.log 2>&1" 

when init file in place, you'll want try sudo start myservice, inspect /tmp/myscript.log errors.

hth!


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -