Moving everything else bazarr.py to a bazarr subdirectory.

pull/222/head
Louis Vézina 6 years ago
parent 53b52d364e
commit 1137090735

@ -0,0 +1 @@
from bazarr import *

@ -3,6 +3,7 @@ import threading
import time import time
import os import os
import signal import signal
import platform
import logging import logging
import sys import sys
import getopt import getopt
@ -17,7 +18,7 @@ arguments = []
try: try:
opts, args = getopt.getopt(sys.argv[1:],"h:",["no-update", "config="]) opts, args = getopt.getopt(sys.argv[1:],"h:",["no-update", "config="])
except getopt.GetoptError: except getopt.GetoptError:
print 'daemon.py -h --no-update --config <config_directory>' print 'bazarr.py -h --no-update --config <config_directory>'
sys.exit(2) sys.exit(2)
for opt, arg in opts: for opt, arg in opts:
arguments.append(opt) arguments.append(opt)
@ -26,7 +27,7 @@ for opt, arg in opts:
def start_bazarr(): def start_bazarr():
script = ['python','main.py'] + globals()['arguments'] script = ['python','bazarr/main.py'] + globals()['arguments']
pidfile = os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr.pid')) pidfile = os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr.pid'))
if os.path.exists(pidfile): if os.path.exists(pidfile):
@ -78,6 +79,44 @@ def restart_bazarr():
file.close() file.close()
# GetExitCodeProcess uses a special exit code to indicate that the process is
# still running.
_STILL_ACTIVE = 259
def is_pid_running(pid):
return (_is_pid_running_on_windows(pid) if platform.system() == "Windows"
else _is_pid_running_on_unix(pid))
def _is_pid_running_on_unix(pid):
try:
os.kill(pid, 0)
except OSError:
return False
return True
def _is_pid_running_on_windows(pid):
import ctypes.wintypes
kernel32 = ctypes.windll.kernel32
handle = kernel32.OpenProcess(1, 0, pid)
if handle == 0:
return False
# If the process exited recently, a pid may still exist for the handle.
# So, check if we can get the exit code.
exit_code = ctypes.wintypes.DWORD()
is_running = (
kernel32.GetExitCodeProcess(handle, ctypes.byref(exit_code)) == 0)
kernel32.CloseHandle(handle)
# See if we couldn't get the exit code or the exit code indicates that the
# process is still running.
return is_running or exit_code.value == _STILL_ACTIVE
if __name__ == '__main__': if __name__ == '__main__':
pidfile = os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr.pid')) pidfile = os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr.pid'))
restartfile = os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr.restart')) restartfile = os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr.restart'))
@ -110,6 +149,19 @@ if __name__ == '__main__':
shutdown_bazarr(True) shutdown_bazarr(True)
start_bazarr() start_bazarr()
if os.path.exists(pidfile):
try:
file = open(pidfile, 'r')
except:
logging.error("Error trying to read pid file.")
else:
pid = int(file.read())
file.close()
if is_pid_running(pid) is False:
logging.warn('Bazarr unexpectedly exited. Starting it back.')
start_bazarr()
daemon() daemon()

@ -2,7 +2,7 @@ import os
import sys import sys
import getopt import getopt
config_dir = os.path.join(os.path.dirname(__file__), 'data/') config_dir = os.path.join(os.path.dirname(__file__), '../data/')
no_update = False no_update = False
try: try:

@ -1,4 +1,4 @@
bazarr_version = '0.6.5' bazarr_version = '0.6.6'
import gc import gc
gc.enable() gc.enable()
@ -11,7 +11,7 @@ import os
import sys import sys
reload(sys) reload(sys)
sys.setdefaultencoding('utf8') sys.setdefaultencoding('utf8')
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'libs/')) sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../libs/'))
import sqlite3 import sqlite3
from init import * from init import *
@ -69,7 +69,7 @@ if get_proxy_settings()[0] != 'None':
from bottle import route, run, template, static_file, request, redirect, response, HTTPError, app from bottle import route, run, template, static_file, request, redirect, response, HTTPError, app
import bottle import bottle
bottle.TEMPLATE_PATH.insert(0, os.path.join(os.path.dirname(__file__), 'views/')) bottle.TEMPLATE_PATH.insert(0, os.path.join(os.path.dirname(__file__), '../views/'))
bottle.debug(True) bottle.debug(True)
bottle.TEMPLATES.clear() bottle.TEMPLATES.clear()
@ -200,7 +200,7 @@ def restart():
@route(base_url + 'static/:path#.+#', name='static') @route(base_url + 'static/:path#.+#', name='static')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
def static(path): def static(path):
return static_file(path, root=os.path.join(os.path.dirname(__file__), 'static')) return static_file(path, root=os.path.join(os.path.dirname(__file__), '../static'))
@route(base_url + 'emptylog') @route(base_url + 'emptylog')
@custom_auth_basic(check_credentials) @custom_auth_basic(check_credentials)
Loading…
Cancel
Save