如何在Ubuntu启动时运行脚本? [英] How to run a script at the start up of Ubuntu?

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

问题描述

当系统在Ubuntu中启动时,我想在后台运行一些Java程序.我试图在/etc/init.d目录中添加脚本,但是无法启动程序.即程序未启动.我该怎么办?

I want to run some Java programs in the background when the system boots in Ubuntu. I have tried to add a script in /etc/init.d directory but failed to start a program. i.e programs are not started. What should I do for that?

推荐答案

首先,在启动时运行事物的最简单方法是将它们添加到文件/etc/rc.local.

另一种简单的方法是在crontab中使用@reboot.阅读cron联机帮助页以了解详细信息.

Another simple way is to use @reboot in your crontab. Read the cron manpage for details.

但是,如果您想正确执行操作,除了向/etc/init.d中添加脚本外,还需要告诉ubuntu何时应运行脚本以及使用什么参数.这是通过命令update-rc.d完成的,该命令创建了从某些/etc/rc*目录到脚本的符号链接.因此,您需要执行以下操作:

However, if you want to do things properly, in addition to adding a script to /etc/init.d you need to tell ubuntu when the script should be run and with what parameters. This is done with the command update-rc.d which creates a symlink from some of the /etc/rc* directories to your script. So, you'd need to do something like:

update-rc.d yourscriptname start 2

但是,真正的初始化脚本应该能够处理各种命令行选项,并以其他方式集成到启动过程中.文件/etc/init.d/README具有一些详细信息和进一步的指针.

However, real init scripts should be able to handle a variety of command line options and otherwise integrate to the startup process. The file /etc/init.d/README has some details and further pointers.

这篇关于如何在Ubuntu启动时运行脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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