From 6fb08baee3602fc28c323a8eced868fd49050d7f Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 15 Aug 2020 16:40:15 -0400 Subject: Rename project to catsit --- .gitignore | 5 +- Makefile | 6 +- catsit.8 | 97 +++++++++++++++++++++++++++++ catsit.conf.5 | 71 +++++++++++++++++++++ catsit.sh | 34 ++++++++++ catsitd.8 | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ daemon.c | 4 +- spawn.8 | 97 ----------------------------- spawn.sh | 34 ---------- spawnd.8 | 197 ---------------------------------------------------------- spawntab.5 | 71 --------------------- 11 files changed, 407 insertions(+), 406 deletions(-) create mode 100644 catsit.8 create mode 100644 catsit.conf.5 create mode 100644 catsit.sh create mode 100644 catsitd.8 delete mode 100644 spawn.8 delete mode 100644 spawn.sh delete mode 100644 spawnd.8 delete mode 100644 spawntab.5 diff --git a/.gitignore b/.gitignore index ffd4582..3b0a7f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.o +catsit +catsit.conf +catsitd config.mk -spawn -spawnd tags diff --git a/Makefile b/Makefile index 5cf0897..d0448ce 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,9 @@ CFLAGS += -D'ETCDIR="${ETCDIR}"' -D'RUNDIR="${RUNDIR}"' -include config.mk -BINS = spawn spawnd +BINS = catsit catsitd MAN8 = ${BINS:=.8} -MAN5 = spawntab.5 +MAN5 = catsit.conf.5 OBJS += daemon.o OBJS += service.o @@ -19,7 +19,7 @@ dev: tags all all: ${BINS} -spawnd: ${OBJS} +catsitd: ${OBJS} ${CC} ${LDFLAGS} ${OBJS} ${LDLIBS} -o $@ ${OBJS}: daemon.h diff --git a/catsit.8 b/catsit.8 new file mode 100644 index 0000000..d901359 --- /dev/null +++ b/catsit.8 @@ -0,0 +1,97 @@ +.Dd August 15, 2020 +.Dt CATSIT 8 +.Os +. +.Sh NAME +.Nm catsit +.Nd catsitd control +. +.Sh SYNOPSIS +.Nm +.Op Fl c Ar control +.Cm start|stop|restart|status Ns | Ns Ar signal +.Ar service ... +. +.Sh DESCRIPTION +The +.Nm +utility controls +the services managed by the +.Xr catsitd 8 +daemon. +It does so by writing +the remainder of its command line +to a named pipe. +. +.Pp +Communication with +.Xr catsitd 8 +is unidirectional. +The daemon logs any feedback +with syslog. +. +.Pp +The arguments are as follows: +.Bl -tag -width Ds +.It Fl c Ar control +Set the path of the named pipe. +. +.It Cm start +Start any matching services +which are not already started. +. +.It Cm stop +Stop any matching services +which are not already stopped. +Processes are stopped using the +.Dv TERM +signal. +. +.It Cm restart +Restart any matching services. +Started services will first be stopped, +then stopped services will be started. +. +.It Cm status +Log the current status of any matching services. +. +.It Ar signal +Send the named signal +to the processes of any matching started services. +. +.It Ar service ... +The list of services to operate on. +Service names can include +the shell-style pattern operators +.Sy *?[] . +Be sure to quote service name patterns +so they are not interpreted by the shell. +.El +. +.Sh ENVIRONMENT +.Bl -tag -width Ds +.It Ev CATSITD_PIPE +The path of the named pipe. +The +.Fl c +flag overrides this variable. +.El +. +.Sh FILES +.Bl -tag -width Ds +.It Pa /var/run/catsitd.pipe +The default path of the named pipe. +.El +. +.Sh EXAMPLES +.Bd -literal +catsit start pounce/freenode +catsit status '*' +catsit USR1 'pounce/*' +.Ed +. +.Sh SEE ALSO +.Xr catsitd 8 +. +.Sh AUTHORS +.An June Bug Aq Mt june@causal.agency diff --git a/catsit.conf.5 b/catsit.conf.5 new file mode 100644 index 0000000..36fc463 --- /dev/null +++ b/catsit.conf.5 @@ -0,0 +1,71 @@ +.Dd August 13, 2020 +.Dt CATSIT.CONF 5 +.Os +. +.Sh NAME +.Nm catsit.conf +.Nd catsitd services list +. +.Sh DESCRIPTION +The +.Nm +file lists the services managed by the +.Xr catsitd 8 +daemon. +Leading whitespace is ignored. +Each line of the file +is one of the following: +. +.Bl -tag -width Ds +.It Cm # Ar comment ... +Lines beinning with +.Ql # +and blank lines are ignored. +. +.It Cm % Ar command ... +Lines beginning with +.Ql % +add shell commands +to be executed before +each of the service commands. +These commands are executed +in the order they appear in the file, +for all services. +These lines can be used to +set shell or environment variables +to be expanded in service command lines +or used by the service processes. +. +.It Ar service Ar command ... +All other lines define services. +The service name is separated +from its command line by whitespace. +The rest of the line after the service name +is executed using the shell. +The shell variable +.Va $0 +is set to the name of the service. +.El +. +.Sh EXAMPLES +.Bd -literal +# Basic services: +calico calico -H irc.example.org /var/run/calico +pounce/freenode pounce /usr/local/etc/pounce/freenode.conf +pounce/tilde pounce /usr/local/etc/pounce/tilde.conf + +# Setting environment variables: +% export PATH=$PATH:/usr/local/bin + +# Using variables to expand service command lines: +% pounce=/usr/local/bin/pounce +% conf=/usr/local/etc/pounce +pounce/freenode $pounce $conf/freenode.conf +pounce/tilde $pounce $conf/tilde.conf +.El +. +.Sh SEE ALSO +.Xr catsitd 8 +. +.Sh AUTHORS +.An June Bug Aq Mt june@causal.agency diff --git a/catsit.sh b/catsit.sh new file mode 100644 index 0000000..bc18a46 --- /dev/null +++ b/catsit.sh @@ -0,0 +1,34 @@ +#!/bin/sh +set -eu + +die() { + echo "${0}:" "$@" >&2 + exit 1 +} + +: ${CATSITD_PIPE:=/var/run/catsitd.pipe} + +while getopts 'c:' opt; do + case "${opt}" in + (c) CATSITD_PIPE=$OPTARG;; + (?) exit 1;; + esac +done +shift $((OPTIND - 1)) + +if ! [ -p "${CATSITD_PIPE}" ]; then + die "${CATSITD_PIPE} is not a named pipe" +fi + +[ $# -lt 1 ] && die 'action required' +[ $# -lt 2 ] && die 'service name required' + +action=$(echo "${1}" | tr 'A-Z' 'a-z') +for valid in start stop restart status $(kill -l | tr 'A-Z' 'a-z'); do + [ "${action}" = "${valid}" ] && break +done +if [ "${action}" != "${valid}" ]; then + die "${action} is not a valid action or signal" +fi + +echo "$@" > "${CATSITD_PIPE}" diff --git a/catsitd.8 b/catsitd.8 new file mode 100644 index 0000000..cdb77a0 --- /dev/null +++ b/catsitd.8 @@ -0,0 +1,197 @@ +.Dd August 13, 2020 +.Dt CATSITD 8 +.Os +. +.Sh NAME +.Nm catsitd +.Nd process supervisor +. +.Sh SYNOPSIS +.Nm +.Op Fl d +.Op Fl C Ar path +.Op Fl c Ar control +.Op Fl f Ar config +.Op Fl g Ar group +.Op Fl p Ar pidfile +.Op Fl s Ar stopexits +.Op Fl t Ar interval +.Op Fl u Ar user +. +.Sh DESCRIPTION +The +.Nm +daemon +is a supervisor for processes +with the following behavior: +.Bl -enum +.It +The process runs in the foreground, +not as a daemon. +.It +The process logs to standard output or standard error. +.It +The process handles errors by exiting +and expects to be restarted. +.It +The process indicates its reason for exiting with +.Xr sysexits 3 . +.El +. +.Pp +The +.Nm +daemon spawns processes for a list of +.Em services , +redirects their output to syslog, +and restarts the processes when they exit +according to their exit status. +Exponential backoff is applied to restarts. +. +.Pp +The list of services is defined in a +.Xr catsit.conf 5 +file. +The services managed by +.Nm +can be controlled +through a named pipe. +The +.Xr catsit 8 +utility is a wrapper +around the named pipe, +and its manual page +describes the control command format. +. +.Pp +The arguments are as follows: +.Bl -tag -width Ds +.It Fl C Ar path +Change directory to +.Ar path +before starting services. +By default the working directory is +.Pa / . +. +.It Fl c Ar control +Set the path of the named pipe +used for control. +. +.It Fl d +Do not run as a daemon. +. +.It Fl f Ar config +Set the path of the +.Xr catsit.conf 5 +file. +. +.It Fl g Ar group +Change group to +.Ar group +before starting services. +If +.Fl u +is used, +the default group is the user's group. +. +.It Fl p Ar pidfile +Write the PID of the +.Nm +process to +.Ar pidfile . +. +.It Fl s Ar stopexits +Set the list of exit statuses +for which a restart will not be attempted. +The +.Ar stopexits +argument is a comma-separated list of integers. +The default list contains the values of +.Dv EX_USAGE , +.Dv EX_DATAERR , +.Dv EX_NOINPUT , +.Dv EX_OSFILE , +.Dv EX_CANTCREAT , +.Dv EX_CONFIG +defined in +.Xr sysexits 3 . +The exit status 127 +is always treated as a stop exit. +. +.It Fl t Ar interval +Set the initial interval between restarts +in milliseconds. +The default interval is 1000. +. +.It Fl u Ar user +Change user to +.Ar user +before starting services. +.El +. +.Pp +When the +.Nm +daemon receives the +.Dv HUP +signal, +the +.Xr catsit.conf 5 +file is reloaded. +Modified services +are not automatically restarted, +newly added services +are not automatically started, +and removed services +are not automatically stopped. +. +.Pp +When the +.Nm +daemon receives the +.Dv TERM +signal, +the control named pipe is closed, +all services are stopped, +and +.Nm +exits. +. +.Sh ENVIRONMENT +Services are started +with empty environments +apart from the following: +.Bl -tag -width Ds +.It Ev LOGNAME , Ev USER +Set to the name of the user specified by +.Fl u . +.It Ev HOME +Set to the home directory of the user specified by +.Fl u . +.It Ev SHELL +Set to +.Pa /bin/sh . +.It Ev PATH +Set to the system default defined by +.Dv _PATH_DEFPATH +in +.In paths.h . +.El +. +.Sh FILES +.Bl -tag -width Ds +.It Pa /usr/local/etc/catsit.conf +The default path of the +.Xr catsit.conf 5 +file. +.It Pa /var/run/catsitd.pipe +The default path of the named pipe +used for control. +.El +. +.Sh SEE ALSO +.Xr catsit.conf 5 , +.Xr catsit 8 +. +.Sh AUTHORS +.An June Bug Aq Mt june@causal.agency diff --git a/daemon.c b/daemon.c index 095e962..c873e8a 100644 --- a/daemon.c +++ b/daemon.c @@ -191,8 +191,8 @@ int main(int argc, char *argv[]) { setAdd(&stopExits, EX_CONFIG); const char *pidPath = NULL; - const char *configPath = ETCDIR "/spawntab"; - const char *fifoPath = RUNDIR "/spawnd.pipe"; + const char *configPath = ETCDIR "/catsit.conf"; + const char *fifoPath = RUNDIR "/catsitd.pipe"; const char *userName = NULL; const char *groupName = NULL; diff --git a/spawn.8 b/spawn.8 deleted file mode 100644 index f5ecc6c..0000000 --- a/spawn.8 +++ /dev/null @@ -1,97 +0,0 @@ -.Dd August 13, 2020 -.Dt SPAWN 8 -.Os -. -.Sh NAME -.Nm spawn -.Nd spawnd control -. -.Sh SYNOPSIS -.Nm -.Op Fl c Ar control -.Cm start|stop|restart|status Ns | Ns Ar signal -.Ar service ... -. -.Sh DESCRIPTION -The -.Nm -utility controls -the services managed by the -.Xr spawnd 8 -daemon. -It does so by writing -the remainder of its command line -to a named pipe. -. -.Pp -Communication with -.Xr spawnd 8 -is unidirectional. -The daemon logs any feedback -with syslog. -. -.Pp -The arguments are as follows: -.Bl -tag -width Ds -.It Fl c Ar control -Set the path of the named pipe. -. -.It Cm start -Start any matching services -which are not already started. -. -.It Cm stop -Stop any matching services -which are not already stopped. -Processes are stopped using the -.Dv TERM -signal. -. -.It Cm restart -Restart any matching services. -Started services will first be stopped, -then stopped services will be started. -. -.It Cm status -Log the current status of any matching services. -. -.It Ar signal -Send the named signal -to the processes of any matching started services. -. -.It Ar service ... -The list of services to operate on. -Service names can include -the shell-style pattern operators -.Sy *?[] . -Be sure to quote service name patterns -so they are not interpreted by the shell. -.El -. -.Sh ENVIRONMENT -.Bl -tag -width Ds -.It Ev SPAWND_PIPE -The path of the named pipe. -The -.Fl c -flag overrides this variable. -.El -. -.Sh FILES -.Bl -tag -width Ds -.It Pa /var/run/spawnd.pipe -The default path of the named pipe. -.El -. -.Sh EXAMPLES -.Bd -literal -spawn start pounce/freenode -spawn status '*' -spawn USR1 'pounce/*' -.Ed -. -.Sh SEE ALSO -.Xr spawnd 8 -. -.Sh AUTHORS -.An June Bug Aq Mt june@causal.agency diff --git a/spawn.sh b/spawn.sh deleted file mode 100644 index 052a7fd..0000000 --- a/spawn.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -set -eu - -die() { - echo "${0}:" "$@" >&2 - exit 1 -} - -: ${SPAWND_PIPE:=/var/run/spawnd.pipe} - -while getopts 'c:' opt; do - case "${opt}" in - (c) SPAWND_PIPE=$OPTARG;; - (?) exit 1;; - esac -done -shift $((OPTIND - 1)) - -if ! [ -p "${SPAWND_PIPE}" ]; then - die "${SPAWND_PIPE} is not a named pipe" -fi - -[ $# -lt 1 ] && die 'action required' -[ $# -lt 2 ] && die 'service name required' - -action=$(echo "${1}" | tr 'A-Z' 'a-z') -for valid in start stop restart status $(kill -l | tr 'A-Z' 'a-z'); do - [ "${action}" = "${valid}" ] && break -done -if [ "${action}" != "${valid}" ]; then - die "${action} is not a valid action or signal" -fi - -echo "$@" > "${SPAWND_PIPE}" diff --git a/spawnd.8 b/spawnd.8 deleted file mode 100644 index 1981304..0000000 --- a/spawnd.8 +++ /dev/null @@ -1,197 +0,0 @@ -.Dd August 13, 2020 -.Dt SPAWND 8 -.Os -. -.Sh NAME -.Nm spawnd -.Nd process supervisor -. -.Sh SYNOPSIS -.Nm -.Op Fl d -.Op Fl C Ar path -.Op Fl c Ar control -.Op Fl f Ar spawntab -.Op Fl g Ar group -.Op Fl p Ar pidfile -.Op Fl s Ar stopexits -.Op Fl t Ar interval -.Op Fl u Ar user -. -.Sh DESCRIPTION -The -.Nm -daemon -is a supervisor for processes -with the following behavior: -.Bl -enum -.It -The process runs in the foreground, -not as a daemon. -.It -The process logs to standard output or standard error. -.It -The process handles errors by exiting -and expects to be restarted. -.It -The process indicates its reason for exiting with -.Xr sysexits 3 . -.El -. -.Pp -The -.Nm -daemon spawns processes for a list of -.Em services , -redirects their output to syslog, -and restarts the processes when they exit -according to their exit status. -Exponential backoff is applied to restarts. -. -.Pp -The list of services is defined in a -.Xr spawntab 5 -file. -The services managed by -.Nm -can be controlled -through a named pipe. -The -.Xr spawn 8 -utility is a wrapper -around the named pipe, -and its manual page -describes the control command format. -. -.Pp -The arguments are as follows: -.Bl -tag -width Ds -.It Fl C Ar path -Change directory to -.Ar path -before starting services. -By default the working directory is -.Pa / . -. -.It Fl c Ar control -Set the path of the named pipe -used for control. -. -.It Fl d -Do not run as a daemon. -. -.It Fl f Ar spawntab -Set the path of the -.Xr spawntab 5 -file. -. -.It Fl g Ar group -Change group to -.Ar group -before starting services. -If -.Fl u -is used, -the default group is the user's group. -. -.It Fl p Ar pidfile -Write the PID of the -.Nm -process to -.Ar pidfile . -. -.It Fl s Ar stopexits -Set the list of exit statuses -for which a restart will not be attempted. -The -.Ar stopexits -argument is a comma-separated list of integers. -The default list contains the values of -.Dv EX_USAGE , -.Dv EX_DATAERR , -.Dv EX_NOINPUT , -.Dv EX_OSFILE , -.Dv EX_CANTCREAT , -.Dv EX_CONFIG -defined in -.Xr sysexits 3 . -The exit status 127 -is always treated as a stop exit. -. -.It Fl t Ar interval -Set the initial interval between restarts -in milliseconds. -The default interval is 1000. -. -.It Fl u Ar user -Change user to -.Ar user -before starting services. -.El -. -.Pp -When the -.Nm -daemon receives the -.Dv HUP -signal, -the -.Xr spawntab 5 -file is reloaded. -Modified services -are not automatically restarted, -newly added services -are not automatically started, -and removed services -are not automatically stopped. -. -.Pp -When the -.Nm -daemon receives the -.Dv TERM -signal, -the control named pipe is closed, -all services are stopped, -and -.Nm -exits. -. -.Sh ENVIRONMENT -Services are started -with empty environments -apart from the following: -.Bl -tag -width Ds -.It Ev LOGNAME , Ev USER -Set to the name of the user specified by -.Fl u . -.It Ev HOME -Set to the home directory of the user specified by -.Fl u . -.It Ev SHELL -Set to -.Pa /bin/sh . -.It Ev PATH -Set to the system default defined by -.Dv _PATH_DEFPATH -in -.In paths.h . -.El -. -.Sh FILES -.Bl -tag -width Ds -.It Pa /usr/local/etc/spawntab -The default path of the -.Xr spawntab 5 -file. -.It Pa /var/run/spawnd.pipe -The default path of the named pipe -used for control. -.El -. -.Sh SEE ALSO -.Xr spawntab 5 , -.Xr spawn 8 -. -.Sh AUTHORS -.An June Bug Aq Mt june@causal.agency diff --git a/spawntab.5 b/spawntab.5 deleted file mode 100644 index 5819ff9..0000000 --- a/spawntab.5 +++ /dev/null @@ -1,71 +0,0 @@ -.Dd August 13, 2020 -.Dt SPAWNTAB 5 -.Os -. -.Sh NAME -.Nm spawntab -.Nd spawnd services list -. -.Sh DESCRIPTION -The -.Nm -file lists the services managed by the -.Xr spawnd 8 -daemon. -Leading whitespace is ignored. -Each line of the file -is one of the following: -. -.Bl -tag -width Ds -.It Cm # Ar comment ... -Lines beinning with -.Ql # -and blank lines are ignored. -. -.It Cm % Ar command ... -Lines beginning with -.Ql % -add shell commands -to be executed before -each of the service commands. -These commands are executed -in the order they appear in the file, -for all services. -These lines can be used to -set shell or environment variables -to be expanded in service command lines -or used by the service processes. -. -.It Ar service Ar command ... -All other lines define services. -The service name is separated -from its command line by whitespace. -The rest of the line after the service name -is executed using the shell. -The shell variable -.Va $0 -is set to the name of the service. -.El -. -.Sh EXAMPLES -.Bd -literal -# Basic services: -calico calico -H irc.example.org /var/run/calico -pounce/freenode pounce /usr/local/etc/pounce/freenode.conf -pounce/tilde pounce /usr/local/etc/pounce/tilde.conf - -# Setting environment variables: -% export PATH=$PATH:/usr/local/bin - -# Using variables to expand service command lines: -% pounce=/usr/local/bin/pounce -% conf=/usr/local/etc/pounce -pounce/freenode $pounce $conf/freenode.conf -pounce/tilde $pounce $conf/tilde.conf -.El -. -.Sh SEE ALSO -.Xr spawnd 8 -. -.Sh AUTHORS -.An June Bug Aq Mt june@causal.agency -- cgit 1.4.1