notes/RK3568/荣品/开机启动.md

72 lines
955 B
Markdown
Raw Permalink Normal View History

2024-04-29 22:22:30 +08:00
### 开机启动
2023-10-19 15:39:03 +08:00
2024-04-29 02:07:50 +08:00
#### 复制程序到 /opt 目录下
2023-10-19 15:39:03 +08:00
```
cp /root/works/console_app/console_app /opt/app
```
2024-04-29 02:07:50 +08:00
#### 创建启动脚本
2023-10-19 15:39:03 +08:00
* 切换目录, 并创建文件
```
cd /opt
vim run.sh
```
* run.sh 文件内容
```
#! /bin/bash
cd /opt/
./app
```
2024-04-29 02:07:50 +08:00
#### 创建服务
2023-10-19 15:39:03 +08:00
* 切换目录, 并创建文件
```
cd /etc/systemd/system
vim console_app.service
```
* console_app.service 文件内容
```
[Unit]
Description=console app server
[Service]
Type=simple
#ExecStart=/home/rpdzkj/works/console_app/console_app
ExecStart=/opt/run.sh
Restart=on-failure
RestartSec=5s
# 30秒后在启动服务
TimeoutStartSec=infinity
ExecStartPre=/bin/sleep 30
[Install]
WantedBy=multi-user.target
```
2024-04-29 02:07:50 +08:00
#### 重新加载 Systemd
2023-10-19 15:39:03 +08:00
```
sudo systemctl daemon-reload
```
2024-04-29 02:07:50 +08:00
#### 启动服务
2023-10-19 15:39:03 +08:00
```
sudo systemctl start console_app
```
2024-04-29 02:07:50 +08:00
#### 开机启动
2023-10-19 15:39:03 +08:00
```
sudo systemctl enable console_app
2023-10-18 17:00:19 +08:00
```