fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/40756?usp=email )
Change subject: Makefile: generate and install complete release package ......................................................................
Makefile: generate and install complete release package
Previously, our Debian packages installed osmo-s1gw as an escript executable - essentially a self-unpacking zip archive containing *.app and *.beam files, similar to a Java JAR. This was generated using `rebar3 escriptize` and worked well for some time.
However, at some point we started hitting bugs and limitations with this approach, prompting a change to packaging osmo-s1gw as a standard OTP-style BEAM application. This patch resolves those issues and aligns better with typical Erlang deployment practices.
The default rebar3-generated start script daemonizes (double‑forks) and wraps erlexec in complex shell logic that does not play well with systemd (e.g. erl_child_setup failures). Thus we provide a custom script that calls erlexec directly, avoids double‑forking, and adds some user-friendly command line options.
The resulting package no longer depends on `erlang-nox` since it includes the ERTS (Erlang Runtime System). This ensures consistent behavior across different environments and simplifies deployment.
Change-Id: I5681ca103daf1c497218b4513b0ca97b1aae03d3 Related: SYS#7332 --- M Makefile A contrib/osmo-s1gw.sh M contrib/systemd/osmo-s1gw.service M debian/control 4 files changed, 80 insertions(+), 7 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw refs/changes/56/40756/1
diff --git a/Makefile b/Makefile index ad7b531..fd9d1ae 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ EUNIT_ARGS ?= # directory paths for 'install' BINDIR ?= /usr/bin +LIBDIR ?= /usr/lib CONFDIR ?= /etc/osmocom SYSTEMDUNITDIR ?= /lib/systemd/system
@@ -30,8 +31,13 @@ analyze: $(GEN_FILES) rebar3 dialyzer
-install: build - install -Dm0755 _build/default/bin/osmo-s1gw \ +release: $(GEN_FILES) + rebar3 release + +install: release + install -d $(DESTDIR)$(LIBDIR) + cp -r _build/default/rel/osmo-s1gw $(DESTDIR)$(LIBDIR)/ + install -Dm0755 contrib/osmo-s1gw.sh \ $(DESTDIR)$(BINDIR)/osmo-s1gw install -Dm0644 config/sys.config \ $(DESTDIR)$(CONFDIR)/osmo-s1gw.config diff --git a/contrib/osmo-s1gw.sh b/contrib/osmo-s1gw.sh new file mode 100755 index 0000000..3db44b6 --- /dev/null +++ b/contrib/osmo-s1gw.sh @@ -0,0 +1,67 @@ +#!/bin/sh -e + +# Simple boot script for Erlang/OTP releases that be used in systemd unit files. + +APP_NAME=osmo-s1gw + +# --- Parse options --- +ROOTDIR=${ROOTDIR:-"/usr/lib/${APP_NAME}"} +CONFIG="/etc/osmocom/${APP_NAME}.config" +COOKIE="${APP_NAME}" +NODE_NAME="${APP_NAME}@$(uname -n)" +ERL_SHELL="-noshell -noinput" + +while getopts "c:C:n:r:s" opt; do + case "$opt" in + c) + CONFIG="$OPTARG" + ;; + C) + COOKIE="$OPTARG" + ;; + n) + NODE_NAME="$OPTARG" + ;; + r) + ROOTDIR=$(realpath "$OPTARG") + ;; + s) + ERL_SHELL="-shell" + ;; + *) + echo "Usage: $0 [-s] [-r ROOTDIR] [-c CONFIG] [-C COOKIE] [-n NAME@HOST]" + exit 1 + ;; + esac +done + +if [ ! -d "${ROOTDIR}" ]; then + echo "Error: ROOTDIR=${ROOTDIR} does not exist" + echo "Please specify the root directory using '-r' or via the environment" + exit 1 +fi + +if [ -z "${ERTS_DIR}" ]; then + ERTS_VSN=$(grep "^ERTS_VSN=" ${ROOTDIR}/bin/${APP_NAME} | cut -d'"' -f2) + ERTS_DIR=${ERTS_DIR:-"${ROOTDIR}/erts-${ERTS_VSN}"} +fi + +if [ -z "${REL_DIR}" ]; then + REL_VSN=$(grep "^REL_VSN=" ${ROOTDIR}/bin/${APP_NAME} | cut -d'"' -f2) + REL_DIR="${ROOTDIR}/releases/${REL_VSN}" +fi + +[ -f "${REL_DIR}/${APP_NAME}.boot" ] && BOOTFILE="${APP_NAME}" || BOOTFILE=start + +export BINDIR="${ERTS_DIR}/bin" + +exec ${BINDIR}/erlexec \ + +C multi_time_warp \ + -boot "${REL_DIR}/${BOOTFILE}" \ + -config "${CONFIG}" \ + -setcookie "${COOKIE}" \ + -sname "${NODE_NAME}" \ + -mode embedded \ + ${ERL_SHELL} + +# vim:set ts=2 sw=2 et: diff --git a/contrib/systemd/osmo-s1gw.service b/contrib/systemd/osmo-s1gw.service index a265964..707bdae 100644 --- a/contrib/systemd/osmo-s1gw.service +++ b/contrib/systemd/osmo-s1gw.service @@ -5,14 +5,13 @@
[Service] Type=simple -Restart=always +Restart=on-failure StateDirectory=osmo-s1gw WorkingDirectory=%S/osmo-s1gw User=osmocom Group=osmocom Environment="HOME=/var/lib/osmo-s1gw" -Environment="ERL_FLAGS=-config /etc/osmocom/osmo-s1gw.config" -ExecStart=/usr/bin/osmo-s1gw foreground +ExecStart=/usr/bin/osmo-s1gw -c /etc/osmocom/osmo-s1gw.config CapabilityBoundingSet=CAP_NET_ADMIN AmbientCapabilities=CAP_NET_ADMIN RestartSec=2 diff --git a/debian/control b/debian/control index 10eddac..8240677 100644 --- a/debian/control +++ b/debian/control @@ -10,8 +10,9 @@
Package: osmo-s1gw Architecture: any -Depends: erlang-nox -Multi-Arch: allowed +Depends: ${shlibs:Depends}, + ${misc:Depends} +Multi-Arch: foreign Description: Osmocom S1 gateway This can be used on the S1 interface between eNB and MME/CN, and acts as separation between the eNB-facing IP network and the