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

已成功完成开机自启

相关推荐
czxyvX6 分钟前
010-Linux内核进程调度队列(了解)
linux
一路往蓝-Anbo26 分钟前
第 1 章:M33 领航——STM32MP257F-DK 硬件解密与启动逻辑重构
linux·stm32·嵌入式硬件·重构
暴力求解1 小时前
Linux--进程(四) 进程优先级与进程切换
linux·运维·服务器
Re_Virtual2 小时前
OpenEuler 20.03构建zabbix7.0 rpm包
linux·zabbix·openeuler
落羽的落羽3 小时前
【Linux系统】磁盘ext文件系统与软硬链接
linux·运维·服务器·数据库·c++·人工智能·机器学习
Codefengfeng3 小时前
Kali-linux中安装与使用Stegsolve
linux·运维·服务器
何中应4 小时前
如何在 Linux 系统中设置系统时间
linux·运维·服务器
予枫的编程笔记4 小时前
【Docker高级篇】吃透Linux底层:Namespace做隔离,Cgroups控资源,UnionFS搭存储
linux·人工智能·namespace·cgroups·unionfs·linux底层原理·容器核心技术
济6175 小时前
ARM Linux 驱动开发篇---Linux 设备树简介-- Ubuntu20.04
linux·arm开发·嵌入式linux驱动开发
leblancAndSherry5 小时前
阿里云轻量/ECS 实战:K3s + Helm + cert-manager + 云效 Codeup 全链路 CI/CD 落地(记录自用)
linux·运维·阿里云·ci/cd·kubernetes·云计算