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

已成功完成开机自启

相关推荐
刚入门的大一新生几秒前
Linux-命令行参数和环境变量
linux·运维·服务器
我星期八休息36 分钟前
Linux I/O多路转接—epoll
java·linux·运维·服务器·开发语言·jvm·算法
wuminyu1 小时前
Java FFM处理网络读写事件源码剖析
java·linux·c语言·jvm·c++
实心儿儿1 小时前
Linux —— 数据链路层
linux·网络·智能路由器
智购科技无人售货机厂家2 小时前
2026自动售货机出货口防夹手设计:从红外检测到电机反转的工程实践~YH
大数据·linux·单片机·嵌入式硬件·微信
新时代牛马3 小时前
异常向量与VBAR_ELx:Linux entry.S 中的vectors 布局
linux·运维·服务器
H_oRIZoN_3 小时前
Linux入门DAY32(文件 IO、进程、线程、IPC 通信)
linux·运维·服务器
0+1113 小时前
Linux --Ext系列文件系统
linux·运维·服务器
攻城有术4 小时前
专项攻克——研发排查Linux各类问题命令+实战案例
linux·运维·服务器
自动化和Linux4 小时前
【win11+virtual Box简单安装centos7,不使用GPT分区】
linux·gpt·虚拟现实