Ubuntu开机自启动
Ubuntu18.0.4
查看/lib/systemd/system的rc.local.service文件(没有则创建)
默认
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19This 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
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
增加
1 | [Install] |
[Unit] 段: 启动顺序与依赖关系
[Service] 段: 启动行为,如何启动,启动类型
Install] 段: 定义如何安装这个配置文件,即怎样做到开机启动
创建
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16sudo touch /etc/rc.local
加上权限
sudo chmod +x /etc/rc.local
建立连接
ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/
里面放测试脚本,运行/home/script 目录下的start.sh脚本
!/bin/bash
test.sh
cd /home/script/
sh start.sh
exit 0在/home/script/的start.sh脚本中编写sh脚本即可
自启动jar包(加上环境)

ubuntu20.0.4
跟上面一样,修改的是/lib/systemd/system的rc-local.service文件
评论