Make it install as systemd service

master
Geoffrey Merck 4 years ago
parent adc2fc7ac9
commit 4171cc0bee

@ -1,37 +1,37 @@
.PHONY: install .PHONY: install
install: install:
install -d -g bin -o root -m 0775 $(DATADIR) @install -d -g bin -o dstar -m 0775 $(DATA_DIR)
install -g bin -o root -m 0664 CCS_Hosts.txt $(DATADIR) @install -g bin -o dstar -m 0664 CCS_Hosts.txt $(DATA_DIR)
install -g bin -o root -m 0664 DCS_Hosts.txt $(DATADIR) @install -g bin -o dstar -m 0664 DCS_Hosts.txt $(DATA_DIR)
install -g bin -o root -m 0664 DExtra_Hosts.txt $(DATADIR) @install -g bin -o dstar -m 0664 DExtra_Hosts.txt $(DATA_DIR)
install -g bin -o root -m 0664 DPlus_Hosts.txt $(DATADIR) @install -g bin -o dstar -m 0664 DPlus_Hosts.txt $(DATA_DIR)
install -g bin -o root -m 0664 TIME_de_DE.ambe $(DATADIR) @install -g bin -o dstar -m 0664 TIME_de_DE.ambe $(DATA_DIR)
install -g bin -o root -m 0664 TIME_de_DE.indx $(DATADIR) @install -g bin -o dstar -m 0664 TIME_de_DE.indx $(DATA_DIR)
install -g bin -o root -m 0664 TIME_en_GB.ambe $(DATADIR) @install -g bin -o dstar -m 0664 TIME_en_GB.ambe $(DATA_DIR)
install -g bin -o root -m 0664 TIME_en_GB.indx $(DATADIR) @install -g bin -o dstar -m 0664 TIME_en_GB.indx $(DATA_DIR)
install -g bin -o root -m 0664 TIME_en_US.ambe $(DATADIR) @install -g bin -o dstar -m 0664 TIME_en_US.ambe $(DATA_DIR)
install -g bin -o root -m 0664 TIME_en_US.indx $(DATADIR) @install -g bin -o dstar -m 0664 TIME_en_US.indx $(DATA_DIR)
install -g bin -o root -m 0664 TIME_fr_FR.ambe $(DATADIR) @install -g bin -o dstar -m 0664 TIME_fr_FR.ambe $(DATA_DIR)
install -g bin -o root -m 0664 TIME_fr_FR.indx $(DATADIR) @install -g bin -o dstar -m 0664 TIME_fr_FR.indx $(DATA_DIR)
install -g bin -o root -m 0664 TIME_se_SE.ambe $(DATADIR) @install -g bin -o dstar -m 0664 TIME_se_SE.ambe $(DATA_DIR)
install -g bin -o root -m 0664 TIME_se_SE.indx $(DATADIR) @install -g bin -o dstar -m 0664 TIME_se_SE.indx $(DATA_DIR)
install -g bin -o root -m 0664 de_DE.ambe $(DATADIR) @install -g bin -o dstar -m 0664 de_DE.ambe $(DATA_DIR)
install -g bin -o root -m 0664 de_DE.indx $(DATADIR) @install -g bin -o dstar -m 0664 de_DE.indx $(DATA_DIR)
install -g bin -o root -m 0664 dk_DK.ambe $(DATADIR) @install -g bin -o dstar -m 0664 dk_DK.ambe $(DATA_DIR)
install -g bin -o root -m 0664 dk_DK.indx $(DATADIR) @install -g bin -o dstar -m 0664 dk_DK.indx $(DATA_DIR)
install -g bin -o root -m 0664 en_GB.ambe $(DATADIR) @install -g bin -o dstar -m 0664 en_GB.ambe $(DATA_DIR)
install -g bin -o root -m 0664 en_GB.indx $(DATADIR) @install -g bin -o dstar -m 0664 en_GB.indx $(DATA_DIR)
install -g bin -o root -m 0664 en_US.ambe $(DATADIR) @install -g bin -o dstar -m 0664 en_US.ambe $(DATA_DIR)
install -g bin -o root -m 0664 en_US.indx $(DATADIR) @install -g bin -o dstar -m 0664 en_US.indx $(DATA_DIR)
install -g bin -o root -m 0664 es_ES.ambe $(DATADIR) @install -g bin -o dstar -m 0664 es_ES.ambe $(DATA_DIR)
install -g bin -o root -m 0664 es_ES.indx $(DATADIR) @install -g bin -o dstar -m 0664 es_ES.indx $(DATA_DIR)
install -g bin -o root -m 0664 fr_FR.ambe $(DATADIR) @install -g bin -o dstar -m 0664 fr_FR.ambe $(DATA_DIR)
install -g bin -o root -m 0664 fr_FR.indx $(DATADIR) @install -g bin -o dstar -m 0664 fr_FR.indx $(DATA_DIR)
install -g bin -o root -m 0664 it_IT.ambe $(DATADIR) @install -g bin -o dstar -m 0664 it_IT.ambe $(DATA_DIR)
install -g bin -o root -m 0664 it_IT.indx $(DATADIR) @install -g bin -o dstar -m 0664 it_IT.indx $(DATA_DIR)
install -g bin -o root -m 0664 no_NO.ambe $(DATADIR) @install -g bin -o dstar -m 0664 no_NO.ambe $(DATA_DIR)
install -g bin -o root -m 0664 no_NO.indx $(DATADIR) @install -g bin -o dstar -m 0664 no_NO.indx $(DATA_DIR)
install -g bin -o root -m 0664 pl_PL.ambe $(DATADIR) @install -g bin -o dstar -m 0664 pl_PL.ambe $(DATA_DIR)
install -g bin -o root -m 0664 pl_PL.indx $(DATADIR) @install -g bin -o dstar -m 0664 pl_PL.indx $(DATA_DIR)
install -g bin -o root -m 0664 se_SE.ambe $(DATADIR) @install -g bin -o dstar -m 0664 se_SE.ambe $(DATA_DIR)
install -g bin -o root -m 0664 se_SE.indx $(DATADIR) @install -g bin -o dstar -m 0664 se_SE.indx $(DATA_DIR)

