runitを使う
Why use this feature?
- 通常ユーザでデーモン機能を使用したい。
- damemontools 相当の機能を個人ユーザで使いたい
apt を使用して runit-systemd 関連のパッケージをインストール
apt update
apt -y install doas
apt -y install runit
apt -y install systemd-sysv
apt -y install runit-systemd
systemctl enable runit
mkdir -p /etc/sv/runsvdir-${NEWUSER}
cat <<END >/etc/sv/runsvdir-${NEWUSER}/run
#!/bin/sh
exec 2>&1
exec chpst -u${NEWUSER} runsvdir /home/${NEWUSER}/service
END
chmod +x /etc/sv/runsvdir-${NEWUSER}/run
mkdir /home/${NEWUSER}/service
chown ${NEWUSER}:${NEWUSER} /home/${NEWUSER}/service
mkdir /etc/sv/runsvdir-${NEWUSER}/log
cat <<END >/etc/sv/runsvdir-${NEWUSER}/log/run
#!/bin/sh
LOG=/var/log/runsvdir/${NEWUSER}
test -d "$LOG" || mkdir -p -m755 "$LOG" && chown ${NEWUSER}:whell "$LOG"
exec chpst -u${NEWUSER} svlogd -t "$LOG"
END
chmod +x /etc/sv/runsvdir-${NEWUSER}/log/run
mkdir /var/lib/supervise
mkdir /var/lib/supervise/runsvdir-${NEWUSER}
mkdir /var/lib/supervise/runsvdir-${NEWUSER}.log
ln -s /var/lib/supervise/runsvdir-${NEWUSER} /etc/sv/runsvdir-${NEWUSER}/supervise
ln -s /var/lib/supervise/runsvdir-${NEWUSER}.log /etc/sv/runsvdir-${NEWUSER}/log/supervise
ln -s /etc/sv/runsvdir-${NEWUSER} /etc/service