Ubuntu18.04设置开启自启应用

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 文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值