Hello,
I am trying to run caddy on a netbsd server, to host a static website (I am interested in the auto_tls feature; yes I could have installed nginx and certbot, which already have an init script, but... why not learning new things).
However pkgin install caddy
only installs the caddy binary in /usr/pkg/bin/caddy.
Thus, I am thinking fine, let's learn more about netbsd rc services and write one.
So I am trying to learn from other existing ones such as apache, nginx, httpd (bozo) and lighthttpd, but I am still a bit lost, notably with the rc.subr things.
I created a system user for caddy (and group) and I am willing to run it as the user caddy in a chroot.
I managed to create the chroot manually and run my service with
chroot -u caddy -g caddy /var/caddy /usr/bin/caddy start --config /etc/caddy/Caddyfile --pidfile /var/run/caddy.pid
And my reload command works in a similar fashion.
As caddy is a user, I managed to do the port forwarding properly with npf to listen publicly on standard ports.
I think having the pid file in the chroot dir is not a problem as long as the service is aware of it.
However, my posix shell scripting skills are a bit rusty and I've never done in the context of the rc init with all the predefined things, which makes it a bit confusing to me.
If someone is happy to guide me, thanks in advance π .
(I already have most of the mans for rc.conf and rc.subdr open)
Here is what I currently have (not working because not finished)
#!/bin/sh
# PROVIDE: caddy
# REQUIRE: DAEMON
# KEYWORD: shutdown
$_rc_subr_loaded . /etc/rc.subr
name="caddy"
rcvar=$name
command="/usr/pkg/bin/${name}"
caddy_user="caddy"
caddy_group="caddy"
caddy_chroot="/var/caddy"
pidfile="/var/run/caddy.pid"
required_files="/etc/caddy/Caddyfile"
load_rc_config $name
#caddy_user=${caddy_user:+-U \'$caddy_user\'}
#command_args="$httpd_wwwuser_arg -b '$httpd_wwwdir'"
#required_dirs="$httpd_wwwdir"
run_rc_command "$1"
Which is super basic.
I could just write an ugly random script not taking care of rc.subdr and pre-definitions but I'd like to learn to do the thing the proper way.
Most of my knowledge comes from the Linux world (mostly systemd but I wrote an alpine linux openrc init script once) and I am trying to translate what I can. I
I'd like to learn the thinking behind the design of such init scripts.