我有很多关于使用 pyinotify 作为守护进程启动脚本的问题。
我有一些这样的代码:
#!/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):
for 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
我现在的问题是,如果我将 daemonize 参数设置为 True,这是否意味着整个脚本作为守护进程运行,还是只是 pyinotify?
如果它只是 pyinotify 我将如何将整个脚本作为守护进程运行?
如果我将脚本作为守护进程运行,是否真的有必要让 pyinotify 成为守护进程?
我的最后一个问题是,如果 pyinotify 是守护进程,我肯定需要回调吗?就我而言,我只希望脚本永远运行并且仅在系统重新启动/重新启动时被杀死。
该脚本还应该像任何标准启动脚本一样运行,无需人工干预。
供参考,
我正在运行 Ubuntu 12.04 服务器。
在此先感谢,导航