bash 我的无头 ubuntu 18.04 中缺少 /etc/rc.local

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51434915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:59:22  来源:igfitidea点击:

/etc/rc.local is missing from my headless ubuntu 18.04

bashubuntu

提问by quackingplatypus

I am currently hosting a minecraft server on ubuntu server 18.04 LTS. I have a .sh script to start the server's java file, and I would like to run it at startup so that the minecraft server starts when the physical server boots. I wished to do this via /etc/rc.local. However, I do not see rc.local in that location. Is it in a different location for this version of ubuntu, or is there an entirely different method I should use to run this .sh at startup?

我目前在 ubuntu 服务器 18.04 LTS 上托管 minecraft 服务器。我有一个 .sh 脚本来启动服务器的 java 文件,我想在启动时运行它,以便在物理服务器启动时启动 minecraft 服务器。我希望通过 /etc/rc.local 执行此操作。但是,我在那个位置没有看到 rc.local。对于此版本的 ubuntu,它是否位于不同的位置,还是我应该使用完全不同的方法在启动时运行此 .sh?

回答by wuseman

Set a crontab for this

为此设置一个 crontab

Make sure the file is executable:

确保文件是可执行的:

chmod +x /path_to_you_file/your_file/file.sh

To edit crontab file:

编辑 crontab 文件:

crontab -e

Then add this:

然后添加这个:

@reboot  /path_to_you_file/your_file/file.sh

回答by cola

There is no "/etc/rc.local" file on Ubuntu 18.04, but you can create it.

Ubuntu 18.04 上没有“/etc/rc.local”文件,但您可以创建它。

Create the file with a text editor:

使用文本编辑器创建文件:

sudo nano /etc/rc.local

Paste the following lines and replace "COMMANDS" with the commands to be executed at system startup:

粘贴以下几行并将“COMMANDS”替换为系统启动时要执行的命令:

#!/bin/sh -e
COMMANDS
exit 0

Add the execute permission on the file:

添加文件的执行权限:

chmod +x /etc/rc.local

回答by td4u

rc.local is disabled by default. Enable by using this command

默认情况下禁用 rc.local。使用此命令启用

sudo systemctl enable rc-local.service