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

已成功完成开机自启

相关推荐
再睡一夏就好13 分钟前
深入Linux线程:从轻量级进程到双TCB架构
linux·运维·服务器·c++·学习·架构·线程
小小药19 分钟前
09-vmware配置虚机连接互联网-nat模式
linux·运维·centos
Bright Xu1 小时前
Qemu 安装 LoongArch架构 Fedora Remix F42 Linux系统
linux·loongarch·国产cpu
莫白媛1 小时前
Linux创作笔记综合汇总篇
linux·运维·笔记
studytosky1 小时前
Linux系统编程:深度解析 Linux 进程,从底层架构到内存模型
linux·运维·服务器·开发语言·架构·vim
wdfk_prog1 小时前
[Linux]学习笔记系列 -- [fs]buffer
linux·笔记·学习
Stella25212 小时前
实习日志|知识总结
linux·服务器·软件测试·数据库
weixin_462446232 小时前
【原创实践】使用 shell 脚本批量创建 Linux 用户并生成随机密码
linux·服务器·前端
可爱又迷人的反派角色“yang”2 小时前
redis知识点总集
linux·运维·数据库·redis·缓存
海奥华22 小时前
进程调度算法 笔记总结
linux·运维·服务器·笔记·学习