متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 7System · Linux

How to start, stop, restart and enable a service

On RHEL, Ubuntu and almost every modern Linux, services are managed by systemd with one command: systemctl. This how-to covers the daily actions — status, start, stop, restart, reload, start at boot — plus the things that confuse people: the difference between start and enable, restart and reload, what masked means, and how to change a service safely.

  • 5 الدروس
  • 6 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

7.1

The quick answer

systemctl status nginx
systemctl restart nginx
systemctl reload nginx
systemctl enable --now nginx
systemctl disable --now nginx
systemctl is-active nginx; systemctl is-enabled nginx
CommandEffect
start / stopNow — not after a reboot.
enable / disableAt boot — not now.
enable --now / disable --nowBoth at once.
restartStop and start (short downtime; reads all changes).
reloadThe service rereads its config without stopping (if it supports it — nginx, sshd, haproxy, postgresql).

الأوامر في هذا الدرس

7.2

Step by step

  1. Find the unit and read its status:
systemctl list-units --type=service --state=running
systemctl list-unit-files --type=service | grep -i ssh
systemctl status sshd
● sshd.service - OpenSSH server daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
     Active: active (running) since Mon 2026-11-17 08:01:12 +03; 3h ago

Loaded … enabled = starts at boot. Active: active (running) = runs now.

  1. After a config change: test the config if the service has a test command, then reload (or restart):
nginx -t && systemctl reload nginx
sshd -t && systemctl reload sshd
  1. See all failed services after a boot or an incident:
systemctl --failed
systemctl reset-failed
  1. Change a service the safe way — never edit files in /usr/lib/systemd/system (updates overwrite them). Use an override:
systemctl edit nginx
/etc/systemd/system/nginx.service.d/override.conf
[Service]
Restart=on-failure
RestartSec=5
LimitNOFILE=65536

systemctl edit reloads systemd for you. If you change unit files by hand: systemctl daemon-reload.

  1. Stop a service from ever starting (even as a dependency):
systemctl mask --now cups
systemctl unmask cups
  1. Your own app as a service — a minimal unit:
/etc/systemd/system/myapp.service
[Unit]
Description=My app
After=network-online.target
 
[Service]
User=myapp
ExecStart=/opt/myapp/bin/myapp --port 8080
Restart=on-failure
 
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now myapp

7.3

Check that it worked

systemctl is-active nginx
active
systemctl is-enabled nginx
enabled
systemctl show nginx -p Restart,ActiveEnterTimestamp

The real test for "enabled": reboot a test machine and check again.

الأوامر في هذا الدرس

7.4

Common problems

ProblemCauseFix
Unit nginx.service not foundNot installed, or another name.systemctl list-unit-files | grep -i NAME; install the package.
Job for X failed because the control process exited with error codeThe service could not start (config, port, rights).journalctl -xeu X; test the config; see "How to read the logs of a service".
Unit X is maskedSomeone masked it on purpose.systemctl unmask X (if it should run).
Changes in the unit file are ignoredsystemd did not reload.systemctl daemon-reload, then restart.
Runs now but not after rebootIt was started, not enabled.systemctl enable X.
reload does nothing / not supportedThe unit has no reload action.Use restart (plan the short downtime).

7.5

Go further

1What is the difference between start and enable?

start runs the service now; enable makes it start at boot. enable --now does both.

2How do you change a vendor service file without losing the change at the next update?

With an override: systemctl edit NAME (file in /etc/systemd/system/NAME.service.d/).

كل الأوامر في هذا الفصل