# dinit-doctor

A small health-check tool for Dinit-managed user services. Supports summary-only and stopped-only modes.

## Installation
### Via Cargo
```bash
cargo install dinit-doctor
```

### From source
Prerequisites:
- A Dinit-based Linux distribution (e.g Artix, Chimera Linux)
- Rust/Cargo installed via rustup or a package manager

Clone the repository and run the install command:
```bash
git clone https://codeberg.org/Enmark/dinit-doctor && cd dinit-doctor && cargo install --path .
```

## Usage
```bash
dinit-doctor (summary-only|stopped-only)
```

Example output:
```bash
>> dinit-doctor
boot is started.
dbus is started.
pipewire is started.
pipewire-pulse is started.
pwms is started.
mpd is started.
mpdris2 is started.
awww is started.
swaync is started.
wlsunset is started.
waybar is started.
foot-server is started.
test: terminated; exited - status 127
>> dinit-doctor summary-only
dinit-doctor: 1 stopped services
>> dinit-doctor stopped-only
test: terminated; exited - status 127
```

## Integrating into shell scripts
dinit-doctor is best paired with Rofi, but you can integrate it into any other shell script. An example of a Rofi-based Dinit service manager with dinit-doctor integration:
```bash
#!/usr/bin/env bash

while true; do
  service=$(
    (
      printf '%s\n' "$(dinit-doctor summary-only)" # puts dinit-doctor's summary to the top of menu
      dinitctl list | awk '{print $3}'
    ) | rofi -dmenu -i -p "User service"
  )
  [ -z "$service" ] && exit 0

  # just in case dinit-doctor gets mistook as a service
  if [[ "$service" == "dinit-doctor: "* ]]; then
    service=$(
      (
        printf '%s\n' "Back to services..."
        dinit-doctor stopped-only
      ) | rofi -dmenu -p "Stopped services"
    )
    if [[ "$service" = "Back to services..." ]]; then
      continue
    fi
    service=$(echo $service | awk '{print $1}')
  fi

  action=$(echo -e "start\nstop\nrestart\nstatus" | rofi -dmenu -i -p "$service")
  [ -z "$action" ] && exit 0

  case "$action" in
    status)
      sel=$(
        (
          printf '%s\n' "Back to services..."
          dinitctl status "$service"
        ) | rofi -dmenu -p "$service status" -theme-str 'listview {lines: 5;}'
      )
      if [[ "$sel" = "Back to services..." ]]; then
        continue
      fi
      ;;
    *)
      notify-send "Executing: dinitctl $action $service" -a "EMS Dinit Service Control"
      dinitctl "$action" "$service"
      ;;
  esac
done
```
