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 — ثمانية أوامر وستكون قادرًا على التشغيل.
Comments
0 total · 0 threads