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

已成功完成开机自启

相关推荐
深念Y2 小时前
从 Windows 迁移到 Linux 开发环境的记录
linux·windows·链接·bun·ram·imdisk
知无不研3 小时前
Linux I/O复用之epoll
linux·服务器·epoll·socket编程
苏宸啊4 小时前
linux网络编程udp服务器和客户端代码编写(echo版本和字典版本)
linux·网络
~|Bernard|4 小时前
Linux 定时任务(Cron)完整教程
linux·运维·服务器
小雪崩4 小时前
嵌入式学习 day25:哈希表及排序与查找
linux·c语言·数据结构·学习·排序算法
奇树谦5 小时前
HDD 为什么适合顺序大文件读写:从 RAID 5 到 RAID 50 的原理与性能分析
linux·运维·网络
hi_ro_a6 小时前
Linux基础开发工具详解
linux·运维·服务器
嵌入式阿蔡6 小时前
Linux_01:交叉编译与开发环境实战——从单片机跨到 Linux 的第一道坎
linux·运维·网络·单片机·嵌入式硬件·嵌入式实时数据库
Pocker_Spades_A7 小时前
终端里也能斗地主:Linux部署Ratel,从本地对战到公网联机
linux·运维·服务器
佳児素花痴╮7 小时前
C语言链接库
linux·运维·服务器