ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

ubuntu18.04设置开机启动脚本

ubuntu18.04设置开机启动脚本

说明:内容来源于网络,并且通过AI工具重新整理归纳。

1、建立rc‑local.service文件

编辑 rc-local.service 服务配置文件

vim /etc/systemd/system/rc-local.service

把以下配置复制粘贴进去并保存

[Unit]
Description=/etc/rc.local Compatibility
# 脚本文件位置
ConditionPathExists=/etc/rc.local[Service]
Type=forking
# 配置的脚本文件rc.local为start
ExecStart=/etc/rc.local start
TimeoutSec=0  
# 标准输出  
StandardOutput=tty
RemainAfterExit=yes
# 优先级,当有多个开机启动文件时可以设置不同的值
SysVStartPriority=99 [Install]
WantedBy=multi-user.target

2、生成rc.local(红色字体修改为软件实际安装的文件夹名称及路径)

编辑 /etc/rc.local 文件

vim /etc/rc.local

写入下面脚本内容:

#!/bin/sh -e
#
# 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.
cd /data/lora/iot_vision_docker_private_deploy/lora_db;docker-compose up -d 
cd /data/lora/iot_vision_docker_private_deploy/lora_app;docker-compose up -d
exit 0

说明:exit 0 之前填写脚本需要执行的操作。

保存文件后,给 rc.local 提升执行权限:

chmod 755 /etc/rc.local

3、启动服务并检查状态

service rc-local start
service rc-local status
返回列表