mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-04-24 06:37:16 -04:00
Initial commit
This commit is contained in:
parent
7c70564646
commit
cb385d8706
3 changed files with 156 additions and 0 deletions
10
bazarr.py
10
bazarr.py
|
@ -5,6 +5,8 @@ gc.enable()
|
|||
|
||||
from get_argv import config_dir, no_update
|
||||
|
||||
from daemon import shutdown_bazarr, restart_bazarr
|
||||
|
||||
import os
|
||||
import sys
|
||||
reload(sys)
|
||||
|
@ -187,6 +189,14 @@ def redirect_root():
|
|||
authorize()
|
||||
redirect (base_url)
|
||||
|
||||
@route(base_url + 'shutdown')
|
||||
def shutdown():
|
||||
shutdown_bazarr(False)
|
||||
|
||||
@route(base_url + 'restart')
|
||||
def restart():
|
||||
restart_bazarr()
|
||||
|
||||
@route(base_url + 'static/:path#.+#', name='static')
|
||||
@custom_auth_basic(check_credentials)
|
||||
def static(path):
|
||||
|
|
118
daemon.py
Normal file
118
daemon.py
Normal file
|
@ -0,0 +1,118 @@
|
|||
import subprocess as sp
|
||||
import threading
|
||||
import time
|
||||
import os
|
||||
import signal
|
||||
import logging
|
||||
import sys
|
||||
import getopt
|
||||
|
||||
log = logging.getLogger()
|
||||
log.setLevel(logging.DEBUG)
|
||||
out_hdlr = logging.StreamHandler(sys.stdout)
|
||||
out_hdlr.setLevel(logging.INFO)
|
||||
log.addHandler(out_hdlr)
|
||||
|
||||
arguments = []
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:],"h:",["no-update", "config="])
|
||||
except getopt.GetoptError:
|
||||
print 'daemon.py -h --no-update --config <config_directory>'
|
||||
sys.exit(2)
|
||||
for opt, arg in opts:
|
||||
arguments.append(opt)
|
||||
if arg != '':
|
||||
arguments.append(arg)
|
||||
|
||||
|
||||
def start_bazarr():
|
||||
script = ['python','bazarr.py'] + globals()['arguments']
|
||||
|
||||
pidfile = os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr.pid'))
|
||||
if os.path.exists(pidfile):
|
||||
logging.error("Bazarr already running, please stop it first.")
|
||||
else:
|
||||
ep = sp.Popen(script, stdout=sp.PIPE, stderr=sp.STDOUT)
|
||||
try:
|
||||
file = open(pidfile,'w')
|
||||
except:
|
||||
logging.error("Error trying to write pid file.")
|
||||
else:
|
||||
file.write(str(ep.pid))
|
||||
file.close()
|
||||
logging.info("Bazarr starting with process id: " + str(ep.pid))
|
||||
|
||||
|
||||
def shutdown_bazarr(restarting):
|
||||
pidfile = os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr.pid'))
|
||||
if os.path.exists(pidfile):
|
||||
try:
|
||||
file = open(pidfile,'r')
|
||||
except:
|
||||
logging.error("Error trying to read pid file.")
|
||||
else:
|
||||
pid = file.read()
|
||||
file.close()
|
||||
try:
|
||||
os.remove(pidfile)
|
||||
except:
|
||||
logging.error("Unable to delete pid file.")
|
||||
else:
|
||||
logging.info('Bazarr restarting...')
|
||||
if restarting is False:
|
||||
stopfile = os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr.stop'))
|
||||
file = open(stopfile, 'w')
|
||||
file.write('')
|
||||
file.close()
|
||||
os.kill(int(pid), signal.SIGINT)
|
||||
else:
|
||||
logging.warn("pid file doesn't exist. You must start Bazarr first.")
|
||||
|
||||
|
||||
def restart_bazarr():
|
||||
restartfile = os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr.restart'))
|
||||
file = open(restartfile, 'w')
|
||||
file.write('')
|
||||
file.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
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'))
|
||||
stopfile = os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr.stop'))
|
||||
|
||||
try:
|
||||
os.remove(pidfile)
|
||||
os.remove(restartfile)
|
||||
os.remove(stopfile)
|
||||
except:
|
||||
pass
|
||||
|
||||
def daemon():
|
||||
threading.Timer(1.0, daemon).start()
|
||||
if os.path.exists(stopfile):
|
||||
try:
|
||||
os.remove(stopfile)
|
||||
except:
|
||||
logging.error('Unable to delete stop file.')
|
||||
else:
|
||||
logging.info('Bazarr exited.')
|
||||
os._exit(0)
|
||||
|
||||
if os.path.exists(restartfile):
|
||||
try:
|
||||
os.remove(restartfile)
|
||||
except:
|
||||
logging.error('Unable to delete restart file.')
|
||||
else:
|
||||
shutdown_bazarr(True)
|
||||
start_bazarr()
|
||||
|
||||
|
||||
daemon()
|
||||
|
||||
start_bazarr()
|
||||
|
||||
# Keep the script running forever.
|
||||
while True:
|
||||
time.sleep(0.001)
|
|
@ -46,6 +46,10 @@
|
|||
% include('menu.tpl')
|
||||
|
||||
<div id="fondblanc" class="ui container">
|
||||
<div class="ui basic icon buttons" style="float: right;">
|
||||
<div id="shutdown" class="ui icon button" data-tooltip="Shutdown" data-inverted=""><i class="red power off icon"></i></div>
|
||||
<div id="restart" class="ui icon button" data-tooltip="Restart" data-inverted=""><i class="redo alternate icon"></i></div>
|
||||
</div>
|
||||
<div class="ui top attached tabular menu">
|
||||
<a class="tabs item active" data-tab="tasks">Tasks</a>
|
||||
<a class="tabs item" data-tab="logs">Logs</a>
|
||||
|
@ -207,4 +211,28 @@
|
|||
$('a:not(.tabs), button:not(.cancel, #download_log)').click(function(){
|
||||
$('#loader').addClass('active');
|
||||
})
|
||||
|
||||
$('#shutdown').click(function(){
|
||||
$.ajax({
|
||||
url: "{{base_url}}shutdown",
|
||||
async: false
|
||||
})
|
||||
.fail(function(){
|
||||
document.open();
|
||||
document.write('Bazarr has shutdown.');
|
||||
document.close();
|
||||
});
|
||||
})
|
||||
|
||||
$('#restart').click(function(){
|
||||
$.ajax({
|
||||
url: "{{base_url}}restart",
|
||||
async: false
|
||||
})
|
||||
.done(function(){
|
||||
document.open();
|
||||
document.write('Bazarr is restarting. Please reload page manually until it come back (should be less than 30 seconds).');
|
||||
document.close();
|
||||
});
|
||||
})
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue