Process interface / requirements
Process supervision
Tip
You can find the corresponding code in func gokrazy.supervise.
gokrazy’s init process (pid 1) supervises all the binaries the user specified via gokr-packer flags.
More specifically, gokrazy:
- Starts your binary using Go’s
os/exec.CommandAPI.- The
stdoutandstderrfile descriptors are hooked up to a ring buffer and can be viewed via gokrazy’s web interface. - Extra command-line flags or environment variables can be specified using per-package configuration.
- The
- When your binary’s process exits, gokrazy restarts it!
- If the process exits with status code
0(or125), gokrazy will stop supervision. Exiting immediately with status code0when theGOKRAZY_FIRST_START=1environment variable is set means “don’t start the program on boot”
- If the process exits with status code
Environment variables
gokrazy sets the HOME environment variable to HOME=/perm/home/<cmd>, where
<cmd> is the name of your binary. For example, tailscale.com/cmd/tailscaled
is started with HOME=/perm/home/tailscaled.
When your binary is first started, gokrazy sets the GOKRAZY_FIRST_START=1
environment variable.
Privilege dropping / security
An easy way to implement privilege dropping in Go is to re-execute the process
with syscall.SysProcAttr fields
set. For example, this is how you would drop privileges to user nobody
(uid/gid 65534):
Examples:
github.com/gokrazy/gokrazy/cmd/ntpis a rather involved example which retains the CAP_SYS_TIME capability in the child processgithub.com/gokrazy/rsyncuses Linux mount namespaces and constructs a file system with read-only bind mounts of the configured rsync modules