Skip to content

Commit

Permalink
Initial work for supporting multiple instances
Browse files Browse the repository at this point in the history
Service rename works, but we also need to handle config file,
log file, log pipe, eeprom file and maybe something more.

This feature was requested in #1407
  • Loading branch information
mfalkvidd committed May 8, 2020
1 parent 8103c6c commit 32b270b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
32 changes: 17 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include $(CONFIG_FILE)
CPPFLAGS+=-Ofast -g -Wall -Wextra
DEPFLAGS=-MT $@ -MMD -MP

GATEWAY_BIN=mysgw
GATEWAY_BIN=$(SERVICE_NAME)
GATEWAY=$(BINDIR)/$(GATEWAY_BIN)
GATEWAY_C_SOURCES=$(wildcard hal/architecture/Linux/drivers/core/*.c)
GATEWAY_CPP_SOURCES=$(wildcard hal/architecture/Linux/drivers/core/*.cpp) examples_linux/mysgw.cpp
Expand Down Expand Up @@ -124,31 +124,33 @@ install-gateway:

install-initscripts:
ifeq ($(INIT_SYSTEM), systemd)
install -m0644 initscripts/mysgw.systemd ${DESTDIR}/etc/systemd/system/mysgw.service
@sed -i -e "s|%gateway_dir%|${GATEWAY_DIR}|g" ${DESTDIR}/etc/systemd/system/mysgw.service
install -m0644 initscripts/mysgw.systemd ${DESTDIR}/etc/systemd/system/${SERVICE_NAME}.service
@sed -i -e "s|%gateway_dir%|${GATEWAY_DIR}|g" ${DESTDIR}/etc/systemd/system/${SERVICE_NAME}.service
@sed -i -e "s|%mysgw%|${SERVICE_NAME}|g" ${DESTDIR}/etc/systemd/system/${SERVICE_NAME}.service
systemctl daemon-reload
@echo "MySensors gateway has been installed, to add to the boot run:"
@echo " sudo systemctl enable mysgw.service"
@echo " sudo systemctl enable ${SERVICE_NAME}.service"
@echo "To start the gateway run:"
@echo " sudo systemctl start mysgw.service"
@echo " sudo systemctl start ${SERVICE_NAME}.service"
else ifeq ($(INIT_SYSTEM), sysvinit)
install -m0755 initscripts/mysgw.sysvinit ${DESTDIR}/etc/init.d/mysgw
@sed -i -e "s|%gateway_dir%|${GATEWAY_DIR}|g" ${DESTDIR}/etc/init.d/mysgw
install -m0755 initscripts/mysgw.sysvinit ${DESTDIR}/etc/init.d/${SERVICE_NAME}
@sed -i -e "s|%gateway_dir%|${GATEWAY_DIR}|g" ${DESTDIR}/etc/init.d/${SERVICE_NAME}
@sed -i -e "s|%mysgw%|${SERVICE_NAME}|g" ${DESTDIR}/etc/init.d/${SERVICE_NAME}
@echo "MySensors gateway has been installed, to add to the boot run:"
@echo " sudo update-rc.d mysgw defaults"
@echo " sudo update-rc.d ${SERVICE_NAME} defaults"
@echo "To start the gateway run:"
@echo " sudo service mysgw start"
@echo " sudo service ${SERVICE_NAME} start"
endif

uninstall:
ifeq ($(INIT_SYSTEM), systemd)
@echo "Stopping daemon mysgw (ignore errors)"
-@systemctl stop mysgw.service
@echo "Stopping daemon ${SERVICE_NAME} (ignore errors)"
-@systemctl stop ${SERVICE_NAME}.service
@echo "removing files"
rm /etc/systemd/system/mysgw.service $(GATEWAY_DIR)/$(GATEWAY_BIN)
rm /etc/systemd/system/${SERVICE_NAME}.service $(GATEWAY_DIR)/$(GATEWAY_BIN)
else ifeq ($(INIT_SYSTEM), sysvinit)
@echo "Stopping daemon mysgw (ignore errors)"
-@service mysgw stop
@echo "Stopping daemon ${SERVICE_NAME} (ignore errors)"
-@service ${SERVICE_NAME} stop
@echo "removing files"
rm /etc/init.d/mysgw $(GATEWAY_DIR)/$(GATEWAY_BIN)
rm /etc/init.d/${SERVICE_NAME} $(GATEWAY_DIR)/$(GATEWAY_BIN)
endif
9 changes: 7 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Original work: https://github.com/TMRh20/RF24/blob/master/configure

function help {
cat <<EOF
cat <<EOF
configure script for MySensors gateway.
Options:
Expand Down Expand Up @@ -34,6 +34,7 @@ Building options:
Installation options:
--prefix=<PREFIX> Installation prefix path. [/usr/local]
--gateway-dir=<DIR> Gateway files installation directory. [PREFIX/bin]
--service-name=<NAME> Name for the binary and systemd service. [mysgw]
MySensors options:
--my-debug=[enable|disable] Enables or disables MySensors core debugging. [enable]
Expand Down Expand Up @@ -297,7 +298,7 @@ signing=none
signing_request_signatures=false
encryption=false

params="SOC CFLAGS CXXFLAGS CPPFLAGS LDFLAGS PREFIX CC CXX ARDUINO_LIB_DIR BUILDDIR BINDIR GATEWAY_DIR INIT_SYSTEM SPI_DRIVER"
params="SOC CFLAGS CXXFLAGS CPPFLAGS LDFLAGS PREFIX CC CXX ARDUINO_LIB_DIR BUILDDIR BINDIR GATEWAY_DIR INIT_SYSTEM SPI_DRIVER SERVICE_NAME"

for opt do
if [ "$opt" = "-h" ] || [ "$opt" = "--help" ]; then
Expand Down Expand Up @@ -345,6 +346,9 @@ for opt do
--bin-dir=*)
BINDIR="$optarg"
;;
--service-name=*)
SERVICE_NAME="$optarg"
;;
--no-clean*)
NO_CLEAN="1"
;;
Expand Down Expand Up @@ -547,6 +551,7 @@ PREFIX=${PREFIX:-/usr/local}
BUILDDIR=${BUILDDIR:-build}
BINDIR=${BINDIR:-bin}
GATEWAY_DIR=${GATEWAY_DIR:-${PREFIX}/bin}
SERVICE_NAME=${SERVICE_NAME:-mysgw}
CC=${CC:-gcc}
CXX=${CXX:-g++}
CXXFLAGS="$CXXFLAGS -std=c++11"
Expand Down

0 comments on commit 32b270b

Please sign in to comment.