mirror of
https://github.com/rembo10/headphones.git
synced 2026-04-03 19:49:27 +01:00
Merge branch 'pidfile'
This commit is contained in:
7
Headphones.py
Normal file → Executable file
7
Headphones.py
Normal file → Executable file
@@ -47,6 +47,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()
|
||||
|
||||
@@ -56,7 +57,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:
|
||||
@@ -88,7 +91,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
@@ -24,6 +24,7 @@ SYS_ENCODING = None
|
||||
|
||||
QUIET = False
|
||||
DAEMON = False
|
||||
PIDFILE= None
|
||||
|
||||
SCHED = Scheduler()
|
||||
|
||||
@@ -348,9 +349,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':
|
||||
@@ -560,7 +565,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