Browse Source

Implement PID file support for non-Windows systems.

Triggered by command line parameter:
--pid <full-path>
tags/0.6.1
ShyPike 14 years ago
parent
commit
123cc3bbf9
  1. 12
      SABnzbd.py
  2. 23
      sabnzbd/__init__.py

12
SABnzbd.py

@ -237,6 +237,7 @@ def print_help():
print " -d --daemon Use when run as a service"
else:
print " -d --daemon Fork daemon process"
print " --pid <path> Create a PID file in the listed folder (full path)"
print
print " --force Discard web-port timeout (see Wiki!)"
print " -h --help Print this message"
@ -760,7 +761,7 @@ def commandline_handler(frozen=True):
'weblogging=', 'server=', 'templates',
'template2', 'browser=', 'config-file=', 'force',
'version', 'https=', 'autorestarted', 'repair', 'repair-all',
'log-all', 'no-login',
'log-all', 'no-login', 'pid=',
# Below Win32 Service options
'password=', 'username=', 'startup=', 'perfmonini=', 'perfmondll=',
'interactive', 'wait=',
@ -830,6 +831,7 @@ def main():
api_url = None
no_login = False
re_argv = [sys.argv[0]]
pid_path = None
service, sab_opts, serv_opts, upload_nzbs = commandline_handler()
@ -904,6 +906,10 @@ def main():
sabnzbd.LOG_ALL = True
elif opt in ('--no-login',):
no_login = True
elif opt in ('--pid',):
pid_path = arg
re_argv.append(opt)
re_argv.append(arg)
sabnzbd.MY_FULLNAME = os.path.normpath(os.path.abspath(sabnzbd.MY_FULLNAME))
sabnzbd.MY_NAME = os.path.basename(sabnzbd.MY_FULLNAME)
@ -1384,6 +1390,9 @@ def main():
# Write URL directly to registry
set_connection_info(api_url)
if pid_path:
sabnzbd.pid_file(pid_path, cherryport)
# Have to keep this running, otherwise logging will terminate
timer = 0
while not sabnzbd.SABSTOP:
@ -1477,6 +1486,7 @@ def main():
logging.info('Leaving SABnzbd')
sys.stderr.flush()
sys.stdout.flush()
sabnzbd.pid_file()
if getattr(sys, 'frozen', None) == 'macosx_app':
AppHelper.stopEventLoop()
else:

23
sabnzbd/__init__.py

@ -98,6 +98,7 @@ DIR_LCLDATA = None
DIR_PROG = None
DIR_INTERFACES = None
DIR_LANGUAGE = None
DIR_PID = None
QUEUECOMPLETE = None #stores the nice name of the action
QUEUECOMPLETEACTION = None #stores the name of the function to be called
@ -160,6 +161,8 @@ def sig_handler(signum = None, frame = None):
if sabnzbd.WIN32:
from util.apireg import del_connection_info
del_connection_info()
else:
pid_file()
SABSTOP = True
os._exit(0)
@ -963,6 +966,26 @@ def check_all_tasks():
return True
def pid_file(pid_path=None, port=0):
""" Create or remove pid file
"""
global DIR_PID
if not sabnzbd.WIN32 and pid_path and pid_path.startswith('/'):
DIR_PID = os.path.join(pid_path, 'sabnzbd-%s.pid' % port)
if DIR_PID:
try:
if port:
f = open(DIR_PID, 'w')
f.write('%d\n' % os.getpid())
f.close()
else:
os.remove(DIR_PID)
except:
logging.warning('Cannot access PID file %s', DIR_PID)
# Required wrapper because nzbstuff.py cannot import downloader.py
def active_primaries():
return sabnzbd.downloader.Downloader.do.active_primaries()

Loading…
Cancel
Save