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

已成功完成开机自启

相关推荐
youyoulg3 分钟前
opencode在Linux终端中无法复制文字的解决方法
linux·服务器·人工智能
终端鹿8 分钟前
Vue3 + TypeScript 大型项目状态管理:Pinia 类型安全最佳实践
安全·ubuntu·typescript
2301_807367199 分钟前
Linux(CentOS)安装 Nginx
linux·nginx·centos
yy_xzz10 分钟前
【Linux开发】 05 Linux 多进程并发服务器
linux·服务器·github
minji...12 分钟前
Linux 进程间通信(四)System V共享内存
linux·运维·服务器
艾莉丝努力练剑13 分钟前
【Linux信号】Linux进程信号(中):信号保存、信号处理(含“OS是如何运行的?”)
大数据·linux·运维·服务器·数据库·c++·mysql
Du_chong_huan23 分钟前
《Linux 是怎样工作的》第 2 章:用户模式实现的功能
linux·运维·服务器
学电子她就能回来吗33 分钟前
【无标题】
linux·运维·服务器
有毒的教程1 小时前
Ubuntu 安装完成后网络配置教程
linux·网络·ubuntu
刚入门的大一新生1 小时前
Linux-Linux的基础指令3
linux·运维·服务器