From 0cbfdce70fb1709b65dec103edd9f38481ea8e88 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 11:30:28 +0000 Subject: [PATCH] make install: install the systemd units make install now makes dmodem-login.service, dmodem-login-authd.service and dmodem-login-ldapd.service from their samples, with the paths of BINDIR and CONF_DIR, and puts them in SYSTEMD_UNIT_DIR (/etc/systemd/system). It keeps a unit that is already there and enables none. install-freepbx and install-dialup use SYSTEMD_UNIT_DIR too. docs/running.md gives the steps after make install. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRV8YPyMUdSM1QgsczH --- .gitignore | 1 + Makefile | 30 ++++++++++++++++++++----- README.md | 2 +- docs/README.md | 2 +- docs/building.md | 5 +++-- docs/running.md | 34 +++++++++++++++++++++++++++++ samples/dmodem-login.service.sample | 2 ++ 7 files changed, 66 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 28a1a56..d2f7af1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ pbx-modem # the site (brand's tools/site.sh) /.site/ /site/ +/systemd/ diff --git a/Makefile b/Makefile index b158236..0144c17 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,9 @@ # make PPPD=0 without the pppd plugin (PPPD=1: with, or fail) # make test the tests # make install into $(BINDIR), samples into $(CONF_DIR), the -# plugin into pppd's plugin directory +# units (samples/*.service.sample) into +# $(SYSTEMD_UNIT_DIR), the plugin into pppd's +# plugin directory # make install-freepbx into $(BINDIR), freepbx/'s samples into # /etc/dmodem-login and dmodem-login.service into systemd # make install-dialup the PPP callers' network (docs/dialup-network.md): @@ -23,6 +25,11 @@ CFLAGS ?= -O2 -g PPPD ?= $(shell [ -e /usr/include/pppd/pppd.h ] && echo 1 || echo 0) PPPD_VERSION ?= $(shell sed -n 's/^\#define VERSION[^"]*"\(.*\)"/\1/p' /usr/include/pppd/patchlevel.h 2>/dev/null) PPPD_PLUGIN_DIR ?= /usr/lib/pppd/$(PPPD_VERSION) +# where the install targets put systemd units; units already there are kept +SYSTEMD_UNIT_DIR ?= /etc/systemd/system +# the units of make install: -serve, the auth socket alone and the LDAP +# provider alone. make install enables none of them +UNITS := dmodem-login.service dmodem-login-authd.service dmodem-login-ldapd.service all: dmodem-login $(if $(filter 1,$(PPPD)),pppd/dmodem-login.so) @@ -35,12 +42,22 @@ pppd/dmodem-login.so: pppd/dmodem-login.c dmodem-login: FORCE $(GO) build -buildvcs=false $(TAGS) -o $@ ./cmd/dmodem-login +# a unit from its sample, with the paths of $(BINDIR) and $(CONF_DIR) +# (FORCE: made again each time, for a BINDIR or CONF_DIR given to make install) +systemd/%.service: samples/%.service.sample FORCE + @mkdir -p systemd + sed -e 's|/usr/local/bin/|$(BINDIR)/|g' -e 's|/etc/asterisk/|$(CONF_DIR)/|g' $< > $@ + test: $(GO) vet $(TAGS) ./... $(GO) test $(TAGS) ./... -install: all +install: all $(addprefix systemd/,$(UNITS)) install -D -m 755 dmodem-login $(DESTDIR)$(BINDIR)/dmodem-login + for u in $(UNITS); do \ + [ -e $(DESTDIR)$(SYSTEMD_UNIT_DIR)/$$u ] || \ + install -D -m 644 systemd/$$u $(DESTDIR)$(SYSTEMD_UNIT_DIR)/$$u || exit 1; \ + done [ -e $(DESTDIR)$(CONF_DIR)/dmodem-login.conf ] || \ install -D -m 640 samples/dmodem-login.conf.sample $(DESTDIR)$(CONF_DIR)/dmodem-login.conf [ -e $(DESTDIR)$(CONF_DIR)/dmodem-login.users ] || \ @@ -59,13 +76,14 @@ install-freepbx: all install -D -m 644 freepbx/dmodem-login.conf $(DESTDIR)$(FREEPBX_CONF_DIR)/dmodem-login.conf [ -e $(DESTDIR)$(FREEPBX_CONF_DIR)/dmodem-login.users ] || \ install -D -m 600 freepbx/dmodem-login.users $(DESTDIR)$(FREEPBX_CONF_DIR)/dmodem-login.users - [ -e $(DESTDIR)/etc/systemd/system/dmodem-login.service ] || \ - install -D -m 644 freepbx/dmodem-login.service $(DESTDIR)/etc/systemd/system/dmodem-login.service + [ -e $(DESTDIR)$(SYSTEMD_UNIT_DIR)/dmodem-login.service ] || \ + install -D -m 644 freepbx/dmodem-login.service $(DESTDIR)$(SYSTEMD_UNIT_DIR)/dmodem-login.service [ $(PPPD) != 1 ] || \ install -D -m 644 pppd/dmodem-login.so $(DESTDIR)$(PPPD_PLUGIN_DIR)/dmodem-login.so clean: rm -f dmodem-login pppd/dmodem-login.so + rm -rf systemd FORCE: .PHONY: all test install install-freepbx install-dialup clean FORCE @@ -76,8 +94,8 @@ install-dialup: install -D -m 755 dialup/dmodem-login-dialup $(DESTDIR)$(SBINDIR)/dmodem-login-dialup install -D -m 755 dialup/ip-up $(DESTDIR)/etc/ppp/ip-up.d/dmodem-login-dialup install -D -m 755 dialup/ip-down $(DESTDIR)/etc/ppp/ip-down.d/dmodem-login-dialup - install -D -m 644 dialup/dmodem-login-dialup.service $(DESTDIR)/etc/systemd/system/dmodem-login-dialup.service - install -D -m 644 dialup/dmodem-login-dns.service $(DESTDIR)/etc/systemd/system/dmodem-login-dns.service + install -D -m 644 dialup/dmodem-login-dialup.service $(DESTDIR)$(SYSTEMD_UNIT_DIR)/dmodem-login-dialup.service + install -D -m 644 dialup/dmodem-login-dns.service $(DESTDIR)$(SYSTEMD_UNIT_DIR)/dmodem-login-dns.service [ -e $(DESTDIR)$(FREEPBX_CONF_DIR)/dialup.conf ] || \ install -D -m 644 dialup/dialup.conf.sample $(DESTDIR)$(FREEPBX_CONF_DIR)/dialup.conf [ -e $(DESTDIR)$(FREEPBX_CONF_DIR)/dnsmasq.conf ] || \ diff --git a/README.md b/README.md index 922201a..b20cc69 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ You must have Go 1.22 or later. Do these steps: ``` make # with PAM when libpam's headers are there -make install # /usr/local/bin/dmodem-login and the samples +make install # /usr/local/bin/dmodem-login, the samples and the systemd units dmodem-login -config /etc/asterisk/dmodem-login.conf -check # check the configuration dmodem-login -config /etc/asterisk/dmodem-login.conf -setup # or change it on a full screen ``` diff --git a/docs/README.md b/docs/README.md index 4f13379..8e3bc1d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,7 @@ # dmodem-login documentation - [Building](building.md): Go, PAM and `make install`. -- [Running it from app_dmodem](running.md): one program for each call, one server on a unix socket, and FreePBX. +- [Running it from app_dmodem](running.md): one program for each call, one server on a unix socket, the systemd units, and FreePBX. - [Configuration](configuration.md): `dmodem-login.conf`, the connect rate, terminals, the message of the day, the menu (full screen or lines) and its items, guests and sign-up, caller ID, time limits, drop files, last callers, and the transfer of callers to a different program. - [Configuration reference](reference.md): all sections and keys, from the sample. - [The sysop's setup](setup.md): `dmodem-login -setup`, to change the configuration on a full screen, at the console or on the line. diff --git a/docs/building.md b/docs/building.md index 75584e0..e84f617 100644 --- a/docs/building.md +++ b/docs/building.md @@ -7,8 +7,9 @@ You must have Go 1.22 or later. Use these commands: make # or: go build ./cmd/dmodem-login (-tags pam for PAM) make PAM=0 # without PAM, when libpam's headers are there make test -make install # /usr/local/bin/dmodem-login, and the samples into - # /etc/asterisk (and /etc/pam.d) if there are none +make install # /usr/local/bin/dmodem-login, the samples into + # /etc/asterisk (and /etc/pam.d), and the systemd + # units into /etc/systemd/system, if there are none ``` If the headers of libpam are installed, `make` builds with PAM. The diff --git a/docs/running.md b/docs/running.md index 3091bcb..c43c3ae 100644 --- a/docs/running.md +++ b/docs/running.md @@ -150,6 +150,40 @@ when it starts. It does not replace a socket that is in use. server under systemd. systemd also makes `/run/dmodem-login`. dmodem-login records each connection in the log, with the pid and uid of its peer. +## Under systemd + +`make install` installs three units in `/etc/systemd/system`. It makes +each unit from its sample in `samples/`, with the paths of `BINDIR` and +`CONF_DIR`: + +| Unit | What it runs | +| --- | --- | +| `dmodem-login.service` | `dmodem-login -serve`, the server on the unix socket (the section above) | +| `dmodem-login-authd.service` | the auth socket alone, for the BBS (refer to [Authentication](authentication.md)) | +| `dmodem-login-ldapd.service` | the LDAP provider alone (refer to [The LDAP provider](ldap-provider.md)) | + +`make install` does not replace a unit that is already there. Thus, your +changes to a unit stay. `make install` does not enable or start a unit. +Enable only the unit that you use. `dmodem-login -serve` also answers the +auth socket and the LDAP provider. Thus, do not enable the other two +units with `dmodem-login.service`. + +Do these steps as root, after `make install`: + +``` +systemctl daemon-reload +systemctl enable --now dmodem-login # or dmodem-login-authd, or dmodem-login-ldapd +``` + +`SYSTEMD_UNIT_DIR` selects a different directory for the units, for +example `make install SYSTEMD_UNIT_DIR=/usr/local/lib/systemd/system`. +`make install-freepbx` and `make install-dialup` also use it. + +`make install-freepbx` installs its own `dmodem-login.service`, with +`/etc/dmodem-login`. It also keeps a unit that is already there. Thus, if +you ran `make install` before, remove +`/etc/systemd/system/dmodem-login.service` before `make install-freepbx`. + ## On FreePBX [freepbx/](../freepbx/README.md) is a configuration that is ready to use diff --git a/samples/dmodem-login.service.sample b/samples/dmodem-login.service.sample index a88e5a8..1aea316 100644 --- a/samples/dmodem-login.service.sample +++ b/samples/dmodem-login.service.sample @@ -3,6 +3,8 @@ # header = yes); [server] socket_group = asterisk lets Asterisk connect [Unit] Description=dmodem-login: login and menu for dial-up callers +Documentation=https://github.com/D-Modem/login/blob/main/docs/running.md +After=network.target Before=asterisk.service [Service]