服务器版本
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 |
重启机器
非技术的路过。