#!/data/data/com.termux/files/usr/bin/bash
#
# runit service: sshd
# Keeps SSH daemon running so the server can manage the phone remotely.
# Install: ln -s ~/sms-server/termux-sms/services/sshd $PREFIX/var/service/
#

# Generate host keys if missing
if [ ! -f "$PREFIX/etc/ssh/ssh_host_rsa_key" ]; then
  ssh-keygen -A
fi

# Kill any standalone sshd first so we can bind the port
# (only kills the listener, not active sessions)
pkill -x sshd 2>/dev/null
sleep 1

# sshd -D = foreground (required for runit), -e = log to stderr
exec sshd -D -e 2>&1
