ubuntu 22.04启用rc.local来实现开机启动调用某些脚本

Ubuntu 22.04 中rc.local 服务并没有启用,手动配置的步骤如下

1、检查rc-local.service服务是否已经配置开机启动

root@mydbserver:~# systemctl is-enabled rc-local.service
static

2、rc-local.service文件增加2行

root@mydbserver:~# vim /lib/systemd/system/rc-local.service
[Install]
WantedBy=multi-user.target

3、检查rc-local.service服务是否已经配置开机启动

root@mydbserver:~# systemctl is-enabled rc-local.service
disabled

4、对rc-local.service服务配置开机启动,并且启动它

root@mydbserver:~# systemctl enable rc-local.service
Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /lib/systemd/system/rc-local.service.
root@mydbserver:~# systemctl is-enabled rc-local.service
enabled
root@mydbserver:~# systemctl start rc-local.service
root@mydbserver:~# systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; enabled; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: inactive (dead)
  Condition: start condition failed at Mon 2024-07-01 15:20:53 CST; 23s ago
             └─ ConditionFileIsExecutable=/etc/rc.local was not met
       Docs: man:systemd-rc-local-generator(8)

Jul 01 15:20:53 wcslsf5t9hm3 systemd[1]: Condition check resulted in /etc/rc.local Compatibility being skipped.

root@mydbserver:~# vim /etc/rc.local
#!/bin/bash
root@mydbserver:~# sudo chmod 777 /etc/rc.local

root@mydbserver:~# systemctl start rc-local.service
root@mydbserver:~# systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; enabled; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: active (exited) since Mon 2024-07-01 15:25:16 CST; 4s ago
       Docs: man:systemd-rc-local-generator(8)
    Process: 2618076 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Jul 01 15:25:16 wcslsf5t9hm3 systemd[1]: Starting /etc/rc.local Compatibility...
Jul 01 15:25:16 wcslsf5t9hm3 systemd[1]: Started /etc/rc.local Compatibility.

5、之后就可以直接在/etc/rc.local文件中添加可执行的脚本文件,开机调用这个可执行的脚本文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值