简体   繁体   English

启动时运行命令

[英]Running a command on startup

I want to run this command on my ubuntu server installation on startup: 我想在启动时在我的ubuntu服务器安装上运行以下命令:

~/factorio/bin/x64/factorio --start-server-load-latest --server-settings ~/factorio/data/server-settings.json

I tried putting this code in the /etc/rc.local directory: 我尝试将这段代码放在/etc/rc.local目录中:

~/factorio/bin/x64/factorio --start-server-load-latest --server-settings ~/factorio/data/server-settings.json || exit 1
exit 0

And the command doesn't run on startup. 而且该命令不会在启动时运行。 I know that the command runs when I type it into the command line, but it won't run for some reason when I put it in the /etc/rc.local file. 我知道命令是在命令行输入时运行的,但是当我将其放在/etc/rc.local文件中时,由于某种原因它不会运行。 Can anyone tell me where the error is in my code or another way that I could get this command to run on boot? 谁能告诉我错误在代码中的位置,或者我可以使此命令在引导时运行的其他方式?

Open crontab. 打开crontab。

 sudo crontab -e

Then try adding you command as root to the bottom.(use nano editor). 然后尝试将您的命令作为root添加到底部。(使用nano编辑器)。

 @reboot root ~/factorio/bin/x64/factorio --start-server-load-latest --server-settings ~/factorio/data/server-settings.json

Note that this will run under root so you will need to change the path of every file from '~/call' to '/full/path/to/file' 请注意,这将在根目录下运行,因此您需要将每个文件的路径从“〜/ call”更改为“ / full / path / to / file”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM