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

已成功完成开机自启

相关推荐
女神下凡1 小时前
芯易选(152):炬芯(Actions)_开发指南
linux·arm开发·stm32·单片机·嵌入式硬件
qetfw4 小时前
EVE-NG 导入 Debian 虚拟机:VMDK 转 QCOW2 与启动验证
linux·前端·debian·github
master3364 小时前
Linux 用户与权限体系:由浅入深完全指南
linux·运维·服务器
骑着蜗牛撵大象3274 小时前
一次 sendto 一次 recvfrom:UDP 数据报在 Linux 内核里怎么走完一整圈
linux·网络·网络协议·udp·ux·sk_buff·端口分用
俊俊几年的6 小时前
RK3588 硬件架构详解:CPU、GPU、NPU 与 RKNN 软件栈
linux·c++·python·yolo·numpy·rockchip
沫璃染墨6 小时前
从零入门MySQL系列(一):Linux 环境下 MySQL 安装部署、服务启动与首次登录问题排查
linux·运维·数据库·sql·mysql·database·数据库架构
打工仔折腾 AI6 小时前
Linux网络:UDP一次sendto对应一次recvfrom的底层机制解析
linux·网络·人工智能·后端·python·性能优化·udp
程序员与背包客_CoderZ6 小时前
Linux C++异步网络编程:c-ares高性能DNS解析编码实战
linux·服务器·c语言·开发语言·网络·c++·网络编程
鱼很腾apoc6 小时前
【Redis】第4期 详解主从复制、哨兵、集群
linux·redis·学习·集群·主从复制·哨兵
老一岁7 小时前
Git详解_提交_回退_分支_合并
大数据·linux·git