fix shutdown
This commit is contained in:
parent
1405582cc2
commit
26da12dedd
5 changed files with 29 additions and 6 deletions
17
ctl
17
ctl
|
@ -82,8 +82,21 @@ if [ "$1" == "debug" ]; then
|
||||||
fi
|
fi
|
||||||
if [ "$1" == "stop" ]; then
|
if [ "$1" == "stop" ]; then
|
||||||
remove_loginscript
|
remove_loginscript
|
||||||
test -e $PID && kill `cat $PID`
|
if [ -e $PID ]; then
|
||||||
test -e $PID && rm $PID
|
_PID=`cat $PID`
|
||||||
|
kill $_PID
|
||||||
|
waited=0
|
||||||
|
while ps -p $_PID > /dev/null
|
||||||
|
do
|
||||||
|
sleep 1
|
||||||
|
waited=$(($waited+1))
|
||||||
|
if [ $waited -gt 10 ]; then
|
||||||
|
kill -9 $_PID
|
||||||
|
sleep 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
test -e $PID && rm $PID
|
||||||
|
fi
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
if [ "$1" == "restart" ]; then
|
if [ "$1" == "restart" ]; then
|
||||||
|
|
|
@ -35,6 +35,8 @@ class Downloads(Thread):
|
||||||
for t in item.models.Transfer.query.filter(
|
for t in item.models.Transfer.query.filter(
|
||||||
item.models.Transfer.added!=None,
|
item.models.Transfer.added!=None,
|
||||||
item.models.Transfer.progress<1).order_by(item.models.Transfer.added):
|
item.models.Transfer.progress<1).order_by(item.models.Transfer.added):
|
||||||
|
if not self._running:
|
||||||
|
return False
|
||||||
for u in t.item.users:
|
for u in t.item.users:
|
||||||
if state.nodes.is_online(u.id):
|
if state.nodes.is_online(u.id):
|
||||||
logger.debug('DOWNLOAD %s %s', t.item, u)
|
logger.debug('DOWNLOAD %s %s', t.item, u)
|
||||||
|
@ -69,7 +71,7 @@ class ScrapeThread(Thread):
|
||||||
item.models.Scrape.added!=None,
|
item.models.Scrape.added!=None,
|
||||||
).order_by(item.models.Scrape.added):
|
).order_by(item.models.Scrape.added):
|
||||||
if not self._running:
|
if not self._running:
|
||||||
return False
|
return True
|
||||||
logger.debug('scrape %s', s.item)
|
logger.debug('scrape %s', s.item)
|
||||||
try:
|
try:
|
||||||
s.item.scrape()
|
s.item.scrape()
|
||||||
|
|
|
@ -31,6 +31,8 @@ def remove_missing():
|
||||||
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/')
|
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/')
|
||||||
if os.path.exists(prefix):
|
if os.path.exists(prefix):
|
||||||
for f in File.query:
|
for f in File.query:
|
||||||
|
if not state.tasks.connected:
|
||||||
|
return
|
||||||
path = f.item.get_path()
|
path = f.item.get_path()
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
dirty = True
|
dirty = True
|
||||||
|
@ -73,6 +75,8 @@ def run_scan():
|
||||||
books = []
|
books = []
|
||||||
for root, folders, files in os.walk(prefix):
|
for root, folders, files in os.walk(prefix):
|
||||||
for f in files:
|
for f in files:
|
||||||
|
if not state.tasks.connected:
|
||||||
|
return
|
||||||
#if f.startswith('._') or f == '.DS_Store':
|
#if f.startswith('._') or f == '.DS_Store':
|
||||||
if f.startswith('.'):
|
if f.startswith('.'):
|
||||||
continue
|
continue
|
||||||
|
@ -84,6 +88,8 @@ def run_scan():
|
||||||
position = 0
|
position = 0
|
||||||
added = 0
|
added = 0
|
||||||
for f in ox.sorted_strings(books):
|
for f in ox.sorted_strings(books):
|
||||||
|
if not state.tasks.connected:
|
||||||
|
return
|
||||||
position += 1
|
position += 1
|
||||||
id = media.get_id(f)
|
id = media.get_id(f)
|
||||||
file = File.get(id)
|
file = File.get(id)
|
||||||
|
@ -96,6 +102,7 @@ def run_import(options=None):
|
||||||
options = options or {}
|
options = options or {}
|
||||||
|
|
||||||
with db.session():
|
with db.session():
|
||||||
|
logger.debug('run_import')
|
||||||
prefs = settings.preferences
|
prefs = settings.preferences
|
||||||
prefix = os.path.expanduser(options.get('path', prefs['importPath']))
|
prefix = os.path.expanduser(options.get('path', prefs['importPath']))
|
||||||
if os.path.islink(prefix):
|
if os.path.islink(prefix):
|
||||||
|
@ -128,6 +135,8 @@ def run_import(options=None):
|
||||||
count = 0
|
count = 0
|
||||||
for root, folders, files in os.walk(prefix):
|
for root, folders, files in os.walk(prefix):
|
||||||
for f in files:
|
for f in files:
|
||||||
|
if not state.tasks.connected:
|
||||||
|
return
|
||||||
#if f.startswith('._') or f == '.DS_Store':
|
#if f.startswith('._') or f == '.DS_Store':
|
||||||
if f.startswith('.'):
|
if f.startswith('.'):
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -119,13 +119,13 @@ def run():
|
||||||
def shutdown():
|
def shutdown():
|
||||||
if state.downloads:
|
if state.downloads:
|
||||||
state.downloads.join()
|
state.downloads.join()
|
||||||
if state.tasks:
|
|
||||||
state.tasks.join()
|
|
||||||
if state.nodes:
|
if state.nodes:
|
||||||
state.nodes.join()
|
state.nodes.join()
|
||||||
if state.scraping:
|
if state.scraping:
|
||||||
state.scraping.join()
|
state.scraping.join()
|
||||||
http_server.stop()
|
http_server.stop()
|
||||||
|
if state.tasks:
|
||||||
|
state.tasks.join()
|
||||||
if PID and os.path.exists(PID):
|
if PID and os.path.exists(PID):
|
||||||
os.unlink(PID)
|
os.unlink(PID)
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ class Tasks(Thread):
|
||||||
def join(self):
|
def join(self):
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.q.put(None)
|
self.q.put(None)
|
||||||
self.q.join()
|
|
||||||
return Thread.join(self)
|
return Thread.join(self)
|
||||||
|
|
||||||
def queue(self, action, data=None):
|
def queue(self, action, data=None):
|
||||||
|
|
Loading…
Reference in a new issue