UOS创建开机自启程序或脚本
通过创建桌面启动程序实现开机自启
创建可执行程序或脚本启动文件xx.desktop,文件格式如下
[Desktop Entry]
Type=Application
Encoding=UTF-8
Exec=/usr/bin/xx.sh #可执行程序路径
Name=xx #程序名称
拷贝脚本到/usr/bin目录
sudo cp -f xx.sh /usr/bin/
chmod a+x /usr/bin/xx.sh
设置开机自启动,启动时间为开机输入密码进入桌面的瞬间执行
sudo cp -f xx.desktop /etc/xdg/autostart/
sudo chmod 644 /etc/xdg/autostart/xx.desktop
通过配置rc-local服务实现开机自启
uos默认没有开启rc-local服务,所以在创建/etc/rc.local文件,并且向该文件写入开机需要执行的命令是不会生效的,需要先开启并配置rc-local.service服务,以下为配置相关步骤:
编辑/lib/systemd/system/rc-local.service文件,在文件结尾添加以下两行代码
[Install]
WantedBy=multi-user.target
lzc@lzc-PC:~$ cat /lib/systemd/system/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
启动rc-local.service服务并设置开机自启
systemctl start rc-local.service
systemctl enable rc-local.service
创建rc.local文件并赋予755的权限,往/etc/rc.local文件中写入开机需要执行的命令即可
touch /etc/rc.local
chmod 755 /etc/rc.local
原文链接:https://blog.csdn.net/zZzZzZ__/article/details/120054678
评论 (0)