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

admin2024-07-01  11

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文件中添加可执行的脚本文件,开机调用这个可执行的脚本文件

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明原文出处。如若内容造成侵权/违法违规/事实不符,请联系SD编程学习网:675289112@qq.com进行投诉反馈,一经查实,立即删除!