首页 > 系统相关 >ubuntu20.04 设置开机启动

ubuntu20.04 设置开机启动

时间:2022-08-16 08:36:02浏览次数:63  
标签:ubuntu20.04 systemd service etc test 设置 rc 开机 local

 

修改 rc-local.service 文件的权限

sudo chmod 777 /lib/systemd/system/rc-local.service

修改 rc-local.service 文件

打开 rc-local.service,可以看到有以下内容:

# SPDX-License-Identifier: LGPL-2.1+
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

增加以下内容:

[Install]
WantedBy=multi-user.target
Alias=rc-local.service

保存,退出。


修改 /etc/rc.local 文件
查看系统中有无 /etc/rc.local 这个文件,没有则自己创建一个。
写入以下内容(清空文件中原有所有内容):

#!/bin/sh
echo "看到这行字,说明添加自启动脚本成功。" > /usr/local/test.log
exit 0

 

赋予权限

sudo chmod +x /etc/rc.local

 

创建软链接

ln -s /lib/systemd/system/rc-local.service /etc/systemd/system/

 

重启Ubuntu后,去 /usr/local 下看看有没有生成test.log这个文件以及这个文件的内容。

cat /usr/local/test.log

 

其他说明

如果在 /etc/rc.local 中添加的是 ./test.sh 这种类型的,要在末尾加上&,不然重启ubuntu的时候会卡在启动界面进不去系统。

 


原文链接:https://blog.csdn.net/guilutian0541/article/details/124111560

标签:ubuntu20.04,systemd,service,etc,test,设置,rc,开机,local
From: https://www.cnblogs.com/dwj192/p/16590318.html

相关文章

  • Express 项目,res.cookie() 设置 Cookie 无法被保存在浏览器的 Application 中
    res.cookie()给客户端响应头封装的Cookie无法被保存在客户端浏览器的Application中,只能在Set-Cookie中看到有这个值:经过多方的搜索和查询,前后端分离项目中,存在跨......
  • podman的基本设置和使用,签名分发镜像推送到harbor仓库
    podman的基本设置和使用目录podman的基本设置和使用podman的基本设置和使用运行示例容器列出正在运行的容器检查正在运行的容器测试httpd服务器查看容器日志查看容器的pid......
  • Ubuntu20.04下微信、QQ、腾讯会议等常用软件的安装
    使用Ubuntu系统的一大痛点就是没有Windows下微信、QQ、腾讯会议等常用软件的适配,好在随着国产linux系统优麒麟UbuntuKylin的发展,这些软件也逐渐有了deb安装包,方便我们在U......
  • podman的基本设置和使用
    podman的基本设置和使用运行一个示例容器[root@localhost~]#podmanrun-dt-p8080:8080/tcp-eHTTPD_VAR_RUN=/run/httpd-eHTTPD_MAIN_CONF_D_PATH=/etc/httpd/co......
  • podman的基本设置与podman签名
    目录podman的基本设置和使用签名和分发podman的基本设置和使用//注:因为只有一个容器所有使用的-l参数创建一个容器并放在后台运行做一个端口映射-p[root@harborhar......
  • php新建画布并设置颜色
    <?phpheader("Content-Type:image/png");$img=imagecreatetruecolor(400,300);//imagejpeg($img);//imagejpeg($img,"./img/copy_img01.jpg",10);$color1=imagecol......
  • 设置SQL*Plus运行环境
    set命令基本语法在Oracle11g数据库中,用户可以使用set命令来设置SQL*Plus的运行环境;setsystem_variablevalue;system_variable:变量名;value:变量值;通过set命令设置......
  • Arthas(6):options全局设置
    options作用:全局开关名称默认值描述unsafefalse是否支持对系统级别的类进行增强,打开该开关可能导致把JVM搞挂,请慎重选择!dumpfalse是否支持被增强了的......
  • 开机自启rc.local文件模板
    #Ubuntu没有开机自启文件,可以在/etc/目录下面创建一个rc.local文件,并且给他一个可执行权限就行了#rc.local文件格式如下:#!/bin/sh-e#rc.local##Thisscriptisexecut......
  • CloseableHttpClient设置超时时间demo 未设置默认是2分钟
    #CloseableHttpClient设置超时时间demo未设置默认是2分钟importorg.apache.http.HttpHeaders;importorg.apache.http.client.config.RequestConfig;importorg.ap......