Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import pyinotify
  5. import shutil
  6. import glob
  7.  
  8. PACKAGES_DIR = '/var/my-packages'
  9. PACKAGES_TEMP_DIR = '/var/www-data/package_temp'
  10.  
  11. wm = pyinotify.WatchManager()
  12. mask = pyinotify.IN_MOVED_TO
  13.  
  14. class ProcessPackages(pyinotify.ProcessEvent):
  15. def process_IN_MOVED_TO(self, event):
  16. for directory in glob.glob(PACKAGES_TEMP_DIR + '/*'):
  17. shutil.move(directory, PACKAGES_DIR)
  18.  
  19. handler = ProcessPackages()
  20. notifier = pyinotify.Notifier(wm, handler)
  21. wdd = wm.add_watch(PACKAGES_TEMP_DIR, mask)
  22.  
  23. try:
  24. notifier.loop(daemonize=True, pid_file='/tmp/packages.pid', stdout='/tmp/stdout.txt')
  25. except pyinotify.NotifierError, err:
  26. print >> sys.stderr, err
  27.  
  28. description "MyService"
  29. author "My Name"
  30.  
  31. start on runlevel [2345]
  32. stop on runlevel [!2345]
  33.  
  34. # Automatically restart process if crashed
  35. #respawn
  36.  
  37. exec su myuser -c "/usr/bin/python /path/to/myscript.py > /tmp/myscript.log 2>&1"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement