Creating a service on OpenBSD
Recently I deployed ssh-chat and Betula on my server, but I didn’t install them as a service. I just have a crontab with the following entry:
@reboot tmux new-session -d '/path/to/service'
It’s been working for me, but it can be annoying sometimes when I want to quickly stop and start the program. To make it easier for me, I made the following in /etc/rc.d/.
Configuration for ssh-chat
Copy this file to
/etc/rc.dand make sure it’s executable.#!/bin/ksh daemon="/usr/local/bin/ssh-chat" daemon_logger="daemon.info" daemon_flags="--verbose --bind ':PORT' --identity PRIVATE_KEY --admin=ADMIN_FILE --motd=MOTD_FILE" daemon_user="USER" . /etc/rc.d/rc.subr rc_bg=YES rc_reload=NO rc_cmd $1# nano /etc/rc.d/ssh_chat # chmod +x /etc/rc.d/ssh_chatPoint the variable daemon to the executable, e.g.,
/usr/local/bin/ssh-chatYou can move or link the executable to a more standard place as well.
# ln -s ~/ssh-chat/ssh-chat /usr/local/bin/ssh-chatModify the values in
daemon_flagsanddaemon_userbased on your liking.Alternatively, you can delete that line and set the flags using rcctl instead:
# rcctl set ssh_chat flags --verbose --bind [...] --identity [...]Create the user that will run this service (see
man useraddorman adduser)Set the proper permissions for files and directories as well that you want the daemon to access.
# useradd -m chat # mkdir /var/chat # chown chat:chat /var/chatEnable and start the service
# rcctl enable ssh_chat # rcctl start ssh_chatCheck the logs in
/var/log/daemon# tail -f /var/log/daemon
Configuration for Betula
Copy this file to
/etc/rc.dand make sure it’s executable.#!/bin/ksh daemon="/usr/local/bin/betula" daemon_flags="/var/betula/links.betula" daemon_user="betula" . /etc/rc.d/rc.subr rc_bg=YES rc_reload=NO rc_cmd $1# nano /etc/rc.d/betula # chmod +x /etc/rc.d/betulaPoint the variable daemon to the executable, e.g.,
/usr/local/bin/betula# ln -s $GOPATH/bin/betula /usr/local/bin/betulaModify the values in
daemon_flagsanddaemon_userbased on your liking.Alternatively, you can delete that line and set the flags using rcctl instead:
# rcctl set betula flags /var/betula/links.betulaCreate the user that will run this service (see
man useraddorman adduser)# useradd -m betula # mkdir /var/betula # chown betula:betula /var/betulaEnable and start the service
# rcctl enable betula # rcctl start betulaCheck the logs in
/var/log/daemon# tail -f /var/log/daemon