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

已成功完成开机自启

相关推荐
行云流水剑30 分钟前
【学习记录】在 Ubuntu 中将新硬盘挂载到 /home 目录的完整指南
服务器·学习·ubuntu
藥瓿亭34 分钟前
K8S认证|CKS题库+答案| 7. Dockerfile 检测
运维·ubuntu·docker·云原生·容器·kubernetes·cks
vortex51 小时前
探索 Shell:选择适合你的命令行利器 bash, zsh, fish, dash, sh...
linux·开发语言·bash·shell·dash
GalaxyPokemon1 小时前
LeetCode - 148. 排序链表
linux·算法·leetcode
懒羊羊大王呀2 小时前
Ubuntu20.04中 Redis 的安装和配置
linux·redis
杰哥技术分享2 小时前
在 CentOS 上安装 Docker 和 Docker Compose 并配置使用国内镜像源
linux·docker·centos
知更鸟呆呆2 小时前
【Linux操作系统】基础开发工具(yum、vim、gcc/g++)
linux·运维·vim
xiangyong582 小时前
ubuntu系统文件误删(/lib/x86_64-linux-gnu/libc.so.6)修复方案 [成功解决]
linux·ubuntu·gnu
t198751283 小时前
Linux 上的 Tomcat 端口占用排查
linux·tomcat·firefox
小狗爱吃黄桃罐头3 小时前
正点原子[第三期]Arm(iMX6U)Linux移植学习笔记-12.1 Linux内核启动流程简介
linux·arm开发·学习