Crates.io | rc_conf |
lib.rs | rc_conf |
version | 0.8.0 |
source | src |
created_at | 2024-08-19 02:43:42.096585 |
updated_at | 2024-11-12 02:28:52.194029 |
description | rc_conf provides rc.conf and rc.d-like data structures for consumption. |
homepage | |
repository | https://github.com/rescrv/blue |
max_upload_size | |
id | 1343337 |
size | 68,092 |
rc_conf
provides an rc-like configuration syntax inspired by FreeBSD's init system. The core principle of rc_conf
is that the configuration should be separated from the runtime. rc_conf
achieves exactly that by putting the
configuration into an rc.conf
file (much like /etc/rc.conf on BSD) and then using the configuration to run programs
via rc.d
service stubs.
For example: A memcached service deploy starts with two pieces. The first is the rc.d
service stub. It looks like
this:
#!/usr/bin/env rcscript
DESCRIBE=A single memcached instance.
COMMAND=memcached -v
The format is intended to be self-describing. The only two gotchas two beware are that this file should be executable and the command should run in the foreground and not daemonize.
If we try to run this service as-is it won't run. By default, every service is disabled. To enable memcached, create
an rc.conf
with the following:
memcached_ENABLED="YES"
This will cause rustrc
(the supervisor written on rc_conf
) to keep the memcached
daemon running with some provisions for backing off during failure.
This isn't a very useful example as our end state, provides a starting point. We may want to configure memcached and
going back to the rc.d
file and redeploying it every time won't be fun.
Enter the first principle of rc_conf
: A separation between configuration and where the value gets used. rc.d
scripts provide the "hooks" for the configuration by taking command line applications and binding them to rc.conf
files. For example, if we wanted to configure the port and hostname for memcached, we modify the rc.d
script to look
like:
COMMAND=memcached -v ${HOST:+-i ${HOST}} ${PORT:+-p ${PORT}}
This will pull the values of HOST and PORT from the rc_conf
where running memcached. But globals get messy fast.
Whose HOST; whose PORT? This is where rc_conf
comes in. To set the hostname, add this to rc.conf
:
memcached_HOST="memcached.example.org"
memcached_PORT="11211"
If either of these were absent, the "memcache_"-prefix-free versions would be substituted in their place. So to have a
default host for all services that can be overridden, specify HOST=default.example.org
.
To spin up a second memcached on 22122, we can add this to our rc.conf
:
memcached_two_INHERIT="YES"
memcached_two_ALIASES="memcached"
memcached_two_PORT="22122"
An alias such as this one uses one rc.d
stub to launch two memcached instances.
Maintenance track. The library is considered stable and will be put into maintenance mode if unchanged for one year.
This crate provides the RcConf
type, rcscript
interpreter, and other rc tools.
rc_conf
file.
Usage: rcdebug rc.conf
rc_conf
as the parser sees it.
Usage: rcexamine rc.conf:rc.conf.local
rc_conf
would prescribe.
Usage: rcinovke --rc-conf-path rc.conf:rc.conf.local --rc-d-path rc.d:/srv/rc.d memcached
rclist rc.d /srv/rc.d
rcvar --rc-conf-path rc.conf:rc.conf.local --rc-d-path rc.d:/srv/rc.d memcached
'{'
and '}'
characters outside the variable declarations won't parse right now.The latest documentation is always available at docs.rs.