From 8262e792d45ac7f7677124d66fe80f3679ebfcc0 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sat, 1 Feb 2020 03:22:22 -0800 Subject: [PATCH] make rc.d file dynamic --- Makefile | 6 +++++- init/bsd/unifi-poller.rc | 31 +++++++++++++++++++++--------- init/homebrew/service.rb.tmpl | 2 +- init/launchd/README.md | 2 +- init/systemd/template.unit.service | 2 +- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 167a7103..8f921711 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ endif # rpm is wierd and changes - to _ in versions. RPMVERSION:=$(shell echo $(VERSION) | tr -- - _) +BINARYU:=$(shell echo $(BINARY) | tr -- - _) PACKAGE_SCRIPTS= ifeq ($(FORMULA),service) @@ -257,7 +258,10 @@ package_build_freebsd: readme man freebsd cp examples/$(CONFIG_FILE).example $@/usr/local/etc/$(BINARY)/$(CONFIG_FILE) cp LICENSE *.html examples/*?.?* $@/usr/local/share/doc/$(BINARY)/ [ "$(FORMULA)" != "service" ] || mkdir -p $@/usr/local/etc/rc.d - [ "$(FORMULA)" != "service" ] || cp init/bsd/unifi-poller.rc $@/usr/local/etc/rc.d/unifi-poller + [ "$(FORMULA)" != "service" ] || \ + sed -e "s/{{BINARY}}/$(BINARY)/g" -e "s/{{BINARYU}}/$(BINARYU)/g" -e "s/{{CONFIG_FILE}}/$(CONFIG_FILE)/g" \ + init/bsd/unifi-poller.rc > $@/usr/local/etc/rc.d/unifi-poller + [ "$(FORMULA)" != "service" ] || chmod +x $@/usr/local/etc/rc.d/unifi-poller package_build_freebsd_386: package_build_freebsd freebsd386 mkdir -p $@ diff --git a/init/bsd/unifi-poller.rc b/init/bsd/unifi-poller.rc index 797fbe24..d0241acb 100755 --- a/init/bsd/unifi-poller.rc +++ b/init/bsd/unifi-poller.rc @@ -1,6 +1,11 @@ #!/bin/sh # -# rc.d startup script for unifi-poller. Written for FreeBSD. +# FreeBSD rc.d startup script for unifi-poller. +# Target like so: +# sed -e "s/{{BINARY}}/app-name/g" +# -e "s/{{BINARYU}}/app_name/g" \ +# -e "s/{{CONFIG_FILE}}/app-name.conf/g" \ +# thisfile.rc > /usr/local/etc/rc.d/unifi-poller # # PROVIDE: unifi-poller # REQUIRE: networking syslog @@ -8,15 +13,23 @@ . /etc/rc.subr -name="unifipoller" -rcvar="unifipoller_enable" -command="/usr/local/bin/unifi-poller" -unifipoller_user="nobody" -unifipoller_config="/usr/local/etc/unifi-poller/up.conf" +name="{{BINARYU}}" +rcvar="{{BINARYU}}_enable" +{{BINARYU}}_command="/usr/local/bin/{{BINARY}}" +{{BINARYU}}_user="nobody" +{{BINARYU}}_config="/usr/local/etc/{{BINARY}}/{{CONFIG_FILE}}" +pidfile="/var/run/{{BINARY}}/pid" -start_cmd="/usr/sbin/daemon -T $name -l daemon -u $unifipoller_user $command -c $unifipoller_config" +# This runs `daemon` as the `{{BINARYU}}_user` user. +command="/usr/sbin/daemon" +command_args="-P ${pidfile} -r -t {{BINARY}} -T {{BINARY}} -l daemon ${{{BINARYU}}_command} -c ${{{BINARYU}}_config}" -load_rc_config $name -: ${unifipoller_enable:=no} +load_rc_config ${name} +: ${{{BINARYU}}_enable:=no} +# Make a place for the pid file. +mkdir -p $(dirname ${pidfile}) +chown -R ${{BINARYU}}_user $(dirname ${pidfile}) + +# Go! run_rc_command "$1" diff --git a/init/homebrew/service.rb.tmpl b/init/homebrew/service.rb.tmpl index de494c11..00921281 100644 --- a/init/homebrew/service.rb.tmpl +++ b/init/homebrew/service.rb.tmpl @@ -1,4 +1,4 @@ -# Homebrew Formula Template. Built by Makefile: `make fomula` +# macOS Homebrew Formula Template. Built by Makefile: `make fomula` # This is part of Application Builder. # https://github.com/golift/application-builder class {{Class}} < Formula diff --git a/init/launchd/README.md b/init/launchd/README.md index 285631f2..d5a6e8ae 100644 --- a/init/launchd/README.md +++ b/init/launchd/README.md @@ -1,2 +1,2 @@ This file isn't used by the build or for any packages. The homebrew launchd is -in the [homebrew](../homebrew) folder. This file is for reference only. +in the [homebrew](../homebrew) folder. This macOS launchd file is for reference only. diff --git a/init/systemd/template.unit.service b/init/systemd/template.unit.service index 82673d82..15ae80c8 100644 --- a/init/systemd/template.unit.service +++ b/init/systemd/template.unit.service @@ -1,4 +1,4 @@ -# Systemd service unit for {{BINARY}}. +# Linux Systemd service unit for {{BINARY}}. # This is part of Application Builder. # https://github.com/golift/application-builder