diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 249a8936..812c6009 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -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("--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-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.add_argument("-q", action="store_true", help="quiet") diff --git a/copyparty/svchub.py b/copyparty/svchub.py index e10b52e2..1e1f87e2 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -206,6 +206,9 @@ class SvcHub(object): self.log("root", t, 1) self.retcode = 1 + self.sigterm() + + def sigterm(self) -> None: os.kill(os.getpid(), signal.SIGTERM) def cb_httpsrv_up(self) -> None: diff --git a/copyparty/up2k.py b/copyparty/up2k.py index c125b5e6..c2c33fca 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -182,6 +182,9 @@ class Up2k(object): all_vols = self.asrv.vfs.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.daemon = True thr.start() @@ -571,7 +574,6 @@ class Up2k(object): t = "online (running mtp)" if scan_vols: thr = threading.Thread(target=self._run_all_mtp, name="up2k-mtp-scan") - thr.daemon = True else: self.pp = None t = "online, idle" @@ -580,6 +582,7 @@ class Up2k(object): self.volstate[vol.vpath] = t if thr: + thr.daemon = True thr.start() return have_e2d @@ -1313,6 +1316,9 @@ class Up2k(object): if "OFFLINE" not in self.volstate[k]: self.volstate[k] = "online, idle" + if self.args.exit == "idx": + self.hub.sigterm() + def _run_one_mtp(self, ptop: str, gid: int) -> None: if gid != self.gid: return