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. 用户服务需要在登录后运行:图形会话启动后才会运行
相关推荐
ONLYOFFICE7 分钟前
ONLYOFFICE成为Linux操作系统 – Winux的预装办公套件
linux·运维·服务器
mounter62512 分钟前
从内核安全到可编程基础设施:Meta 的 eBPF 实践与形式化验证探索
linux·ebpf·linux kernel·kernel
新时代牛马16 分钟前
嵌入式 Linux WiFi 框架完整篇:从cfg80211、mac80211 到wpa_supplicant
linux·运维·服务器
吴声子夜歌24 分钟前
Linux命令——打印
linux·运维·服务器
企鹅的蚂蚁27 分钟前
Linux 开发板串口调试:picocom 从识别到退出的完整用法
linux·运维·服务器
bksczm41 分钟前
从 “什么是 MySQL“ 到库与表的完整操作(MySQL基础篇)
linux·数据库·mysql
企鹅的蚂蚁1 小时前
LubanCat RK3588 实时内核移植第一步:先确认硬件与系统版本
linux·lubancat·嵌入式linux·freempt_rt
是个西兰花1 小时前
网络基础1
linux·网络·c++·智能路由器
2601_962299881 小时前
Python编写Linux命令指南
linux·python·开发·命令·指南
此冬歌咏1 小时前
自动化服务器运维监控系统(python+shell)
linux·运维·服务器·开发语言·python·自动化