Skip to content

Commit 32b270b

Browse files
committed
Initial work for supporting multiple instances
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
1 parent 8103c6c commit 32b270b

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

Makefile

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ include $(CONFIG_FILE)
1818
CPPFLAGS+=-Ofast -g -Wall -Wextra
1919
DEPFLAGS=-MT $@ -MMD -MP
2020

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

125125
install-initscripts:
126126
ifeq ($(INIT_SYSTEM), systemd)
127-
install -m0644 initscripts/mysgw.systemd ${DESTDIR}/etc/systemd/system/mysgw.service
128-
@sed -i -e "s|%gateway_dir%|${GATEWAY_DIR}|g" ${DESTDIR}/etc/systemd/system/mysgw.service
127+
install -m0644 initscripts/mysgw.systemd ${DESTDIR}/etc/systemd/system/${SERVICE_NAME}.service
128+
@sed -i -e "s|%gateway_dir%|${GATEWAY_DIR}|g" ${DESTDIR}/etc/systemd/system/${SERVICE_NAME}.service
129+
@sed -i -e "s|%mysgw%|${SERVICE_NAME}|g" ${DESTDIR}/etc/systemd/system/${SERVICE_NAME}.service
129130
systemctl daemon-reload
130131
@echo "MySensors gateway has been installed, to add to the boot run:"
131-
@echo " sudo systemctl enable mysgw.service"
132+
@echo " sudo systemctl enable ${SERVICE_NAME}.service"
132133
@echo "To start the gateway run:"
133-
@echo " sudo systemctl start mysgw.service"
134+
@echo " sudo systemctl start ${SERVICE_NAME}.service"
134135
else ifeq ($(INIT_SYSTEM), sysvinit)
135-
install -m0755 initscripts/mysgw.sysvinit ${DESTDIR}/etc/init.d/mysgw
136-
@sed -i -e "s|%gateway_dir%|${GATEWAY_DIR}|g" ${DESTDIR}/etc/init.d/mysgw
136+
install -m0755 initscripts/mysgw.sysvinit ${DESTDIR}/etc/init.d/${SERVICE_NAME}
137+
@sed -i -e "s|%gateway_dir%|${GATEWAY_DIR}|g" ${DESTDIR}/etc/init.d/${SERVICE_NAME}
138+
@sed -i -e "s|%mysgw%|${SERVICE_NAME}|g" ${DESTDIR}/etc/init.d/${SERVICE_NAME}
137139
@echo "MySensors gateway has been installed, to add to the boot run:"
138-
@echo " sudo update-rc.d mysgw defaults"
140+
@echo " sudo update-rc.d ${SERVICE_NAME} defaults"
139141
@echo "To start the gateway run:"
140-
@echo " sudo service mysgw start"
142+
@echo " sudo service ${SERVICE_NAME} start"
141143
endif
142144

143145
uninstall:
144146
ifeq ($(INIT_SYSTEM), systemd)
145-
@echo "Stopping daemon mysgw (ignore errors)"
146-
-@systemctl stop mysgw.service
147+
@echo "Stopping daemon ${SERVICE_NAME} (ignore errors)"
148+
-@systemctl stop ${SERVICE_NAME}.service
147149
@echo "removing files"
148-
rm /etc/systemd/system/mysgw.service $(GATEWAY_DIR)/$(GATEWAY_BIN)
150+
rm /etc/systemd/system/${SERVICE_NAME}.service $(GATEWAY_DIR)/$(GATEWAY_BIN)
149151
else ifeq ($(INIT_SYSTEM), sysvinit)
150-
@echo "Stopping daemon mysgw (ignore errors)"
151-
-@service mysgw stop
152+
@echo "Stopping daemon ${SERVICE_NAME} (ignore errors)"
153+
-@service ${SERVICE_NAME} stop
152154
@echo "removing files"
153-
rm /etc/init.d/mysgw $(GATEWAY_DIR)/$(GATEWAY_BIN)
155+
rm /etc/init.d/${SERVICE_NAME} $(GATEWAY_DIR)/$(GATEWAY_BIN)
154156
endif

configure

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Original work: https://github.com/TMRh20/RF24/blob/master/configure
55

66
function help {
7-
cat <<EOF
7+
cat <<EOF
88
configure script for MySensors gateway.
99
Options:
1010
@@ -34,6 +34,7 @@ Building options:
3434
Installation options:
3535
--prefix=<PREFIX> Installation prefix path. [/usr/local]
3636
--gateway-dir=<DIR> Gateway files installation directory. [PREFIX/bin]
37+
--service-name=<NAME> Name for the binary and systemd service. [mysgw]
3738
3839
MySensors options:
3940
--my-debug=[enable|disable] Enables or disables MySensors core debugging. [enable]
@@ -297,7 +298,7 @@ signing=none
297298
signing_request_signatures=false
298299
encryption=false
299300

300-
params="SOC CFLAGS CXXFLAGS CPPFLAGS LDFLAGS PREFIX CC CXX ARDUINO_LIB_DIR BUILDDIR BINDIR GATEWAY_DIR INIT_SYSTEM SPI_DRIVER"
301+
params="SOC CFLAGS CXXFLAGS CPPFLAGS LDFLAGS PREFIX CC CXX ARDUINO_LIB_DIR BUILDDIR BINDIR GATEWAY_DIR INIT_SYSTEM SPI_DRIVER SERVICE_NAME"
301302

302303
for opt do
303304
if [ "$opt" = "-h" ] || [ "$opt" = "--help" ]; then
@@ -345,6 +346,9 @@ for opt do
345346
--bin-dir=*)
346347
BINDIR="$optarg"
347348
;;
349+
--service-name=*)
350+
SERVICE_NAME="$optarg"
351+
;;
348352
--no-clean*)
349353
NO_CLEAN="1"
350354
;;
@@ -547,6 +551,7 @@ PREFIX=${PREFIX:-/usr/local}
547551
BUILDDIR=${BUILDDIR:-build}
548552
BINDIR=${BINDIR:-bin}
549553
GATEWAY_DIR=${GATEWAY_DIR:-${PREFIX}/bin}
554+
SERVICE_NAME=${SERVICE_NAME:-mysgw}
550555
CC=${CC:-gcc}
551556
CXX=${CXX:-g++}
552557
CXXFLAGS="$CXXFLAGS -std=c++11"

0 commit comments

Comments
 (0)