--- sysutils/consul/Makefile (revision 513055) +++ sysutils/consul/Makefile (working copy) @@ -26,12 +26,30 @@ PLIST_FILES= bin/consul -USERS= consul -GROUPS= consul +ETCDIR= ${PREFIX}/etc/${PORTNAME}.d +CONSUL_USER?= consul +CONSUL_GROUP?= consul +CONSUL_DATADIR?= /var/db/${PORTNAME} +USERS= ${CONSUL_USER} +GROUPS= ${CONSUL_GROUP} + +SUB_LIST= ETCDIR=${ETCDIR} \ + CONSUL_USER=${CONSUL_USER} \ + CONSUL_GROUP=${CONSUL_GROUP} \ + CONSUL_DATADIR=${CONSUL_DATADIR} + post-extract: ${MKDIR} ${WRKSRC}/vendor/github.com/${GH_ACCOUNT}/${PORTNAME} ${LN} -s ${WRKSRC}/api ${WRKSRC}/vendor/github.com/${GH_ACCOUNT}/${PORTNAME}/api ${LN} -s ${WRKSRC}/sdk ${WRKSRC}/vendor/github.com/${GH_ACCOUNT}/${PORTNAME}/sdk +pre-install: + ${MKDIR} ${STAGEDIR}${ETCDIR} + ${MKDIR} ${STAGEDIR}${CONSUL_DATADIR} + +post-install: + @${ECHO_CMD} "@dir(${CONSUL_USER},${CONSUL_GROUP},750) ${ETCDIR}" >> ${TMPPLIST} + @${ECHO_CMD} "@dir(${CONSUL_USER},${CONSUL_GROUP},750) ${CONSUL_DATADIR}" >> ${TMPPLIST} + .include --- sysutils/consul/files/consul.in (revision 513055) +++ sysutils/consul/files/consul.in (working copy) @@ -6,47 +6,79 @@ # REQUIRE: LOGIN # KEYWORD: shutdown # -# Add the following lines to /etc/rc.conf.local or /etc/rc.conf -# to enable this service: +# Add consul_enable="YES" to /etc/rc.conf to enable Consul # -# consul_enable (bool): Set to NO by default. -# Set it to YES to enable consul. -# consul_user (user): Set user to run consul. -# Default is "consul". -# consul_group (group): Set group to run consul. -# Default is "consul". -# consul_dir (dir): Set dir to run consul in. -# Default is "/var/db/consul". +# Additional variables you can define are: +# +# consul_debug (bool) +# Set it to YES to enable Consul debugging to syslog +# Set to NO by default +# consul_user (string) +# Set user that Consul will run under +# Default is "%%CONSUL_USER%%" +# consul_pidfile (string) +# Set full path to pid file +# Default is "/var/run/consul.pid" +# consul_configtest (bool) +# Set it to NO to disable Consul config validation +# Set to YES by default +# consul_data_dir (string) +# Set dir to store Consul state +# Default is "%%CONSUL_DATADIR%%" +# consul_env (string) +# Set environment variables used with Consul +# Default is "" +# consul_args (string) +# Set additional command line arguments +# Default is "" . /etc/rc.subr name=consul rcvar=consul_enable -extra_commands="reload configtest" +extra_commands="reload" + load_rc_config $name : ${consul_enable:="NO"} -: ${consul_user:="consul"} -: ${consul_group:="consul"} -: ${consul_dir:="/var/db/consul"} +: ${consul_debug:="NO"} +: ${consul_user:="%%CONSUL_USER%%"} +: ${consul_pidfile:="/var/run/consul.pid"} +: ${consul_configtest:="YES"} +: ${consul_datadir:="%%CONSUL_DATADIR%%"} -pidfile=/var/run/consul.pid +_consul_user=${consul_user} +unset consul_user + +# backwards compatibility +if [ -n "${consul_dir}"; ]; then + consul_datadir=${consul_dir} +fi + +if checkyesno consul_debug; then + consul_syslog_flags="-T ${name}" +fi + +if checkyesno consul_configtest; then + restart_precmd="consul_checkconfig" + reload_precmd="consul_checkconfig" + configtest_cmd="consul_checkconfig" + extra_commands="${extra_commands} configtest" +fi + +pidfile=${consul_pidfile} +required_dirs="%%ETCDIR%% ${consul_datadir}" + procname="%%PREFIX%%/bin/consul" command="/usr/sbin/daemon" -command_args="-f -p ${pidfile} /usr/bin/env ${consul_env} ${procname} agent -data-dir=${consul_dir} -config-dir=%%PREFIX%%/etc/consul.d ${consul_args}" +command_consul="/usr/bin/env ${consul_env} ${procname} agent -data-dir=${consul_datadir} -config-dir=%%ETCDIR%% ${consul_args}" +command_args="-f ${consul_syslog_flags} -p ${pidfile} -u ${_consul_user} -t ${name} ${command_consul}" -start_precmd=consul_startprecmd - -consul_startprecmd() +consul_checkconfig() { - if [ ! -e ${pidfile} ]; then - install -o ${consul_user} -g ${consul_group} /dev/null ${pidfile}; - fi - - if [ ! -d ${consul_dir} ]; then - install -d -o ${consul_user} -g ${consul_group} ${consul_dir} - fi + echo "Performing sanity check on ${name} configuration:" + eval ${procname} validate %%ETCDIR%% } run_rc_command "$1"