mirror of
https://gitlab.com/LazyLibrarian/LazyLibrarian.git
synced 2026-02-06 10:47:15 +00:00
Downgrade to previous version if upgrade doesnt start
This commit is contained in:
parent
c4aed4554a
commit
83150e9faf
@ -24,6 +24,7 @@ import threading
|
||||
import time
|
||||
import sqlite3
|
||||
import traceback
|
||||
import tarfile
|
||||
|
||||
import cherrypy
|
||||
from lazylibrarian import logger, database, versioncheck, postprocess, searchbook, searchmag, searchrss, \
|
||||
@ -1214,9 +1215,9 @@ def config_write(part=None):
|
||||
else:
|
||||
def_val = '755'
|
||||
value = CONFIG[key]
|
||||
if len(value) == 5:
|
||||
if len(value) in [5, 6]:
|
||||
value = value[2:]
|
||||
if len(value) == 3:
|
||||
if len(value) in [3, 4]:
|
||||
try:
|
||||
_ = int(value, 8)
|
||||
except ValueError:
|
||||
@ -2127,5 +2128,55 @@ def shutdown(restart=False, update=False):
|
||||
|
||||
logmsg('debug', 'Restarting LazyLibrarian with ' + str(popen_list))
|
||||
subprocess.Popen(popen_list, cwd=os.getcwd())
|
||||
logmsg('debug', 'Lazylibrarian (pid %s) is exiting now' % os.getpid())
|
||||
if 'HTTP_HOST' in CONFIG:
|
||||
# updating a running instance, not an --update
|
||||
# wait for it to open the httpserver
|
||||
host = CONFIG['HTTP_HOST']
|
||||
if '0.0.0.0' in host:
|
||||
host = 'localhost' # windows doesn't like 0.0.0.0
|
||||
newserver = "%s:%s" % (host, CONFIG['HTTP_PORT'])
|
||||
if CONFIG['HTTP_ROOT']:
|
||||
newserver = newserver + '/' + CONFIG['HTTP_ROOT']
|
||||
if not newserver.startswith('http'):
|
||||
newserver = 'http://' + newserver
|
||||
logmsg("info", "Waiting for %s to start" % newserver)
|
||||
pawse = 12
|
||||
success = False
|
||||
res = ''
|
||||
while pawse:
|
||||
result, success = fetchURL(newserver, retry=False)
|
||||
if success:
|
||||
try:
|
||||
res = result.split('<title>')[1].split('</title>')[0]
|
||||
except IndexError:
|
||||
res = ''
|
||||
success = res.startswith('LazyLibrarian')
|
||||
if success:
|
||||
break
|
||||
else:
|
||||
print("Waiting... %s" % pawse)
|
||||
time.sleep(5)
|
||||
pawse -= 1
|
||||
|
||||
if success:
|
||||
print('Reached webserver page %s' % res)
|
||||
else:
|
||||
print('Webserver failed to start, reverting update')
|
||||
archivename = 'backup.tgz'
|
||||
if tarfile.is_tarfile(archivename):
|
||||
try:
|
||||
with tarfile.open(archivename) as tar:
|
||||
tar.extractall()
|
||||
success = True
|
||||
except Exception as e:
|
||||
print('Failed to unpack tarfile %s (%s): %s' %
|
||||
(type(e).__name__, archivename, str(e)))
|
||||
else:
|
||||
print("Invalid archive")
|
||||
|
||||
if success:
|
||||
print("Restarting from backup")
|
||||
subprocess.Popen(popen_list, cwd=os.getcwd())
|
||||
|
||||
print('Lazylibrarian (pid %s) is exiting now' % os.getpid())
|
||||
sys.exit(0)
|
||||
|
||||
16
recover.py
16
recover.py
@ -1,20 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 -*-
|
||||
#
|
||||
# This file is part of Lazylibrarian.
|
||||
#
|
||||
# Lazylibrarian is free software':'you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Lazylibrarian is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Lazylibrarian. If not, see <http://www.gnu.org/licenses/>.
|
||||
# This program is used to revert lazylibrarian back to a known working state
|
||||
# if an update fails. It unpacks "backup.tgz" to replace the update
|
||||
|
||||
import tarfile
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user