Linux Ubuntu下启动时自动运行程序 [英] Automatically run a program on startup under Linux Ubuntu

查看:38
本文介绍了Linux Ubuntu下启动时自动运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每次启动 Ubuntu Linux 时都需要运行一个程序.所以我需要将它添加到我的启动程序列表中.只有一个问题:我需要通过终端来完成.

I'd need a program to be run every time I start up my Ubuntu Linux. So I'd need to add it to my startup programs list. Just one problem: I'd need to do it via the terminal.

推荐答案

sudo mv /filename /etc/init.d/
sudo chmod +x /etc/init.d/filename 
sudo update-rc.d filename defaults 

脚本现在应该在启动时启动.请注意,此方法也适用于硬链接和符号链接 (ln).

The script should now start on boot. Note that this method also works with both hard links and symbolic links (ln).

此时在引导过程中 PATH 尚未设置,因此始终使用绝对路径至关重要.但是,正如 Steve HHH 在评论中指出的那样,明确声明了 update-rc.d 命令的完整文件路径(/etc/init.d/filename)在大多数 Linux 版本中无效.根据 更新 rc.d 的手册页,第二个参数是位于/etc/init.d/*中的脚本.

At this point in the boot process PATH isn't set yet, so it is critical that absolute paths are used throughout. But, as pointed out in the comments by Steve HHH, explicitly declaring the full file path (/etc/init.d/filename) for the update-rc.d command is not valid in most versions of Linux. Per the manpage for update-rc.d, the second parameter is a script located in /etc/init.d/*.

同样在评论中指出(由 Charles Brandt),/filename 必须是一个 init 风格的脚本.还提供了一个很好的模板 - System V init 脚本模板.

Also as pointed out in the comments (by Charles Brandt), /filename must be an init style script. A good template was also provided - System V init script template.

正如评论中所指出的(Russell Yan),这仅适用于 update-rc.d 的默认模式.

As pointed out in the comments (by Russell Yan), this works only on default mode of update-rc.d.

根据update-rc.d的手册,它可以在两种模式下运行:使用legacy模式的机器会有一个文件/etc/init.d/.legacy-bootordering",在这种情况下,您必须通过命令行参数传递序列和运行级别配置.

According to the manual of update-rc.d, it can run on two modes: "the machines using the legacy mode will have a file /etc/init.d/.legacy-bootordering", in which case you have to pass sequence and runlevel configuration through command line arguments.

为上面的例子设置的等效参数是

The equivalent argument set for the above example is

sudo update-rc.d 文件名开始 20 2 3 4 5 .停止 20 0 1 6 .

这篇关于Linux Ubuntu下启动时自动运行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