systemctl — Control systemd services — start, stop, enable, inspect across all 5 shells
Equivalents in every shell
sudo systemctl restart nginxThe canonical systemd service controller. Subcommands: `start`, `stop`, `restart`, `reload` (SIGHUP), `status` (current state + recent log lines), `enable` (start at boot), `disable`, `mask` (prevent ever starting). `--user` operates on the per-user systemd instance (`~/.config/systemd/user/*.service`) instead of system-wide. Returns exit 0 only when the operation succeeded — useful in deploy scripts.
sudo systemctl restart nginxSame external. macOS does NOT ship systemd — it uses `launchctl` instead: `sudo launchctl load /Library/LaunchDaemons/com.foo.bar.plist` (system) or `launchctl load ~/Library/LaunchAgents/com.foo.plist` (user). The plist XML format is the macOS analog of systemd unit files.
sudo systemctl restart nginxSame external. Fish auto-completion for `systemctl` is excellent — pressing TAB after `systemctl re` suggests `reload`, `restart`, `reload-or-restart`. The completion script ships with fish since 3.0 and reads `/lib/systemd/system/*.service` to populate service names.
Restart-Service -Name nginxConceptual map for Windows services (NOT systemd — Windows uses the Service Control Manager). Cmdlets: `Start-Service`, `Stop-Service`, `Restart-Service`, `Get-Service` (status), `Set-Service -StartupType Automatic` (enable at boot), `Set-Service -StartupType Disabled` (disable). New services: `New-Service -Name foo -BinaryPathName "C:\path\to\foo.exe"`. The two systems are NOT interoperable — Windows pwsh cannot manage systemd units directly.
sc start nginx`sc.exe` (Service Control) is the cmd-side equivalent. Subcommands: `sc start`, `sc stop`, `sc query` (status), `sc qc` (full config), `sc config nginx start=auto` (enable at boot), `sc config nginx start=disabled`. Older: `net start <service>` / `net stop <service>` are shorter but lack the config/state inspection that `sc` offers. cmd cannot manage systemd — only Windows services.
Worked examples
Start a service and enable it at boot
sudo systemctl enable --now nginxSet-Service -Name nginx -StartupType Automatic; Start-Service -Name nginxsc config nginx start= auto && sc start nginxCheck whether a service is running
systemctl is-active nginx(Get-Service -Name nginx).Statussc query nginx | findstr STATEReload service config without dropping connections
sudo systemctl reload nginx(Get-Service -Name nginx).Refresh()sc control nginx 130Gotchas
- systemd is LINUX-ONLY. macOS uses `launchctl` + `.plist` files; FreeBSD uses `rc.d` + `/etc/rc.conf`; Windows uses the Service Control Manager + `sc.exe` / Get-Service. There is no "systemctl for macOS" — `systemctl` on macOS is "command not found".
- `systemctl restart` is NOT zero-downtime — it stops the service, then starts it. For graceful reload (no dropped connections, no socket re-bind), use `systemctl reload` if the unit defines `ExecReload=` (most well-written daemons do). For services without reload support, the alternative is socket activation via systemd: the kernel-held socket survives the daemon restart.
- Enabling a service via `systemctl enable nginx` does NOT start it — only configures auto-start at next boot. Use `systemctl enable --now nginx` to enable AND start in one step (the `--now` flag also works for `disable --now`, which both disables and stops).
- Windows services cannot be reloaded as a first-class concept the way systemd reloads. `(Get-Service nginx).Refresh()` only refreshes the cmdlet's cache, NOT the service. True graceful-reload requires the service to listen for a custom control code (130–255 are user-defined) and `sc control nginx 130` sends it. Most stock Windows services do NOT support reload — they have to restart.
- User-mode systemd (`systemctl --user`) requires that the user has an active login session (`loginctl enable-linger <user>` if you want services to stay running after logout). Without lingering, your `--user` unit dies the moment you SSH out. The same applies to long-running pwsh / shell processes started from a remote session.