@ -1,13 +1,30 @@
# Copyright (c) 2021 by Geoffrey Merck F4FXL / KC3FRA #
# Copyright (C) 2021 by Geoffrey Merck F4FXL / KC3FRA
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# if you change these locations, make sure the dstargateway.service file is updated! export BIN_DIR=/usr/local/bin
BIN_DIR=/usr/local/bin export CFG_DIR=/usr/local/etc/
CFG_DIR=/usr/local/etc/dstargateway.d/ export DATA_DIR=/usr/local/share/dstargateway.d/
export LOG_DIR=/var/log/dstargateway
# choose this if you want debugging help # choose this if you want debugging help
CPPFLAGS=-g -ggdb -W -Wall -std=c++17 -DCFG_DIR=\"$(CFG_DIR)\" CPPFLAGS=-g -ggdb -W -Wall -std=c++17
# or, you can choose this for a much smaller executable without debugging help # or, you can choose this for a much smaller executable without debugging help
#CPPFLAGS=-W -Wall -std=c++17 -DCFG_DIR=\"$(CFGDIR)\" -DDATA_DIR=\"$(DATA_DIR)" #CPPFLAGS=-W -Wall -std=c++17
SRCS = $(wildcard *.cpp) SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o) OBJS = $(SRCS:.cpp=.o)
@ -22,6 +39,20 @@ dstargateway : GitVersion.h $(OBJS)
%.o : %.cpp %.o : %.cpp
g++ $(CPPFLAGS) -MMD -MD -c $< -o $@ g++ $(CPPFLAGS) -MMD -MD -c $< -o $@
GitVersion.h : FORCE
ifneq ("$(wildcard .git/index)","")
@echo "#pragma once\nconst char *gitversion = \"$(shell git rev-parse HEAD)\";" > /tmp/$@
else
@echo "#pragma once\nconst char *gitversion = \"0000000000000000000000000000000000000000\";" > /tmp/$@
endif
@cmp -s /tmp/$@ $@; \
RETVAL=$$?; \
if [ $$RETVAL -ne 0 ]; then \
echo "Git version has changed"; \
cp -f /tmp/$@ $@; \
fi; \
rm /tmp/$@;
.PHONY: clean .PHONY: clean
clean: clean:
$(RM) GitVersion.h $(OBJS) $(DEPS) dstargateway $(RM) GitVersion.h $(OBJS) $(DEPS) dstargateway
@ -29,42 +60,64 @@ clean:
-include $(DEPS) -include $(DEPS)
# install, uninstall and removehostfiles need root priviledges # install, uninstall and removehostfiles need root priviledges
.PHONY: newhostfiles
newhostfiles : newhostfiles :
/usr/bin/wget http://www.pistar.uk/downloads/DExtra_Hosts.txt && sudo /bin/mv -f DExtra_Hosts.txt $(CFGDIR) @echo "Fetching new host files"
/usr/bin/wget http://www.pistar.uk/downloads/DCS_Hosts.txt && sudo /bin/mv -f DCS_Hosts.txt $(CFGDIR) @mkdir -p $(DATA_DIR)
@wget http://www.pistar.uk/downloads/DExtra_Hosts.txt -nv -O $(DATA_DIR)/DExtra_Hosts.txt
@wget http://www.pistar.uk/downloads/DCS_Hosts.txt -nv -O $(DATA_DIR)/DCS_Hosts.txt
@wget http://www.pistar.uk/downloads/DPlus_Hosts.txt -nv -O $(DATA_DIR)/DPlus_Hosts.txt
.PHONY: install
install : dstargateway install : dstargateway
/bin/cp -f dstargateway.cfg $(CFGDIR) # create user for daemon
/bin/cp -f dstargateway $(BINDIR) @useradd --user-group -M --system dstar --shell /bin/false || true
/bin/cp -f dstargateway.service /lib/systemd/system
# Create directories
@mkdir -p $(CFG_DIR)
@mkdir -p $(DATA_DIR)
@mkdir -p $(BIN_DIR)
@mkdir -p $(LOG_DIR)
@chown dstar:dstar $(LOG_DIR)
# Install data
$(MAKE) -C Data install
@chown -R dstar:dstar $(DATA_DIR)
# copy and adjust config
@cp -fn example.cfg $(CFG_DIR)/dstargateway.cfg
@sed -i "s|log=.*|log=\"$(LOG_DIR)\"|g" $(CFG_DIR)/dstargateway.cfg
@sed -i "s|data=.*|data=\"$(DATA_DIR)\"|g" $(CFG_DIR)/dstargateway.cfg
# copy binary
@cp -f dstargateway $(BIN_DIR)
# SystemD service install
@cp -f debian/dstargateway.service /lib/systemd/system/
@sed -i "s|%CFG_DIR%|$(CFG_DIR)|g" /lib/systemd/system/dstargateway.service
systemctl enable dstargateway.service systemctl enable dstargateway.service
systemctl daemon-reload @systemctl daemon-reload
systemctl start dstargateway.service @echo "\n\n"
@echo "Install complete, edit $(CFG_DIR)dstargateway.cfg and start the daemon with 'systemctl start dstargateway.service'"
@echo "\n\n"
.PHONY: uninstall
uninstall : uninstall :
systemctl stop dstargateway.service systemctl stop dstargateway.service || true
systemctl disable dstargateway.service systemctl disable dstargateway.service || true
/bin/rm -f /lib/systemd/system/dstargateway.service @rm -f /lib/systemd/system/dstargateway.service
systemctl daemon-reload @systemctl daemon-reload
/bin/rm -f $(BINDIR)/dstargateway @rm -f $(BIN_DIR)/dstargateway
/bin/rm -f $(CFGDIR)/dstargateway.cfg # @rm -f $(CFG_DIR)/dstargateway.cfg
# Only remove folder content
@rm -f $(DATA_DIR)/*
.PHONY: removehostfiles
removehostfiles : removehostfiles :
/bin/rm -f $(CFGDIR)/DExtra_Hosts.txt @rm -f $(DATA_DIR)/DExtra_Hosts.txt
/bin/rm -f $(CFGDIR)/DCS_Hosts.txt @rm -f $(DATA_DIR)/DCS_Hosts.txt
@rm -f $(DATA_DIR)/DPlus_Hosts.txt
GitVersion.h : FORCE
ifneq ("$(wildcard .git/index)","")
@echo "#pragma once\nconst char *gitversion = \"$(shell git rev-parse HEAD)\";" > /tmp/$@
else
@echo "#pragma once\nconst char *gitversion = \"0000000000000000000000000000000000000000\";" > /tmp/$@
endif
@cmp -s /tmp/$@ $@; \
RETVAL=$$?; \
if [ $$RETVAL -ne 0 ]; then \
echo "Git version has changed"; \
cp -f /tmp/$@ $@; \
fi; \
rm /tmp/$@;
FORCE: FORCE:

@ -1,10 +1,17 @@
[Unit] [Unit]
Description=DStar Gateway User=dstar
After=systemd-user-session.service Description=D-STAR Gateway Daemon
After=network.target,network-online.target
Wants=network-online.target
RestartSec=5
StartLimitIntervalSec=60
StartLimitBurst=0
[Service] [Service]
Type=simple Type=simple
ExecStart=/usr/local/bin/dstargateway /usr/local/etc/dstargeteway/dstargateway.cfg ExecStart=/usr/local/bin/dstargateway %CFG_DIR%/dstargateway.cfg
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
Requires=network-online.target

Loading…
Cancel
Save

Powered by TurnKey Linux.