From dd64f64db665840b35cd980291f1c14711ac42d2 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 12 Mar 2024 06:07:07 -0700 Subject: feat: systemd support Signed-off-by: Robin H. Johnson --- .gitignore | 3 +++ fifo-cronolog-setup | 17 +++++++++++++++++ fifo-cronolog.c | 27 +++------------------------ fifo-cronolog.confd | 11 ----------- fifo-cronolog.initd | 29 ----------------------------- openrc/fifo-cronolog.confd | 11 +++++++++++ openrc/fifo-cronolog.initd | 29 +++++++++++++++++++++++++++++ systemd/README.md | 4 ++++ systemd/fifo-cronolog@.service | 10 ++++++++++ systemd/fifo-cronolog@example.service.env | 4 ++++ 10 files changed, 81 insertions(+), 64 deletions(-) create mode 100644 .gitignore create mode 100755 fifo-cronolog-setup delete mode 100644 fifo-cronolog.confd delete mode 100644 fifo-cronolog.initd create mode 100644 openrc/fifo-cronolog.confd create mode 100644 openrc/fifo-cronolog.initd create mode 100644 systemd/README.md create mode 100644 systemd/fifo-cronolog@.service create mode 100644 systemd/fifo-cronolog@example.service.env diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..29b8ac9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +*.o +fifo-cronolog diff --git a/fifo-cronolog-setup b/fifo-cronolog-setup new file mode 100755 index 0000000..55f46f0 --- /dev/null +++ b/fifo-cronolog-setup @@ -0,0 +1,17 @@ +#!/bin/bash +# Copyright 2024-2024, Gentoo Foundation +# SPDX-License-Identifier: BSD-2-Clause +FIFO=$1 +FIFO_OWNER=$2 +FIFO_PERMS=$3 +if [ ! -e "${FIFO}" ]; then + mkfifo "$FIFO" || exit 1 +fi +if [ -p "${FIFO}" ]; then + chown "$FIFO_OWNER" "$FIFO" || exit 1 + chmod "$FIFO_PERMS" "$FIFO" || exit 1 +else + echo "${FIFO} is not a valid FIFO!" 1>&2 + exit 1 +fi +exit 0 diff --git a/fifo-cronolog.c b/fifo-cronolog.c index de87827..f7ff19f 100644 --- a/fifo-cronolog.c +++ b/fifo-cronolog.c @@ -1,27 +1,6 @@ /* -Copyright (c) 2007-2010, Gentoo Foundation -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. +Copyright 2010-2024, Gentoo Foundation +SPDX-License-Identifier: BSD-2-Clause */ #include @@ -35,7 +14,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#define VERSION "1.1.1" +#define VERSION "1.2.0" char *pidfile; diff --git a/fifo-cronolog.confd b/fifo-cronolog.confd deleted file mode 100644 index a73e291..0000000 --- a/fifo-cronolog.confd +++ /dev/null @@ -1,11 +0,0 @@ -# Various paths: -PIDFILE="/var/run/fifo-cronolog.pid" -FIFO="/var/lib/fifo-cronolog.fifo" -# User/Group of the fifo owner, will be set during startup if the fifo doesn't exist already -FIFO_OWNER="root:root" -FIFO_PERMS="0600" -LOGS="/var/log/fifo-cronolog/transfer/%Y%m%d.log" - -# Uncomment and add the service name you want to use it for to ensure -# fifo-cronolog start first. -#rc_fifo_cronolog_before="squid varnish" diff --git a/fifo-cronolog.initd b/fifo-cronolog.initd deleted file mode 100644 index 30812e6..0000000 --- a/fifo-cronolog.initd +++ /dev/null @@ -1,29 +0,0 @@ -#!/sbin/runscript -# Copyright 1999-2010 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -start() { - ebegin "Starting fifo-cronolog" - - if [ ! -e "${FIFO}" ]; then - mkfifo $FIFO || eend $? - fi - if [ -p "${FIFO}" ]; then - chown $FIFO_OWNER $FIFO || eend $? - chmod $FIFO_PERMS $FIFO || eend $? - else - eerror "${FIFO} is not a valid FIFO!" - eend 1 - fi - - start-stop-daemon --start --exec /usr/sbin/fifo-cronolog \ - --pidfile "${PIDFILE}" -- "${PIDFILE}" "${FIFO}" "${LOGS}" - eend $? -} - -stop() { - ebegin "Stopping fifo-cronolog" - start-stop-daemon --stop --exec /usr/sbin/fifo-cronolog \ - --pidfile "${PIDFILE}" - eend $? -} diff --git a/openrc/fifo-cronolog.confd b/openrc/fifo-cronolog.confd new file mode 100644 index 0000000..a73e291 --- /dev/null +++ b/openrc/fifo-cronolog.confd @@ -0,0 +1,11 @@ +# Various paths: +PIDFILE="/var/run/fifo-cronolog.pid" +FIFO="/var/lib/fifo-cronolog.fifo" +# User/Group of the fifo owner, will be set during startup if the fifo doesn't exist already +FIFO_OWNER="root:root" +FIFO_PERMS="0600" +LOGS="/var/log/fifo-cronolog/transfer/%Y%m%d.log" + +# Uncomment and add the service name you want to use it for to ensure +# fifo-cronolog start first. +#rc_fifo_cronolog_before="squid varnish" diff --git a/openrc/fifo-cronolog.initd b/openrc/fifo-cronolog.initd new file mode 100644 index 0000000..30812e6 --- /dev/null +++ b/openrc/fifo-cronolog.initd @@ -0,0 +1,29 @@ +#!/sbin/runscript +# Copyright 1999-2010 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +start() { + ebegin "Starting fifo-cronolog" + + if [ ! -e "${FIFO}" ]; then + mkfifo $FIFO || eend $? + fi + if [ -p "${FIFO}" ]; then + chown $FIFO_OWNER $FIFO || eend $? + chmod $FIFO_PERMS $FIFO || eend $? + else + eerror "${FIFO} is not a valid FIFO!" + eend 1 + fi + + start-stop-daemon --start --exec /usr/sbin/fifo-cronolog \ + --pidfile "${PIDFILE}" -- "${PIDFILE}" "${FIFO}" "${LOGS}" + eend $? +} + +stop() { + ebegin "Stopping fifo-cronolog" + start-stop-daemon --stop --exec /usr/sbin/fifo-cronolog \ + --pidfile "${PIDFILE}" + eend $? +} diff --git a/systemd/README.md b/systemd/README.md new file mode 100644 index 0000000..1d88021 --- /dev/null +++ b/systemd/README.md @@ -0,0 +1,4 @@ +1. Put env into `/etc/systemd-env/`, using the entire name of the unit, with instance suffix, and an extra `.env`, + e.g. `/etc/systemd-env/fifo-cronolog@example.service.env` +2. `systemctl enable fifo-cronolog@example` +3. Use systemd overrides if you need to add dependencies. diff --git a/systemd/fifo-cronolog@.service b/systemd/fifo-cronolog@.service new file mode 100644 index 0000000..0ab0962 --- /dev/null +++ b/systemd/fifo-cronolog@.service @@ -0,0 +1,10 @@ +[Unit] +Description=fifo-cronolog.%i +[Service] +Type=forking +EnvironmentFile=/etc/systemd-env/%n.env +PIDFile=/run/%N.pid +ExecStartPre=/usr/sbin/fifo-cronolog-setup $FIFO $FIFO_OWNER $FIFO_PERMS +ExecStart=/usr/sbin/fifo-cronolog /run/%N.pid $FIFO $LOGS +[Install] +WantedBy=multi-user.target diff --git a/systemd/fifo-cronolog@example.service.env b/systemd/fifo-cronolog@example.service.env new file mode 100644 index 0000000..370d157 --- /dev/null +++ b/systemd/fifo-cronolog@example.service.env @@ -0,0 +1,4 @@ +FIFO="/tmp/example.fifo" +FIFO_OWNER="somebody:somegroup" +FIFO_PERMS="0600" +LOGS="/var/log/example/%Y%m%d.log" -- cgit v1.2.3-65-gdbad