fixeria has submitted this change. ( 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, 98 insertions(+), 6 deletions(-) Approvals: Jenkins Builder: Verified osmith: Looks good to me, approved diff --git a/Makefile b/Makefile index 1f37da5..ec8a7d6 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ EUNIT_ARGS ?= # directory paths for 'install' BINDIR ?= /usr/bin +LIBDIR ?= /usr/lib CONFDIR ?= /etc/osmocom SYSTEMDUNITDIR ?= /lib/systemd/system @@ -32,8 +33,16 @@ analyze: $(GEN_FILES) rebar3 dialyzer -install: build - install -Dm0755 _build/default/bin/osmo-s1gw \ +release: $(GEN_FILES) + rebar3 release + +run-release: release + contrib/osmo-s1gw.sh -r $(REBAR_BASE_DIR)/default/rel/osmo-s1gw -c $(CONFIG) + +install: release + install -d $(DESTDIR)$(LIBDIR) + cp -r $(REBAR_BASE_DIR)/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..385f981 --- /dev/null +++ b/contrib/osmo-s1gw.sh @@ -0,0 +1,83 @@ +#!/bin/sh -e + +# Simple boot script for Erlang/OTP releases that can be used in systemd unit files. +# +# Copyright 2025 by sysmocom - s.f.m.c. GmbH <i...@sysmocom.de> +# Author: Vadim Yanitskiy <vyanits...@sysmocom.de> +# +# SPDX-License-Identifier: MPL-2.0 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +APP_NAME=osmo-s1gw + +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" + +# Parse command line options, if any +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 + +# Make sure that the application's root directory exists +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 + +# Determine the ERTS directory path (if not set) +if [ -z "${ERTS_DIR}" ]; then + # Parse the ERTS version from rebar3-generated bootstrap script + ERTS_VSN=$(grep "^ERTS_VSN=" ${ROOTDIR}/bin/${APP_NAME} | cut -d'"' -f2) + ERTS_DIR=${ERTS_DIR:-"${ROOTDIR}/erts-${ERTS_VSN}"} +fi + +# Determine the release directory path (if not set) +if [ -z "${REL_DIR}" ]; then + # Parse the release version from rebar3-generated bootstrap script + REL_VSN=$(grep "^REL_VSN=" ${ROOTDIR}/bin/${APP_NAME} | cut -d'"' -f2) + REL_DIR="${ROOTDIR}/releases/${REL_VSN}" +fi + +# Determine the boot script name +[ -f "${REL_DIR}/${APP_NAME}.boot" ] && BOOTFILE="${APP_NAME}" || BOOTFILE=start + +# erlexec requires BINDIR to be set +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..bd52c4d 100644 --- a/contrib/systemd/osmo-s1gw.service +++ b/contrib/systemd/osmo-s1gw.service @@ -11,8 +11,7 @@ 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 eea7e1c..f5dda19 100644 --- a/debian/control +++ b/debian/control @@ -13,8 +13,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 -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/40756?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: erlang/osmo-s1gw Gerrit-Branch: master Gerrit-Change-Id: I5681ca103daf1c497218b4513b0ca97b1aae03d3 Gerrit-Change-Number: 40756 Gerrit-PatchSet: 5 Gerrit-Owner: fixeria <vyanits...@sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanits...@sysmocom.de> Gerrit-Reviewer: osmith <osm...@sysmocom.de> Gerrit-Reviewer: pespin <pes...@sysmocom.de>