0 我的配置
#!/bin/sh -e
# Gogs
su - ubuntu -c "/home/ubuntu/service/gogs/gogs web &"
# MinDoc
su - ubuntu -c "cd /home/ubuntu/service/mindoc;./mindoc-linux &"
# Java
/home/ubuntu/deploy/auto-admin/run
/home/ubuntu/deploy/caseapi/run
exit 0
1 创建文件 rc-local.service
sudo vim /etc/systemd/system/rc-local.service
2 写入内容 rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
3 创建文件 rc.local
sudo vim /etc/rc.local
4 写入内容 rc.local
#!/bin/sh -e
# 在这里写入开机时要执行的命令
echo "看到这行字,说明添加自启动脚本成功。" > /usr/local/test.log
exit 0
5 设置权限 rc.local
sudo chmod +x /etc/rc.local
6 启用服务
sudo systemctl enable rc-local