美文网首页
设置linux设置开机自启动应用程序

设置linux设置开机自启动应用程序

作者: 南瓜pump | 来源:发表于2022-03-10 09:41 被阅读0次

1.新建文件:

vi /etc/systemd/system/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

2.新建文件:

sudo vi /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.

echo "执行自启动脚本成功!" > /usr/local/test.log
echo "启动docker服务..." | tee -a /usr/local/test.log
sudo docker start $(sudo docker ps -a | awk '{ print $1}' | tail -n +2)
exit 0

3.加权限

chmod +x /etc/rc.local

4.允许开机自启

systemctl enable rc-local

5.手动启动服务

systemctl start rc-local.service

6.检查服务状态

systemctl status rc-local.service

7.查看日志

cat /usr/local/test.log

相关文章

网友评论

      本文标题:设置linux设置开机自启动应用程序

      本文链接:https://www.haomeiwen.com/subject/mqrfdrtx.html