[Share Experiences] 让Deepin开机自启运行一些命令(基本debian系列都能用)
Tofloor
poster avatar
川顺页
deepin
2023-06-15 06:57
Author

设置后台开机自启动

  1. 编辑rc.local服务
sudo vim /lib/systemd/system/rc-local.service

最后面新增几行

[Install]
WantedBy=multi-user.target
Alias=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

  1. 新建/etc/rc.local文件
sudo vim /etc/rc.local

写入文件如下:

#!/bin/bash
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing. 
# 下面是你想要执行的自启动命令
# 例如:echo hello world
exit 0
sudo chmod +x /etc/rc.local
  1. 重启rc.local服务,查看效果

先创建软链接

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

再重启服务

sudo systemctl daemon-reload
sudo systemctl restart rc-local
  1. 开机自启动
sudo systemctl enable rc-local.service
Reply Favorite View the author
All Replies
阿尼樱奈奈
deepin
2023-06-15 07:00
#1

like

Reply View the author
donaldsebleung
deepin
2023-06-15 17:36
#2

学习了,感谢分享kissing_heart

Reply View the author
jjcui8595
deepin
2023-06-15 17:46
#3

学习,收藏

Reply View the author
xuqi
deepin testing team
2023-06-16 17:22
#4

like

Reply View the author
树先生tree666
deepin
2024-06-02 15:10
#5

学习了

Reply View the author