linux开发板开机启动向日葵

硬件:orangepi 5 pro

操作系统:ubuntu 20.4 lts

安装向日葵

根据我的实测,arm架构的ubuntu系统只能安装向日葵提供的麒麟系统的那个版本,具体安装方式官网下载页面有

允许任意用户连接到 X11

使用root用户登录后打开终端输入一下命令,至于X11是什么可以自行搜索,我也一知半解,可以理解为一个图形界面的后端接口

powershell 复制代码
xhost +          #允许任意用户连接到X11

编写python脚本

python 复制代码
# coding:utf-8 
import subprocess 
import threading
import time
import os  # 导入 os 模块
from datetime import datetime  # 导入 datetime 模块

def is_connected():
    try:
        output = subprocess.check_output("ping -c 1 www.baidu.com", shell=True)
        return "1 packets transmitted, 1 received" in output.decode()
    except subprocess.CalledProcessError:
        return False

def task_1():
    # 设置 XDG_RUNTIME_DIR 环境变量
    os.environ['XDG_RUNTIME_DIR'] = '/run/user/1000'  # 替换为您的运行时文件目录
    
    isOpenXRK=False
    xCount=0        #计数
    while(True):  
        print("线程依然活着")
        time.sleep(3)
        xCount=xCount+1
        if xCount<10:
            continue
        else:
            xCount=0
        # 调用函数来验证联网状态
        if is_connected():
            print("已联网")
            if not isOpenXRK:
                # 设置 DISPLAY 环境变量
                #os.environ['DISPLAY'] = ':0'  # 设置显示服务器地址为默认值,经过测试这句可以不要
                
                # 启动进程并等待其完成
                process = subprocess.Popen(['/usr/local/sunlogin/bin/sunloginclient'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                stdout, stderr = process.communicate()
                # 打印输出和时间
                print("向日葵客户端输出:", stdout.decode())
                print("向日葵客户端错误:", stderr.decode())
                print("时间:", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))  # 输出当前时间,精确到秒
                isOpenXRK=True
                # 如果有错误,打印错误信息
                if stderr:
                    print(stderr.decode())
                
                
        else:
            print("未联网")
            print("等待三秒 ")
        

if __name__== "__main__" :
    task1=threading.Thread(target=task_1,args=())
    task1.start()
    print("开启了线程")

使用supervisor管理该脚本开机启动

supervisor的使用方法这里就不赘述了,网上可以搜到很多,是一个进程管理工具

最后贴一张效果图,pi放在家里,刚reboot过,我在外面用外网连的

相关推荐
啊吧怪不啊吧10 小时前
UU远程协助迎来升级!第一期更新实测
运维·服务器·远程工作
一 乐15 小时前
婚纱摄影网站|基于ssm + vue婚纱摄影网站系统(源码+数据库+文档)
前端·javascript·数据库·vue.js·spring boot·后端
C_心欲无痕15 小时前
ts - tsconfig.json配置讲解
linux·前端·ubuntu·typescript·json
冰西瓜60016 小时前
国科大2025操作系统高级教程期末回忆版
linux
1.14(java)16 小时前
SQL数据库操作:从CRUD到高级查询
数据库
HIT_Weston16 小时前
93、【Ubuntu】【Hugo】搭建私人博客:面包屑(一)
linux·运维·ubuntu
Full Stack Developme17 小时前
数据库索引的原理及类型和应用场景
数据库
cuijiecheng201817 小时前
Linux下Beyond Compare过期
linux·运维·服务器
喵叔哟17 小时前
20.部署与运维
运维·docker·容器·.net
HIT_Weston17 小时前
92、【Ubuntu】【Hugo】搭建私人博客:侧边导航栏(六)
linux·运维·ubuntu