nostop
一个极小的 Linux 命令行工具,用于包装并执行任意命令,并在命令因断网、断电、 崩溃等任何原因中断后,能够从中断处继续,避免从头重跑浪费时间。
nostop <命令> # 运行 / 续跑一条命令
nostop stats # 查看此前中断的命令(命令内容 + 中断时的工作目录)
它解决什么问题
- 跑了 6 个小时的生信流程,第 5 步时断电 / 断网 / 节点被回收,重跑又要 6 小时。
- 写了一个多步骤的 shell 流程,中途失败,希望已完成的步骤不要再跑。
nostop 的价值:
- 通用:
nostop <任意命令>的行为与直接执行该命令完全一致(输出、退出码、环境都透传)。 - 可续跑:中断后再次运行完全相同的
nostop <命令>(同一工作目录),工具会识别已完成的 进度并跳过,从断点继续。 - 可查询:
nostop stats列出此前中断的命令,含命令内容与其中断时所在路径(cwd), 方便你回到原目录重新启动。 - 简约:单个 bash 脚本,无编译、无依赖、无守护进程、无数据库;体积几 KB,运行时几乎零开销。
- 支持广:既支持“多步骤 shell 脚本”(用 checkpoint API 精确跳过步骤),也支持“单个长时间 运行的程序”(如 megahit 等自带断点续跑能力的二进制,nostop 负责用完全相同的方式重新拉起它)。
安装
方式一:pip 安装(推荐)
本工具已打包为 Python 项目,可直接用 pip 从源码或你们内部的 PyPI 源安装:
# 从本地源码目录安装
pip install .
# 或打包后安装(生成 dist/nostop-cli-*.whl / tar.gz)
pip install build
python -m build
pip install dist/nostop-cli-*.whl
# 如需发布到你们内部的 PyPI 或公开 PyPI:
twine upload dist/*
# 之后他人即可:pip install nostop-cli (命令名仍是 nostop)
安装后 nostop 命令即可用(其实质是一个极薄的 Python 入口,启动后立刻 exec
到内置的 bash 脚本,运行时不依赖 Python)。也可用 python -m nostop ... 运行。
方式二:单文件拷贝(零依赖,连 Python 都不需要)
如果你只想用一个文件、连 Python 环境都不想依赖,直接复制内置脚本即可 (依赖系统自带的 bash 与 coreutils,CentOS / Ubuntu 等主流发行版默认都有):
sudo cp src/nostop/nostop.sh /usr/local/bin/nostop
sudo chmod +x /usr/local/bin/nostop
# 可选:自定义状态目录(默认 ~/.nostop)
# export NOSTOP_HOME=/data/.nostop
验证:nostop help
快速开始
# 像平常一样运行命令,只是前面加 nostop
nostop "bash my_pipeline.sh"
# 中断后,回到同一个目录,原样再敲一次即可续跑
nostop "bash my_pipeline.sh"
# 查看哪些命令之前中断了(含命令内容与工作目录)
nostop stats
场景一:多步骤 shell 流程(精确到步骤的跳过)
对“脚本里有多个步骤”的情况,使用 nostop 提供的 checkpoint(检查点)API。
在脚本里把每个步骤包成 nostop step <名字> -- <命令>:
#!/bin/bash
# my_pipeline.sh
nostop step prepare -- "echo 准备数据 && sleep 2"
nostop step align -- "echo 比对 && sleep 2"
nostop step call -- "echo 变异检测 && sleep 2"
nostop step report -- "echo 出报告"
echo "全部完成"
运行:
nostop "bash my_pipeline.sh"
- 第一次正常运行,每完成一步就记录一个检查点。
- 中途断电/被杀:再次
nostop "bash my_pipeline.sh"时,已完成的步骤会被自动跳过 (输出[nostop] skip step 'prepare' (already done)),直接从断点继续。 - 步骤失败(退出码非 0)不会被标记为完成,下次会自动重跑该步骤。
如果你的步骤本身是一条带管道 / 重定向的复杂命令,可以写成单个字符串:
nostop step build -- "make && make test | tee build.log"。
手动控制检查点(更灵活):
| 写法 | 作用 |
|---|---|
nostop step <名字> -- <命令> |
运行命令;成功则标记 <名字> 完成,下次跳过 |
nostop done <名字> |
退出码 0 表示该检查点已完成,否则 1(用于 if 判断) |
nostop mark <名字> |
直接把 <名字> 标记为完成 |
例如在脚本里手写分支:
if nostop done align; then
echo "比对已完成,跳过"
else
do_align && nostop mark align
fi
注意:checkpoint API 只在
nostop <命令>内部才记录进度;直接bash my_pipeline.sh运行时它会退化为“直接执行”,不影响结果,只是不记录进度。
场景二:单个长时间运行的程序(如 megahit)
很多生信程序(megahit、Trinity、SPAdes 等)自身就支持断点续跑——只要用相同的输出目录 重新运行,它们会接着上次的产物继续。nostop 在这里的作用是:用完全相同的方式重新拉起命令, 并替你记录状态 / 方便重跑。
# 第一次运行
nostop "megahit -1 read1.fq -2 read2.fq -o mega.out"
# 中断后,回到同一目录,原样再敲一次;megahit 会基于 mega.out 里已有的中间文件续跑
nostop "megahit -1 read1.fq -2 read2.fq -o mega.out"
nostop 本身对“单个二进制内部进度”无感知(那是程序自己的事),但它保证:
- 用完全相同的命令字符串与工作目录重启;
- 把这次运行登记到状态库,供
nostop stats查看; - 程序成功跑完(退出码 0)后记为
DONE,之后原样再跑会被直接跳过,不会重复计算。
如果程序需要显式续跑参数(例如某些工具要用
--continue/-c),把它写进命令里即可, 因为 nostop 是“原样重放”。
场景三:批处理(nostop batch)
当同一道命令要对多组输入分别跑一遍(例如多个样本分别做 fastp / spades),用 nostop batch
一次性提交。它把每条输入展开到模板里,并把每条输入当作一个检查点——中断后续跑时,
已完成的样本会被自动跳过。
模板占位符:
{N}:第 N 个字段(从 1 起),输入按:切分。例s1_1.fq:s1_2.fq→{1}=s1_1.fq、{2}=s1_2.fq。{}:整条输入原文(含:)。
# 双端配对({1}/{2} 占位)
nostop batch "fastp -i {1} -I {2} -o {1}.clean.fq -O {2}.clean.fq" s1_1.fq:s1_2.fq s2_1.fq:s2_2.fq
# 工具无续跑参数时,结合幂等写法最稳(重跑时已完成的组装直接跳过)
nostop batch "[ -s asm_{}/final.contigs.fa ] || spades.py -1 {1} -2 {2} -o asm_{}" s1_1.fq:s1_2.fq s2_1.fq:s2_2.fq
- 每条输入即
nostop step <输入>检查点,状态同样出现在nostop stats。 - 某个样本失败,batch 会停下(不再跑后续),修好后重跑即可;已完成样本自动跳过。
{}是整条输入原文(如s1_1.fq:s1_2.fq),故asm_{}目录名会带冒号(Linux 下合法); 想要干净目录名时,把样本名单独作为条目传入、用{1}/{2}拼文件路径即可。
子命令
| 命令 | 说明 |
|---|---|
nostop <命令> |
运行 / 续跑一条命令 |
nostop batch <模板> <条目>... |
对每条条目展开模板并分别运行,已完成的跳过 |
nostop stats [--all] |
列出中断 / 失败 / 正在运行的命令;--all 同时显示已完成的 |
nostop show <id> |
查看某条运行的详情(命令、目录、开始时间、尾部输出) |
nostop resume <id> |
在原始工作目录下,重新运行该命令(不用再手敲整条命令) |
| `nostop clean [--all | ]` |
nostop step/mark/done <名字> |
见上文 checkpoint API |
nostop help |
帮助 |
stats 示例输出:
ID STATUS COMMAND
97ecb77e INTERRUPTED bash my_pipeline.sh
cwd: /home/user/project
last checkpoint: align
ID是状态库里的短标识,可直接用于nostop show <id>/nostop resume <id>/nostop clean <id>。STATUS取值:RUNNING(仍在跑) /INTERRUPTED(被中断,最常见:断电、被杀、崩溃) /FAILED(命令自身非零退出) /DONE(已成功完成)。
工作原理(如何检测“中断”)
状态保存在 $NOSTOP_HOME/runs/<hash>/,其中 <hash> 由 命令字符串 + 当前工作目录 计算。
每次运行写入 meta 文件,记录 status(初始 running)、pid、boot_id(来自
/proc/sys/kernel/random/boot_id)、命令、目录等。
- 命令成功退出 ->
status=done;非零退出 ->status=failed。 - 若进程被 SIGINT/SIGTERM 终止 -> 捕获后记为
interrupted。 - 若机器断电 / 崩溃(nostop 来不及响应)->
meta仍停留在running, 且记录的pid已不存在(或boot_id与本次启动不一致)-> 查询时判定为INTERRUPTED。
因此 nostop stats 能可靠区分“正在跑”、“被中断”、“已成功”、“已失败”。
环境变量
| 变量 | 默认值 | 说明 |
|---|---|---|
NOSTOP_HOME |
~/.nostop |
状态库根目录,可指向大容量磁盘 |
兼容性与限制
- 兼容性:纯 bash + coreutils(
sha256sum/date/kill/tee),CentOS 7/8、Ubuntu 20.04/22.04 等主流发行版开箱即用;仅依赖 Linux 的/proc/sys/kernel/random/boot_id(缺失时退化为仅按 PID 判断)。 - 限制:
- 对“单个不自带续跑能力的黑盒二进制”,nostop 只能保证原样重放,无法替它在内部续跑;
这类场景请用脚本 +
nostop step拆成可重入的步骤,或选用自带续跑的程序。 - 检查点跳过依赖步骤本身是可重入 / 幂等的;请确保重试某步不会造成破坏。
- 同一“命令 + 目录”被视为同一次运行;若想以不同参数再跑一份,请换目录或改命令。
- 对“单个不自带续跑能力的黑盒二进制”,nostop 只能保证原样重放,无法替它在内部续跑;
这类场景请用脚本 +
- 已知命令已 DONE 时再原样运行会被直接跳过(输出提示)。需要强制重跑请先
nostop clean <id>。
文件结构
nostop # 工具本体(单文件,拷贝即用)
README.md # 本文档
examples/ # 示例脚本
pipeline.sh # 场景一:带 checkpoint 的多步骤流程
megahit.sh # 场景二:单个长时间程序续跑示例
Metadata
Release files for nostop-cli 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nostop_cli-0.1.0.tar.gz | 17.2 kB | Without provenance | Details for nostop_cli-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nostop_cli-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for nostop_cli-0.1.0-py3-none-any.whl |
Total release size: 29.8 kB
Release files / nostop_cli-0.1.0.tar.gz
| Download URL | nostop_cli-0.1.0.tar.gz |
|---|---|
| Size | 17.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0c92896fe768b85f21017a48c56d0186e87ade8893127a5c3efc466640a0612
|
|
BLAKE2b-256 checksum How to use checksums |
a20ce2967a74ee6538c390e4a6ca4d80a4879367146fbdc04f4ed2f812dc51cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / nostop_cli-0.1.0-py3-none-any.whl
| Download URL | nostop_cli-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f3d11d1a8d766ccc6290bebd05738138e46ae92c993bdf8ef97936bc18136fd7
|
|
BLAKE2b-256 checksum How to use checksums |
fc1b2946f9f3b136c3115e6ba0573c11998adca3ac9ea85a6f0d250f78304f7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for nostop-cli 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.