add option to exit after scanning volumes

This commit is contained in:
ed 2022-08-12 21:20:13 +02:00
parent f62dd0e3cc
commit 11df36f3cf
3 changed files with 12 additions and 2 deletions

View file

@ -552,9 +552,10 @@ def run_argparse(argv: list[str], formatter: Any, retry: bool) -> argparse.Names
ap2.add_argument("--no-robots", action="store_true", help="adds http and html headers asking search engines to not index anything") ap2.add_argument("--no-robots", action="store_true", help="adds http and html headers asking search engines to not index anything")
ap2.add_argument("--logout", metavar="H", type=float, default="8086", help="logout clients after H hours of inactivity (0.0028=10sec, 0.1=6min, 24=day, 168=week, 720=month, 8760=year)") ap2.add_argument("--logout", metavar="H", type=float, default="8086", help="logout clients after H hours of inactivity (0.0028=10sec, 0.1=6min, 24=day, 168=week, 720=month, 8760=year)")
ap2 = ap.add_argument_group('yolo options') ap2 = ap.add_argument_group('shutdown options')
ap2.add_argument("--ign-ebind", action="store_true", help="continue running even if it's impossible to listen on some of the requested endpoints") ap2.add_argument("--ign-ebind", action="store_true", help="continue running even if it's impossible to listen on some of the requested endpoints")
ap2.add_argument("--ign-ebind-all", action="store_true", help="continue running even if it's impossible to receive connections at all") ap2.add_argument("--ign-ebind-all", action="store_true", help="continue running even if it's impossible to receive connections at all")
ap2.add_argument("--exit", metavar="WHEN", type=u, default="", help="shutdown after WHEN has finished; for example 'idx' will do volume indexing + metadata analysis")
ap2 = ap.add_argument_group('logging options') ap2 = ap.add_argument_group('logging options')
ap2.add_argument("-q", action="store_true", help="quiet") ap2.add_argument("-q", action="store_true", help="quiet")

View file

@ -206,6 +206,9 @@ class SvcHub(object):
self.log("root", t, 1) self.log("root", t, 1)
self.retcode = 1 self.retcode = 1
self.sigterm()
def sigterm(self) -> None:
os.kill(os.getpid(), signal.SIGTERM) os.kill(os.getpid(), signal.SIGTERM)
def cb_httpsrv_up(self) -> None: def cb_httpsrv_up(self) -> None:

View file

@ -182,6 +182,9 @@ class Up2k(object):
all_vols = self.asrv.vfs.all_vols all_vols = self.asrv.vfs.all_vols
have_e2d = self.init_indexes(all_vols, []) have_e2d = self.init_indexes(all_vols, [])
if not self.pp and self.args.exit == "idx":
return self.hub.sigterm()
thr = threading.Thread(target=self._snapshot, name="up2k-snapshot") thr = threading.Thread(target=self._snapshot, name="up2k-snapshot")
thr.daemon = True thr.daemon = True
thr.start() thr.start()
@ -571,7 +574,6 @@ class Up2k(object):
t = "online (running mtp)" t = "online (running mtp)"
if scan_vols: if scan_vols:
thr = threading.Thread(target=self._run_all_mtp, name="up2k-mtp-scan") thr = threading.Thread(target=self._run_all_mtp, name="up2k-mtp-scan")
thr.daemon = True
else: else:
self.pp = None self.pp = None
t = "online, idle" t = "online, idle"
@ -580,6 +582,7 @@ class Up2k(object):
self.volstate[vol.vpath] = t self.volstate[vol.vpath] = t
if thr: if thr:
thr.daemon = True
thr.start() thr.start()
return have_e2d return have_e2d
@ -1313,6 +1316,9 @@ class Up2k(object):
if "OFFLINE" not in self.volstate[k]: if "OFFLINE" not in self.volstate[k]:
self.volstate[k] = "online, idle" self.volstate[k] = "online, idle"
if self.args.exit == "idx":
self.hub.sigterm()
def _run_one_mtp(self, ptop: str, gid: int) -> None: def _run_one_mtp(self, ptop: str, gid: int) -> None:
if gid != self.gid: if gid != self.gid:
return return