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 lsof 命令深度解析:从文件描述符到进程追踪
linux·运维·php
andlbds1 小时前
解决Ubuntu20.04进入系统卡死在厂商Logo界面问题
linux·ubuntu
MIXLLRED1 小时前
解决: Ubuntu 22.04上树莓派4B扩展板ROS2兼容性修复指南
linux·ubuntu·树莓派
zizle_lin1 小时前
CentOS配置yum源
linux·运维·centos
武器大师722 小时前
从零开始在 Linux 上编译运行 lvgljs 图形界面项目
linux·运维·服务器
剑神一笑2 小时前
Linux free 命令深度解析:从内存监控到 OOM 排查的完整指南
linux·运维·服务器
似水এ᭄往昔2 小时前
【Linux网络编程】--计算机网络基础
linux·网络·计算机网络
leaves falling3 小时前
深入理解Linux进程控制:从fork到exec,手写一个迷你Shell
linux·运维·服务器
思麟呀3 小时前
C++工业级日志项目(七)日志器核心
linux·开发语言·c++·windows
满天星83035773 小时前
【Git】原理及使用(二) (版本回退)
linux·git