autostartd
自动启动管理工具,支持 Windows 任务计划程序与 Linux Supervisor。提供统一的交互式菜单,帮助你配置脚本或可执行文件自启动。
安装
pip install autostartd
如需 pyre_tools 菜单能力,再额外安装:
pip install "autostartd[tools]"
运行
autostartd
任何输入处输入 q 可退出当前流程返回菜单。
功能
- Windows:通过
schtasks创建、更新、查询、删除任务。 - Windows 支持
.exe、.py、.bat、.cmd、.ps1。 - Windows 可选择登录后自启或登录前自启。
- Linux:通过 Supervisor 创建、查询、删除项目。
- Linux 支持
.py、.sh、.bash、.run、可执行文件、alias、原始命令、roslaunch、pip 工具命令和python -m模块命令。 - Linux 可选择登录前自启或登录后自启。
- Linux 创建时可选择“立即生效”或“仅下次开机/登录后生效”。
- Linux 会在首次 sudo 成功后缓存密码到
~/.autostartd/config.json,后续复用;若失效会提示重新输入并更新缓存。 - Linux 提供基础管理菜单,可查看项目状态并启动、停止、重启、禁用自启、恢复自启。
- 支持中英文界面切换,语言配置保存到
~/.autostartd/config.json。
自启动时机
Windows
- 登录后自启:创建
ONLOGON任务,使用当前用户运行,通常不需要管理员权限。 - 登录前自启:创建
ONSTART任务,使用SYSTEM账户和最高权限运行,需要在管理员终端运行。
Linux
- 登录前自启:使用系统级 Supervisor,配置写入
/etc/supervisor/conf.d/,需要 sudo。Supervisor 服务会尽量通过systemctl enable --now supervisor启用。 - 登录后自启:使用用户级 supervisord,配置写入
~/.config/autostartd/supervisor/,并在~/.profile中添加启动用户 supervisord 的片段。具体进程仍由 Supervisor 管理。 - 新增/修改项目时,可选择立即启动,或者只保存配置让它在下次开机/登录后生效。
WSL 中推荐启用 systemd 后使用登录前自启;如果不启用 systemd,可以使用登录后自启,用户登录 shell 后会启动用户级 supervisord。
Linux 启动类型
新增 Linux Supervisor 项目时可以选择启动类型:
- 自动识别脚本/可执行文件:
.py会用当前 Python,.sh/.bash会用/bin/bash,.run或无扩展名可执行文件会直接运行。 - Shell/alias/原始命令:自动包装为
bash -lc,并加载~/.bashrc、~/.bash_profile,适合 alias、自定义命令、带管道或环境变量的命令。 - ROS roslaunch:输入包名和 launch 文件,自动包装为
roslaunch package file.launch ...。 - ROS roslaunch 会通过
bash -lc加载常见 ROS 环境,并以前台主进程方式运行,降低 SupervisorBACKOFF概率。 - pip 工具:输入命令名和参数,例如
uvicorn app:app --host 0.0.0.0。 - Python 模块:自动包装为
python -m module ...。
API 调用
from autostartd import set_autostart, remove_autostart, list_autostart
# start_mode 可选:
# "after_login"
# "before_login"
set_autostart(
"my_task",
"~/Downloads/test_auto_start.py",
overwrite=True,
sudo_password="your_sudo_password",
start_mode="before_login",
)
set_autostart(
"ros_task",
"my_robot bringup.launch",
command_type="roslaunch",
start_mode="before_login",
sudo_password="your_sudo_password",
run_immediately=False,
)
set_autostart(
"alias_task",
"my_alias --flag",
command_type="alias",
start_mode="after_login",
)
print(list_autostart("my", sudo_password="your_sudo_password", start_mode="before_login"))
remove_autostart("my_task", sudo_password="your_sudo_password", start_mode="before_login")
说明:
- Windows 不需要
sudo_password。 - Linux
before_login需要sudo_password。 - 若之前已经通过交互模式缓存过 sudo 密码,API 也可以复用该缓存。
- Linux
after_login不需要 sudo,但需要当前用户登录后启动用户级 supervisord。
依赖
- Windows:系统自带
schtasks。 - Linux:需要
supervisord与supervisorctl。Ubuntu/Debian 会尝试通过apt-get install supervisor自动安装;CentOS/RHEL 会尝试使用dnf或yum。 - 首次自动安装 Supervisor 时会显示
tqdm进度条。 pyre_tools为可选依赖,仅在需要菜单中的Run pyre_tools功能时安装。- Python:3.8+。
autostartd
Cross-platform autostart manager for Windows Task Scheduler and Linux Supervisor.
Features
- Windows task management via
schtasks. - Windows supports
.exe,.py,.bat,.cmd, and.ps1. - Windows supports after-login and before-login startup.
- Linux process management via Supervisor.
- Linux supports
.py,.sh,.bash,.run, executable files, aliases, raw commands,roslaunch, pip tool commands, andpython -mmodule commands. - Linux supports before-login system Supervisor and after-login user supervisord.
- Linux can either apply a new task immediately or only on the next boot/login.
- Linux caches a validated sudo password in
~/.autostartd/config.jsonand asks again only if the saved credential fails. - Linux includes a basic management menu to start, stop, restart, disable autostart, and re-enable autostart.
Startup Timing
- Windows after login: creates an
ONLOGONtask for the current user. - Windows before login: creates an
ONSTARTtask asSYSTEM; run autostartd from an administrator terminal. - Linux before login: writes system Supervisor config under
/etc/supervisor/conf.d/; sudo is required. - Linux after login: writes user Supervisor config under
~/.config/autostartd/supervisor/and starts user supervisord from~/.profile.
API
from autostartd import set_autostart, remove_autostart, list_autostart
set_autostart("my_task", "/path/to/app.py", start_mode="before_login", sudo_password="password")
set_autostart("ros_task", "my_pkg bringup.launch", command_type="roslaunch", start_mode="before_login", sudo_password="password")
set_autostart("tool_task", "uvicorn app:app --host 0.0.0.0", command_type="pip", start_mode="after_login")
print(list_autostart("my", start_mode="before_login", sudo_password="password"))
remove_autostart("my_task", start_mode="before_login", sudo_password="password")
Installation Notes
pip install autostartd
Install the optional pyre_tools integration only if you need that menu action:
pip install "autostartd[tools]"
Metadata
Release files for autostartd 0.1.4
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 |
|---|---|---|---|---|
| autostartd-0.1.4.tar.gz | 22.4 kB | Without provenance | Details for autostartd-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| autostartd-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for autostartd-0.1.4-py3-none-any.whl |
Total release size: 44.7 kB
Release files / autostartd-0.1.4.tar.gz
| Download URL | autostartd-0.1.4.tar.gz |
|---|---|
| Size | 22.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eb0109ee0f4c3a629042bc858e2100fda96739f7928ad11997cdadc207a419cd
|
|
BLAKE2b-256 checksum How to use checksums |
2b6dd5bc3af9a844997e80d51691ae7ac250feeeb7a934e8eaa093e85e6cc7ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / autostartd-0.1.4-py3-none-any.whl
| Download URL | autostartd-0.1.4-py3-none-any.whl |
|---|---|
| Size | 22.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6491e5be53f8a8e32692777c11475ba9b48c89c82f215781a578605b3e280568
|
|
BLAKE2b-256 checksum How to use checksums |
e0a0479c56955ebc8b5614aa7fc1533e29c71be085e4ced775ef16935af5574a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for autostartd 0.1.4
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.