Duke Yin's Technology database

Wake On LAN工具 UpSnap

一个德国小哥写的局域网唤醒工具,我用上去觉得很不错,不用自己造轮子了。

如果家里或者公司有7X24小时开机的设备,安装了以后把WEB给公网,就能随时随地对局域网设备唤醒、关机。

GitHub地址:https://github.com/seriousm4x/UpSnap

常见有两种部署方式,二进制或Docker:

Docker

Docker compose文件

services:
  upsnap:
    container_name: upsnap
    image: seriousm4x/upsnap:latest
    network_mode: host
    restart: unless-stopped
    volumes:
      - /volume1/docker/upsnap/data:/app/pb_data
    # # To use a non-root user, create the mountpoint first (mkdir data) so that it has the right permission.
    # user: 1000:1000
    environment:
      - TZ=Asia/Shanghai # Set container timezone for cron schedules
      - UPSNAP_INTERVAL=*/10 * * * * * # Sets the interval in which the devices are pinged
      - UPSNAP_SCAN_RANGE=192.168.2.0/24 # Scan range is used for device discovery on local network
      - UPSNAP_SCAN_TIMEOUT=500ms # Scan timeout is nmap's --host-timeout value to wait for devices (https://nmap.org/book/man-performance.html)
      - UPSNAP_PING_PRIVILEGED=false # Set to false if you don't have root user permissions
      - UPSNAP_WEBSITE_TITLE=Yongping WOL # Custom website title
    # # dns is used for name resolution during network scan
    dns:
      - 192.168.2.1
    # # you can change the listen ip:port inside the container like this:
    # entrypoint: /bin/sh -c "./upsnap serve --http 0.0.0.0:5000"
    # healthcheck:
    #   test: curl -fs "http://localhost:5000/api/health" || exit 1
    #   interval: 10s
    # # or install custom packages for shutdown
    # entrypoint: /bin/sh -c "apk update && apk add --no-cache <YOUR_PACKAGE> && rm -rf /var/cache/apk/* && ./upsnap serve --http 0.0.0.0:8090"

docker-compose up 后,就可以在局域网浏览器访问 ip:8090 来配置WOL。

配置差不多后用反代就能开放到公网。

Docker部署会有一些限制,如果你家里有一台常开的Debian/ubuntu,也可以使用二进制文件,更加原生,如果使用root用户执行会获得全功能:

二进制运行

在项目Release页面找到设备CPU架构对应的包,比如Linux X86 对应的就是 UpSnap_5.2.4_linux_amd64.zip

下载后解压得到一个单文件 upsnap

建议将这个文件放置在 /opt/upsnap/upsnap

创建systemd服务

sudo nano /etc/systemd/system/upsnap.service

写入以下内容

[Unit]
Description=UpSnap Wake-on-LAN Service
After=network.target

[Service]
Type=simple
WorkingDirectory=/opt/upsnap
ExecStart=/opt/upsnap/upsnap serve --http=0.0.0.0:8080 #指定端口,修改为你想要的
Restart=on-failure
RestartSec=3

# 如果想以非 root 启动,取消注释并指定你自己的用户
# User=duke

[Install]
WantedBy=multi-user.target

保存退出

重载systemd,启动服务

sudo systemctl daemon-reload
sudo systemctl start upsnap

检查运行状态

sudo systemctl status upsnap

如果正常,你会看到它正在监听8080端口。

设置开机自启

sudo systemctl enable upsnap

开放防火墙端口

sudo ufw allow 8080/tcp

这个时候就可以在浏览器打开 服务器ip:8080,开始设置。

其他

停止服务

sudo systemctl stop upsnap

重启服务

sudo systemctl restart upsnap

查看日志

journalctl -u upsnap -f

修改端口

修改服务文件 /etc/systemd/system/upsnap.service 中的 ExecStart

ExecStart=/opt/upsnap/upsnap serve --http=0.0.0.0:9000

然后执行

sudo systemctl daemon-reload
sudo systemctl restart upsnap

对于PVE系统,默认配置无法获取开机状态,在custom ping选项里填入自定义命令可以正常获取到开机状态(例如PVE的IP是192.168.2.3,web端口是默认的8006):

nc -z -w 2 192.168.2.3 8006

# #

发布评论

评论

标注 * 的为必填项。