美文网首页
树莓派搭建Awtrix服务器

树莓派搭建Awtrix服务器

作者: 剑山 | 来源:发表于2023-01-14 15:32 被阅读0次

    恩,装系统就不用说了吧,有个事情是树莓派默认32位系统,我用的4B还是建议装64位的,因为做其他用处的时候有的时候只有arm64版本的,32位的装不了。。。

    apt-get换源

    因为是64位的,需要选64位的源

    大概的过程就是两个地方。
    第一个

    sudo nano /etc/apt/sources.list
    

    改为

    deb http://mirrors.tuna.tsinghua.edu.cn/debian buster main contrib non-free
    deb http://mirrors.tuna.tsinghua.edu.cn/debian-security/ buster/updates main contrib non-free
    deb http://mirrors.tuna.tsinghua.edu.cn/debian buster-updates main contrib non-free
    

    第二个是/etc/apt/sources.list.d/raspi.list这里改为

    deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui
    

    然后记得要sudo apt updatesudo apt upgrade

    搭建Awtrix

    大概是按照这个教程https://sakitami.github.io/posts/7968d939/

    安装jdk

    sudo apt install default-jdk
    

    下载awtrix到树莓派

    因为好像被墙了,我是下载到U盘上然后拷过去的
    https://awtrixdocs.blueforcer.de/#/en-en/host
    我下载到了这个位置/usr/local/awtrix

    写service

    首先sudo nano /etc/systemd/system/awtrix.service然后在里面写入

    [Unit]
    Description = AWTRIX Service
    After network.target = awtrix.service
    
    [Service]
    Type = forking
    WorkingDirectory =/usr/local/awtrix
    ExecStart = /usr/local/bin/awtrix.sh start
    ExecStop = /usr/local/bin/awtrix.sh stop
    ExecReload = /usr/local/bin/awtrix.sh reload
    
    [Install]
    WantedBy=multi-user.target
    

    然后创建sh文件,sudo nano /usr/local/bin/awtrix.sh

        SERVICE_NAME=awtrix
        PATH_TO_JAR=/usr/local/awtrix/awtrix.jar
        PID_PATH_NAME=/tmp/awtrix-pid
        case $1 in
            start)
                echo "Starting $SERVICE_NAME ..."
                if [ ! -f $PID_PATH_NAME ]; then
                    sudo nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
                                echo $! > $PID_PATH_NAME
                    echo "$SERVICE_NAME started ..."
                else
                    echo "$SERVICE_NAME is already running ..."
                fi
            ;;
            stop)
                if [ -f $PID_PATH_NAME ]; then
                    PID=$(cat $PID_PATH_NAME);
                    echo "$SERVICE_NAME stoping ..."
                    kill $PID;
                    echo "$SERVICE_NAME stopped ..."
                    rm $PID_PATH_NAME
                else
                    echo "$SERVICE_NAME is not running ..."
                fi
            ;;
            restart)
                if [ -f $PID_PATH_NAME ]; then
                    PID=$(cat $PID_PATH_NAME);
                    echo "$SERVICE_NAME stopping ...";
                    kill $PID;
                    echo "$SERVICE_NAME stopped ...";
                    rm $PID_PATH_NAME
                    echo "$SERVICE_NAME starting ..."
                    sudo nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
                                echo $! > $PID_PATH_NAME
                    echo "$SERVICE_NAME started ..."
                else
                    echo "$SERVICE_NAME is not running ..."
                fi
            ;;
        esac
    

    老实说上面这部分我没有很看懂,大概就是运行那个jar文件吧。然后加权限sudo chmod +x /usr/local/bin/awtrix.sh,起服务sudo systemctl enable awtrix.servicesudo systemctl start awtrix.service

    测试

    打开设备的ip地址,端口号7000,应该可以看到后台界面了


    image.png

    相关文章

      网友评论

          本文标题:树莓派搭建Awtrix服务器

          本文链接:https://www.haomeiwen.com/subject/alpgcdtx.html