NatPierce & Sunshine systemctl 服务配置指南

NatPierce & Sunshine systemctl 服务配置指南

概述

本文记录 natpierce 和 sunshine 两个服务的正确配置方法。

区别

环境 适合运行 图形支持
系统服务 (root) 系统守护进程、硬件服务 ❌ 无图形环境
用户服务 (普通用户) GUI 程序、用户级守护 ✅ 完整图形环境

root 用户没有图形化界面环境(没有 DISPLAY、无 Xauthority、无 DBus 会话等),因此 GUI 程序必须用用户服务运行。


1. NatPierce 服务(系统级服务)

特点

  • 系统守护进程
  • root 权限运行
  • 无需图形界面

服务文件

ini 复制代码
[Unit]
Description=NatPierce Service
After=network.target

[Service]
Type=simple
ExecStart=/opt/natpierce/natpierce
Restart=always
RestartSec=5
User=root

[Install]
WantedBy=multi-user.target

文件位置

  • 服务文件:/etc/systemd/system/natpierce.service

2. Sunshine 服务(用户级服务)

特点

  • GUI 程序,需要图形环境
  • 当前用户权限运行
  • 登录后自启动
  • 关闭/崩溃自动重启

服务文件

ini 复制代码
[Unit]
Description=Sunshine Game Streaming
After=graphical-session.target

[Service]
ExecStart=/opt/sunshine/sunshine.AppImage
Restart=always
RestartSec=5

[Install]
WantedBy=graphical-session.target

文件位置

  • 服务文件:~/.config/systemd/user/sunshine.service

参数说明

  • Restart=always - 任何退出(包括手动关闭)都会自动重启
  • RestartSec=5 - 重启间隔 5 秒

常用命令

NatPierce (系统服务)

bash 复制代码
# 启动/停止/重启
sudo systemctl start natpierce.service
sudo systemctl stop natpierce.service
sudo systemctl restart natpierce.service

# 查看状态
sudo systemctl status natpierce.service

# 查看日志
sudo journalctl -u natpierce.service -f

Sunshine (用户服务)

bash 复制代码
# 启动/停止/重启
systemctl --user start sunshine.service
systemctl --user stop sunshine.service
systemctl --user restart sunshine.service

# 查看状态
systemctl --user status sunshine.service

# 查看日志
journalctl --user -u sunshine.service -f

注意事项

  1. GUI 程序必须用用户服务:不能用系统服务运行 GUI,否则会因缺少显示环境变量而失败
  2. 用户服务需要在登录后运行:图形会话启动后才会运行
相关推荐
小此方1 小时前
Linux网络(一):揭秘从网络发展哲学到 TCP/IP 协议栈分层设计的设计哲学
linux·网络·tcp/ip
星野爱8951 小时前
远程控制哪家安全性更高?ToDesk、UU远程、向日葵隐私屏深度测评!
linux·运维·网络
ALINX技术博客1 小时前
【黑金云课堂】FPGA技术教程Linux开发:系统定制
linux·运维·fpga开发
ShineWinsu1 小时前
对于Linux:传输层协议UDP原理的解析
linux·c++·面试·udp·协议·传输层·计算机系统
2601_965798472 小时前
How to Build a Custom Artisan Store on WordPress: Crafti Theme Review
linux·服务器·数据库
mounter6252 小时前
深度解析 Linux 内核中的 iomap 子系统:历史、演进、核心机制与未来
linux·文件系统·linux kernel·kernel·iomap
养海绵宝宝的小蜗4 小时前
LVS(Linux Virtual Server)项目知识点总结
linux·运维·lvs
阿黎02145 小时前
Linux驱动
linux
tjjingpan5 小时前
HCIP-Datacom Core Technology V1.0_20 IPv6概述
linux·服务器·网络
云泽8085 小时前
Linux基础开发工具(三):Vim高级配置、Swap恢复机制与Sudo权限白名单详解
linux·运维·vim