ubuntu设置脚本开机自启动
- 人工智能
- 2025-08-12 13:42:03

rc-local.service flexmi@td1:~$ cd /lib/systemd/system/ flexmi@td1:/lib/systemd/system$ ls |grep rc-local.service rc-local.service rc-local.service.d flexmi@td1:/lib/systemd/system$ pwd /lib/systemd/system flexmi@td1:/lib/systemd/system$
确保有rc-local.service文件,没有手动添加,内容如下:
#flexmi@td1:/lib/systemd/system$ cat ./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 rc.local找到rc.local文件,没有就创建在/etc目录下,内容为你需要执行的脚本内容或者你需要执行的脚本启动命令
flexmi@td1:/lib/systemd/system$ cd /etc flexmi@td1:/etc$ ls |grep rc.local rc.local flexmi@td1:/etc$ cat ./rc.local #!/bin/bash cd /home/flexmi/cmss sudo ./start.sh exit 0 flexmi@td1:/etc$注意要给rc.local脚本文件添加执行权限
sudo chmod +x ./rc.local 启动服务 sudo systemctl enable rc-local sudo systemctl start rc-local.service sudo systemctl status rc-local.service 注意 如果服务启动失败,看看是不是rc.local的问题,脚本的开头一定要是 #!/bin/bashrc.local脚本的后面一定要加上exit 0下面是我在操作过程中的截图: 启动失败: 启动成功
ubuntu设置脚本开机自启动由讯客互联人工智能栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“ubuntu设置脚本开机自启动”
上一篇
实用小算法