Linux
前言
在Linux开发过程中,我们写好软件之后,可能会设置开机自动启动,下面说一下在Ubuntu18.04系统下如何设置
方法
1.进入下面目录, 编辑 rc.local.service文件
cd /lib/systemd/system
sudo vi rc.local.service
在末尾添加 [Install]
字段,如下
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
2.创建 rc.local脚本(ubuntu 18.04 下没有这个脚本,需自行创建),并添加执行权限
touch /etc/rc.local
注意:设置权限!
chmod a+x /etc/rc.local
3.在 /etc/systemd/system目录下创建软链接
ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/
4.修改 rc.local 脚本
#!/bin/bash
/root/tty
这样开机重启就会运行我们 /roo/root 文件