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、找到

已成功完成开机自启

相关推荐
欧神附体1231 小时前
在虚拟机搭建本地仓库和网络仓库
linux·运维·服务器
是个西兰花2 小时前
Linux:深入解析Linux线程原理与实现
linux·运维·c++·线程·互斥锁
运维大师2 小时前
【Linux运维极简教程】07-磁盘管理与LVM
linux·运维·服务器
乖巧的妹子2 小时前
刷题总结知识
linux·服务器·windows
拳里剑气3 小时前
Linux:基础IO
linux·运维·服务器·io
小小龙学IT4 小时前
Day 2-3:Linux 文件与目录操作
linux
三8444 小时前
基本Linux命令总结
linux·运维·服务器
hehelm5 小时前
AI 大模型接入 SDK —项目概述
linux·服务器·网络·数据库·c++
mounter6255 小时前
跨越鸿沟:从内核驱动开发到超大规模云端生产环境的思考
linux·驱动开发·linux kernel·kernel
kdxiaojie5 小时前
Linux 驱动研究 —— V4L2 (3)
linux·运维·笔记·学习