#!/bin/sh # PROVIDE: openarc # REQUIRE: DAEMON # BEFORE: mail # KEYWORD: shutdown . /etc/rc.subr # Copyright (c) 2021, The JMBG Network. All rights reserved. name="openarc" rcvar=openarc_enable extra_commands="reload" start_precmd="openarc_prepcmd" start_postcmd="openarc_start_postcmd" stop_postcmd="openarc_postcmd" command="/usr/local/sbin/openarc" _piddir="/var/run/openarc" pidfile="${_piddir}/pid" sig_reload="USR1" load_rc_config $name # # DO NOT CHANGE THESE DEFAULT VALUES HERE # : ${openarc_enable="NO"} : ${openarc_uid="mailnull"} : ${openarc_gid="mailnull"} : ${openarc_cfgfile="/usr/local/etc/openarc/openarc.conf"} : ${openarc_socket_perms="0755"} # Options other than above can be set with $openarc_flags. if [ -n "$2" ]; then profile="$2" if [ "x${openarc_profiles}" != "x" ]; then pidfile="${_piddir}/${profile}.pid" eval openarc_enable="\${openarc_${profile}_enable:-${openarc_enable}}" eval openarc_socket="\${openarc_${profile}_socket:-}" eval openarc_socket_perms="\${openarc_${profile}_socket_perms:-}" if [ "x${openarc_socket}" = "x" ];then echo "You must define a socket (openarc_${profile}_socket)" exit 1 fi eval openarc_cfgfile="\${openarc_${profile}_cfgfile:-${openarc_cfgfile}}" eval openarc_domain="\${openarc_${profile}_domain:-${openarc_domain}}" eval openarc_key="\${openarc_${profile}_key:-${openarc_key}}" eval openarc_selector="\${openarc_${profile}_selector:-${openarc_selector}}" eval openarc_alg="\${openarc_${profile}_alg:-${openarc_alg}}" eval openarc_flags="\${openarc_${profile}_flags:-${openarc_flags}}" if [ -f "${openarc_cfgfile}" ];then openarc_cfgfile="-c ${openarc_cfgfile}" else openarc_cfgfile="" fi if [ "x${openarc_socket}" != "x" ];then _socket_prefix="-p" fi if [ "x${openarc_uid}" != "x" ];then _uid_prefix="-u" if [ "x${openarc_gid}" != "x" ];then openarc_uid=${openarc_uid}:${openarc_gid} fi fi if [ "x${openarc_domain}" != "x" ];then openarc_domain="-d ${openarc_domain}" fi if [ "x${openarc_key}" != "x" ];then openarc_key="-k ${openarc_key}" fi if [ "x${openarc_selector}" != "x" ];then openarc_selector="-s ${openarc_selector}" fi if [ "x${openarc_alg}" != "x" ];then openarc_alg="-S ${openarc_alg}" fi command_args="-l ${_socket_prefix} ${openarc_socket} ${_uid_prefix} ${openarc_uid} -P ${pidfile} ${openarc_cfgfile} ${openarc_domain} ${openarc_key} ${openarc_selector} ${openarc_alg}" else echo "$0: extra argument ignored" fi else if [ "x${openarc_profiles}" != "x" -a "x$1" != "x" ]; then if [ "x$1" != "xrestart" ]; then for profile in ${openarc_profiles}; do echo "===> openarc profile: ${profile}" /usr/local/etc/rc.d/openarc $1 ${profile} retcode="$?" if [ "0${retcode}" -ne 0 ]; then failed="${profile} (${retcode}) ${failed:-}" else success="${profile} ${success:-}" fi done exit 0 else restart_precmd="" fi else if [ -f "${openarc_cfgfile}" ];then openarc_cfgfile="-c ${openarc_cfgfile}" else openarc_cfgfile="" fi if [ "x${openarc_socket}" != "x" ];then _socket_prefix="-p" fi if [ "x${openarc_uid}" != "x" ];then _uid_prefix="-u" if [ "x${openarc_gid}" != "x" ];then openarc_uid=${openarc_uid}:${openarc_gid} fi fi if [ "x${openarc_domain}" != "x" ];then openarc_domain="-d ${openarc_domain}" fi if [ "x${openarc_key}" != "x" ];then openarc_key="-k ${openarc_key}" fi if [ "x${openarc_selector}" != "x" ];then openarc_selector="-s ${openarc_selector}" fi if [ "x${openarc_alg}" != "x" ];then openarc_alg="-S ${openarc_alg}" fi command_args="-l ${_socket_prefix} ${openarc_socket} ${_uid_prefix} ${openarc_uid} -P ${pidfile} ${openarc_cfgfile} ${openarc_domain} ${openarc_key} ${openarc_selector} ${openarc_alg}" fi fi openarc_prepcmd () { if [ -S ${openarc_socket##local:} ] ; then rm -f ${openarc_socket##local:} elif [ -S ${openarc_socket##unix:} ] ; then rm -f ${openarc_socket##unix:} fi if [ ! -d ${_piddir} ] ; then mkdir -p ${_piddir} fi if [ -n "${openarc_uid}" ] ; then chown ${openarc_uid} ${_piddir} fi if [ -n "${openarc_gid}" ] ; then chgrp ${openarc_gid} ${_piddir} fi chmod ${openarc_socket_perms} ${_piddir} } openarc_start_postcmd () { if [ "x${openarc_socket}" != "x" ] ; then # postcmd is executed too fast and socket is not created before checking... sleep 1 if [ -S ${openarc_socket##local:} ] ; then chmod ${openarc_socket_perms} ${openarc_socket##local:} elif [ -S ${openarc_socket##unix:} ] ; then chmod ${openarc_socket_perms} ${openarc_socket##unix:} fi fi } openarc_postcmd() { if [ "x${openarc_socket}" != "x" ] ; then if [ -S ${openarc_socket##local:} ] ; then rm -f ${openarc_socket##local:} elif [ -S ${openarc_socket##unix:} ] ; then rm -f ${openarc_socket##unix:} fi fi # just if the directory is empty rmdir ${_piddir} > /dev/null 2>&1 } run_rc_command "$1"