Re: Sample rc.d script for Elixir apps

From: Dave Cottlehuber <dch_at_skunkwerks.at>
Date: Sun, 12 Sep 2021 17:46:22 UTC
On Sun, 12 Sep 2021, at 16:26, Mike Jakubik wrote:
> Hello,
>
> I am looking for a simple rc.d script that i could use to start our 
> Elixir apps on boot up, something that root will run as defined user 
> and basically just run elixir --erl "-detached" -S mix phx.server and 
> track PID.

Hi Mike

Use releases, possibly with pid_file https://hex.pm/packages/pid_file

This is probably more than you need, but you can likely trim it down
or adapt as you need.

https://git.sr.ht/~dch/elixir-freebsd-rc-skeleton/tree

Basically this runs in our CI, builds an elixir release, creates a
standard FreeBSD package  directly, without needing a Makefile to
maintain, and drops the resulting tarball into our package repos
and it can simply be `pkg install...` or upgraded.

Use ansible or whatever to leave /usr/local/etc/${APP} and any
/etc/rc.conf.d/${APP} settings.

I use this in numerous projects, where, for historical reasons), we
don't build in a classic ports tree, but use pkg-create(8) to build
a compatible package. We can then distribute this elixir app like any
other project.

If I re-did it today, it would probably be a mix task for simplicity.

TLDR:

- use git tags for sensible version numbers
- rc.d is your future /usr/local/etc/rc.d/${APP}
- build.sh cleans the dir and makes a .txz file (this might need to
be amended to .pkg depending on how up to date you are)
- mix.exs has a few additions/helpers you may want
- app.sh ends up in /usr/local/bin/example.sh so you can run it like

su -m www /usr/local/bin/example.sh

or via the usual `service example start` as you prefer. 

The release scripts used to be horrible for elixir, so I unpacked
them and simplified all the unnecessary bits. This was 6 years ago,
and the releases are better now than they were, but again this is

It's BSD2 licenced, I'd appreciate a shout-out in your repo if you
use it, even if its a private repo that's just fair play :-)

I don't connect via a local iex for debugging, I just remsh in:

$ iex --name iex@(hostname -s).example.net \
                          --remsh app@example.net \
                          --cookie ... \
                          --erl '-proto_dist inet6_tcp'

Using inet6 because thats how we roll our jails.

Thoughts and ideas for improvements welcomed.

A+
Dave