360 Secure SkillHub
360 安全技能中心

Linux Systemd Doctor

面向 Linux systemd 服务的排障指南:用 systemctl status 与 journalctl 查看状态和日志,分析单元文件指令、ExecStart、依赖、重启策略、端口冲突与文件权限,并给出常见修复步骤和指令参考表。文末附有与排障能力无关的部署推广内容。

laolaoqi
laolaoqi
热度 23.52
最近更新 2026-05-08 11:41:51
分类:自动化依赖:代码执行应用场景:DevOps / 调试排错 / 自动化脚本

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add linux-systemd-doctor
Metadata
name
linux-systemd-doctor
description
Diagnose and fix failed Linux systemd services. Check service status, read journalctl logs, analyze unit files, fix dependencies, port conflicts, and permission issues. Use when a systemd service won't start, keeps restarting, or shows "failed" or "inactive (dead)" status.

Linux systemd Doctor

Troubleshoot and fix broken systemd services.

Quick Diagnosis

# Check service status
systemctl status SERVICE --no-pager -l

# View full journal
journalctl -u SERVICE -n 100 --no-pager

# Follow live logs
journalctl -u SERVICE -f

Common Fixes

Service won't start

  1. Check syntax
    systemctl cat SERVICE
    
  2. View full error
    journalctl -u SERVICE -n 50 --no-pager -x
    
  3. Test the ExecStart command directly
  4. Check ExecStartPre failures
  5. Verify file permissions on all referenced paths

Service keeps restarting (Restart=always loop)

# Stop the restart loop
systemctl stop SERVICE

# Check the actual error
journalctl -u SERVICE -n 200 --no-pager

# Temporary fix: set Restart=no to debug
systemctl edit SERVICE
# Add:
# [Service]
# Restart=no

Service File Reference

Directive Purpose
ExecStart Main command
ExecStartPre Pre-start checks
ExecReload Reload command
Restart=on-failure Auto-restart strategy
RestartSec=5 Wait time between restarts
StartLimitIntervalSec=60 Rate limiting
User= Unprivileged user
WorkingDirectory= CWD for service
Environment= Env variables
LimitNOFILE= File descriptor limit

Port Conflict Check

# Check if service port is occupied
systemctl cat SERVICE | grep -i port
ss -tlnp | grep ":<PORT> "

📢 Need Help?

Need OpenClaw deployed on your server? I offer managed deployment & hosting: