mkunit status

Check the status of a unit.

mkunit status <name> [flags]

Description

The status command shows the current status of a unit. This is a convenient wrapper around systemctl status that automatically handles user vs system units.

Arguments

Argument Description
<name> Name of the unit (with or without extension)

Flags

Flag Description Default
--system Check a system unit false
--quiet, -q Only return exit code, no output false
--json Output status as JSON false

Exit Codes

Code Meaning
0Unit is active (running)
1Unit is inactive or dead
2Unit is activating or deactivating
3Unit has failed
4Unit not found

Examples

Check service status

mkunit status myapp

Example output:

● myapp.service - myapp service
     Loaded: loaded (/home/user/.config/systemd/user/myapp.service; enabled)
     Active: active (running) since Mon 2024-01-15 10:30:00 UTC; 2h ago
   Main PID: 12345 (server)
      Tasks: 4 (limit: 4915)
     Memory: 24.5M
        CPU: 1.234s
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/myapp.service
             └─12345 /home/user/myapp/server

Jan 15 10:30:00 hostname server[12345]: Starting server on :8080

Check system service

mkunit status nginx --system

Check timer status

mkunit status backup.timer

For timers, this shows when the timer last ran and when it will run next.

Quiet mode for scripts

if mkunit status myapp -q; then
  echo "Service is running"
else
  echo "Service is not running"
fi

JSON output

mkunit status myapp --json
{
  "name": "myapp.service",
  "load_state": "loaded",
  "active_state": "active",
  "sub_state": "running",
  "pid": 12345,
  "memory": "24.5M",
  "uptime": "2h 15m",
  "enabled": true
}

See Also