ubuntu开机自启动

ubuntu开机自启动

1、建一个test.sh脚本,并写入

#!/bin/sh

gnome-terminal -x bash -c 'cd /home/文件路径/;python3 main.py'

exit 0

2、:wq!保存

3、创建rc-local.service文件(sudo vim /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

Alias=rc-local.service

4、建一个文件 vim /etc/rc.local

#!/bin/bash

**# 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.

开机启动的程序**

bash /xxx/xxx/xxx/start.sh &

exit 0

5、终端输入命令:

sudo systemctl start rc-local.service 启动服务

sudo systemctl enable rc-local.service 开机自动启动

sudo systemctl daemon-reload 更新服务

sudo systemctl restart rc-local.service 重启服务

sudo systemctl status rc-local.service 查看当前服务状态

6、找到

已成功完成开机自启

相关推荐
一匹电信狗12 分钟前
【MySQL】数据库表的操作
linux·运维·服务器·数据库·mysql·ubuntu·小程序
撬动未来的支点25 分钟前
【Linux】Linux 零拷贝技术全景解读:从内核到硬件的性能优化之道
linux·服务器·性能优化
ajassi200026 分钟前
开源 Linux 服务器与中间件(六)服务器--Lighttpd
linux·服务器·开源
立昂36 分钟前
Linux route
linux·运维
爱吃生蚝的于勒1 小时前
【Linux】深入理解进程(一)
java·linux·运维·服务器·数据结构·c++·蓝桥杯
heisd_11 小时前
使用搭载Ubuntu的树莓派开启热点
linux·运维·ubuntu
阿干tkl1 小时前
优麒麟(Ubuntu Kylin) 安装向日葵远程工具/ToDesk
linux·ubuntu·kylin
Goafan1 小时前
ubuntu20.04插入USB耳机无法识别
linux
无敌最俊朗@2 小时前
VMware Ubuntu 虚拟机网络故障分析报告
服务器·网络·ubuntu
Wins_calculator2 小时前
Fixed VLC snap on Ubuntu
linux·ubuntu·vlc·snap