mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-09 21:29:27 +01:00
Add option --pidfile to create a pid file when running as a daemon.
This commit is contained in:
7
Headphones.py
Normal file → Executable file
7
Headphones.py
Normal file → Executable file
@@ -34,6 +34,7 @@ def main():
|
||||
parser.add_argument('--datadir', help='Specify a directory where to store your data files')
|
||||
parser.add_argument('--config', help='Specify a config file to use')
|
||||
parser.add_argument('--nolaunch', action='store_true', help='Prevent browser from launching on startup')
|
||||
parser.add_argument('--pidfile', help='Create a pid file (only relevant when running as a daemon)')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -43,7 +44,9 @@ def main():
|
||||
if args.daemon:
|
||||
headphones.DAEMON=True
|
||||
headphones.QUIET=True
|
||||
|
||||
if args.pidfile :
|
||||
headphones.PIDFILE = args.pidfile
|
||||
|
||||
if args.datadir:
|
||||
headphones.DATA_DIR = args.datadir
|
||||
else:
|
||||
@@ -75,7 +78,7 @@ def main():
|
||||
|
||||
if headphones.DAEMON:
|
||||
headphones.daemonize()
|
||||
|
||||
|
||||
# Force the http port if neccessary
|
||||
if args.port:
|
||||
http_port = args.port
|
||||
|
||||
17
headphones/__init__.py
Normal file → Executable file
17
headphones/__init__.py
Normal file → Executable file
@@ -22,6 +22,7 @@ SIGNAL = None
|
||||
|
||||
QUIET = False
|
||||
DAEMON = False
|
||||
PIDFILE= None
|
||||
|
||||
SCHED = Scheduler()
|
||||
|
||||
@@ -346,9 +347,13 @@ def daemonize():
|
||||
os.dup2(si.fileno(), sys.stdin.fileno())
|
||||
os.dup2(so.fileno(), sys.stdout.fileno())
|
||||
os.dup2(se.fileno(), sys.stderr.fileno())
|
||||
|
||||
logger.info('Daemonized to PID: %s' % os.getpid())
|
||||
|
||||
|
||||
pid = os.getpid()
|
||||
logger.info('Daemonized to PID: %s' % pid)
|
||||
if PIDFILE:
|
||||
logger.info('Writing PID %s to %s' % (pid, PIDFILE))
|
||||
file(PIDFILE, 'w').write("%s\n" % pid)
|
||||
|
||||
def launch_browser(host, port, root):
|
||||
|
||||
if host == '0.0.0.0':
|
||||
@@ -558,7 +563,11 @@ def shutdown(restart=False, update=False):
|
||||
versioncheck.update()
|
||||
except Exception, e:
|
||||
logger.warn('Headphones failed to update: %s. Restarting.' % e)
|
||||
|
||||
|
||||
if PIDFILE :
|
||||
logger.info ('Removing pidfile %s' % PIDFILE)
|
||||
os.remove(PIDFILE)
|
||||
|
||||
if restart:
|
||||
logger.info('Headphones is restarting...')
|
||||
popen_list = [sys.executable, FULL_PATH]
|
||||
|
||||
Reference in New Issue
Block a user