Running Atuin as daemon on TrueNas and ZFS

I was having major delays and even tried moving my system dataset but still found it may ssh’ing into the shell horrid. I have hacked together a quick startup script to load the daemon when I ssh into the box. It check if the daemon is running first. It seems to be working so far. I just include the Atuin stuff in a script that gets sourced from the .zshrc.

setopt interactive_comments
source  $HOME/.atuin/bin/env

atsearch() {
    atuin search "$1"  --format "{host}\t{command}"
}

is_atuin_daemon_running() {
   if pgrep -f "atuin daemon" > /dev/null; then
      return 0  # true
   else
      return 1  # false
   fi
}
# Not  used but included.
stop_all_atuin_daemons() {
  # Find all process IDs of "atuin daemon"
  local pids
  pids=$(pgrep -f "atuin daemon")

  if [[ -n "$pids" ]]; then
    # Loop through each PID and kill it
    for pid in $pids; do
      kill "$pid" && echo "Atuin daemon with PID $pid stopped."
    done
  else
    echo "No running instances of atuin daemon found."
  fi
}
# if running on truenas, then launch the daemon because of the sqllite bug on zfs
if uname -a | grep -q "truenas"; then

  SOCKET="$HOME/.local/share/atuin/atuin.sock"
  # Check if the socket file exists and is active
  if [ -S "$SOCKET" ] && nc -zU "$SOCKET" 2>/dev/null; then
      echo "Atuin daemon is runing."
  else
      echo "Starting atuin daemon"
      if [ -S $SOCKET ]; then
          rm $SOCKET
      fi
      nohup atuin daemon >/dev/null 2>&1 &
  fi
fi


eval "$(atuin init zsh --disable-up-arrow)"

#lsof -c "atuin"  | grep sock
alias h="atsearch"```
1 Like