Community Tutorials Linux Basics كيفية إدارة خدمات systemd على Linux
كيفية إدارة خدمات systemd على Linux
LINUX BASICS

كيفية إدارة خدمات systemd على Linux

SKYLINE Knowledge Base
Photo by Sigmund on Unsplash

دليل عملي خطوة بخطوة لـ كيفية إدارة خدمات systemd على Linux. أوامر مختبرة في الإنتاج، متطلبات مسبقة، تحقق نهائي وروابط لمواضيع ذات صلة.

systemd هو نظام init على كل توزيعة Linux رئيسية منذ 2015. معرفة الأوامر الثمانية أدناه يغطي 99% من العمليات اليومية.

المتطلبات المسبقة

  • صندوق Linux مع systemd كـ PID 1.
  • sudo.

الخطوة 1: تأكد من systemd PID 1

ps -p 1 -o comm=
systemctl --version | head -1

الخطوة 2: status، start، stop، restart، reload

sudo systemctl status nginx
sudo systemctl start  nginx
sudo systemctl stop   nginx
sudo systemctl restart nginx
sudo systemctl reload  nginx
sudo systemctl reload-or-restart nginx

الخطوة 3: enable، disable، mask

sudo systemctl enable  nginx
sudo systemctl enable --now nginx
sudo systemctl disable nginx
sudo systemctl mask    nginx
sudo systemctl unmask  nginx

الخطوة 4: السرد والفحص

systemctl list-units --type=service
systemctl list-units --type=service --state=failed
systemctl is-active nginx
systemctl cat nginx
systemctl show nginx | head -30

الخطوة 5: السجلات — journalctl

sudo journalctl -u nginx -f
sudo journalctl -u nginx --since '1 hour ago'
sudo journalctl -p err -b
sudo journalctl _PID=12345
sudo journalctl -k

الخطوة 6: اكتب unit خاص

/etc/systemd/system/skyline-api.service:

[Unit]
Description=SKYLINE API service
After=network-online.target postgresql.service
Wants=network-online.target

[Service]
Type=simple
User=skyline
Group=skyline
WorkingDirectory=/opt/skyline-api
EnvironmentFile=/etc/skyline-api.env
ExecStart=/opt/skyline-api/bin/api
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5

NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now skyline-api
sudo journalctl -u skyline-api -f

الخطوة 7: المؤقتات (cron الخاص بـ systemd)

backup.service:

[Service]
Type=oneshot
ExecStart=/usr/local/bin/skyline-backup.sh

backup.timer:

[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true
RandomizedDelaySec=5min

[Install]
WantedBy=timers.target
sudo systemctl enable --now backup.timer
systemctl list-timers

الخطوة 8: drop-in overrides

sudo systemctl edit nginx
[Service]
LimitNOFILE=65536
Restart=on-failure

التحقق

systemctl --failed
systemctl list-units --type=service --state=running | head -20
journalctl -p err -b | tail -20
systemctl list-timers | head -10

الخاتمة

status, start, stop, restart, reload, enable, disable, list-units + journalctl -u UNIT -f — ثمانية أوامر وستكون قادرًا على التشغيل.

الخطوات التالية

SKYLINE Engineering

@skyline

The engineering team at SKYLINE Industrial Solutions. We publish field-tested guides drawn from real KSA and GCC deployments.

See author profile
SKYLINE engineering services

Need this implemented for you?

Reading is free — building it right takes a team. SKYLINE engineers ship Linux Basics for Aramco vendors, banks, hospitals and government agencies across Saudi Arabia. Talk to us before you start.

Aramco Approved Contractor ISO 9001 · ISO 27001 SAMA CSF aligned NCA ECC ready 247+ KSA clients

Comments

0 total · 0 threads
Be the first to leave a comment.