ubuntu服务器调用rc.local自动启动脚本问题-ubuntu-19.04-live-server版本

服务器版本
ubuntu-19.04-live-server-amd64

网上查了不少资料其实ubuntu 在ubuntu-18的版本里就修改了自动启动的方式了。

1. 创建一个rc.local

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 "this is a test" > /usr/local/text.log
exit 0

2.ubuntu修改这个自动脚本为可以执行

sudo chmod +x /etc/rc.local

3.创建一个执行service脚本

sudo 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

4.启动 让rc local 服务生效

 systemctl enable rc-local

Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /etc/systemd/system/rc-local.service.

5. 启动和状态查看

sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

重启机器


This entry was posted in Linux and tagged , . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/ubuntu-server-1904-auto-start/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力

One Response to ubuntu服务器调用rc.local自动启动脚本问题-ubuntu-19.04-live-server版本

  1. repostone says:

    非技术的路过。

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

  

  

About Me

静水流深,水滴石穿