ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

如何注册 Lima 实例在用户登录时自动启动(limactl autostart)?

如何注册 Lima 实例在用户登录时自动启动(limactl autostart)? 如何注册 Lima 实例在用户登录时自动启动limactl autostart【免费下载链接】limaLinux virtual machines, with a focus on running containers项目地址: https://gitcode.com/GitHub_Trending/lim/lima如果你已经有可用的 Lima 实例但每次登录后都要手动执行limactl start才能使用容器或开发环境可以用limactl autostart把实例注册为用户登录时自动启动。Lima 2.2 提供该命令支持 macOS 和 Linux在 macOS 上它安装一个 LaunchAgent在 Linux 上安装一个 systemd 用户服务。注册完成后实例会在下一次登录以及之后的每次登录时于后台自动启动。旧命令limactl start-at-login自 v2.2 起已废弃由limactl autostart取代详见 website/content/en/docs/usage/autostart.md。前提条件已安装 Lima 2.2autostart 文档中给出的版本要求。目标实例已存在。limactl autostart enable INSTANCE会先查找实例实例不存在时命令直接报错instance ... not found见 cmd/limactl/autostart.go 的autostartEnableAction所以不要对尚未limactl create的名称注册。注册实例在登录时自动启动在宿主机macOS 或 Linux的终端执行limactl autostart enable defaultdefault是实例名替换为你自己的实例名称。--condition参数默认为login用户登录时启动所以上面命令无需额外参数即可实现登录时自动启动可选值只有login和boot其中boot系统启动时、早于任何用户会话启动仅 macOS 支持本文不展开。注册成功时命令输出Instance default registered to start at login各平台写入的位置不同macOS在~/Library/LaunchAgents/安装 LaunchAgent服务名为io.lima-vm.autostart.实例名见 pkg/autostart/launchd/launchd.go。Linux安装 systemd 用户服务lima-vm实例名.service单元模板以limactl start %i --foreground启动实例见 pkg/autostart/systemd/lima-vmINSTANCE.service。注册完成后退出并重新登录用户会话实例会在后台自动启动之后的每次登录同样会自动启动。可选关闭意外退出后的自动重启keep-alive默认--keep-alivetrue如果 Lima host agent 意外退出系统会自动重启它。要禁用该行为注册时显式传入--keep-alivefalselimactl autostart enable --keep-alivefalse default该参数在两种平台上的具体作用不同来自 autostart 文档的 Keep-alive behavior 一节macOSLaunchAgent 场景launchd 是否会在 host agent 意外退出后自动重启它Linuxsystemd 用户服务写入单元文件的Restart指令——启用时默认为on-failure禁用时为no。验证注册结果文档给出的成功条件是实例在下一次登录及之后的每次登录时于后台自动启动。可以按下面两步核对注册时确认命令输出registered to start at login且未出现failed to register ...错误。重新登录后确认实例确实在后台运行例如通过limactl list查看实例状态或用limactl shell default进入实例验证。另外注册文件本身也落在文档说明的固定位置macOS 在~/Library/LaunchAgents/Linux 在用户级 systemd 配置目录中可直接查看确认已写入。取消注册要移除自动启动执行limactl autostart disable default输出为Instance default unregistered from start at login如果该实例本来就没有注册命令会提示Instance default is not registered for automatic startup可借此确认注册确实已被清除。在 macOS 上disable会先检查 LaunchAgent若未命中再检查系统级 LaunchDaemon 并卸载见 cmd/limactl/autostart_darwin.go。版本边界Lima 2.2 没有autostart命令需要继续使用已废弃的start-at-login其等价关系为limactl start-at-login等价于limactl autostart enable --conditionlogin# 注册 limactl start-at-login default # 取消注册 limactl start-at-login --enabledfalse default升级到 Lima 2.2 后建议改用limactl autostartstart-at-login仅作为旧版本的兼容路径存在源码中已标记Deprecated见 cmd/limactl/start-at-login.go。【免费下载链接】limaLinux virtual machines, with a focus on running containers项目地址: https://gitcode.com/GitHub_Trending/lim/lima创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表