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

已成功完成开机自启

相关推荐
小白同学_C1 天前
Lab4-Lab: traps && MIT6.1810操作系统工程【持续更新】 _
linux·c/c++·操作系统os
今天只学一颗糖1 天前
1、《深入理解计算机系统》--计算机系统介绍
linux·笔记·学习·系统架构
不做无法实现的梦~1 天前
ros2实现路径规划---nav2部分
linux·stm32·嵌入式硬件·机器人·自动驾驶
默|笙1 天前
【Linux】fd_重定向本质
linux·运维·服务器
陈苏同学1 天前
[已解决] Solving environment: failed with repodata from current_repodata.json (python其实已经被AutoDL装好了!)
linux·python·conda
“αβ”1 天前
网络层协议 -- ICMP协议
linux·服务器·网络·网络协议·icmp·traceroute·ping
不爱学习的老登1 天前
Windows客户端与Linux服务器配置ssh无密码登录
linux·服务器·windows
十日十行1 天前
修复root用户登录的浏览器无法跳转vscode问题
ubuntu
小王C语言1 天前
进程状态和进程优先级
linux·运维·服务器
xlp666hub1 天前
【字符设备驱动】:从基础到实战(下)
linux·面试