diff --git a/helper/tt2-daemon b/helper/tt2-daemon index 25bc9019..d2e975c1 100755 --- a/helper/tt2-daemon +++ b/helper/tt2-daemon @@ -45,11 +45,14 @@ sub get_server_port { binmode $server => ":encoding(utf8)"; - open (my $PORTFILE, '>', '/var/run/ngcpcfg.port'); - print $PORTFILE $server->sockport(); - close ($PORTFILE); - - return $server; + my $NGCP_PORTFILE = $ENV{'NGCP_PORTFILE'} //= '/var/run/ngcpcfg.port'; + if (open (my $portfile, '>', "$NGCP_PORTFILE")) { + print $portfile $server->sockport(); + close ($portfile); + return $server; + } else { + die "Can't write to $NGCP_PORTFILE\n"; + } } sub handle_connections { diff --git a/helper/tt2-wrapper b/helper/tt2-wrapper index 28a78d50..578b2d1f 100755 --- a/helper/tt2-wrapper +++ b/helper/tt2-wrapper @@ -1,9 +1,9 @@ #!/bin/bash -if [ -r /var/run/ngcpcfg.port ] ; then - port=$(cat /var/run/ngcpcfg.port) +if [ -r "${NGCP_PORTFILE:-/var/run/ngcpcfg.port}" ] ; then + port=$(cat "${NGCP_PORTFILE}") else - echo "ERROR: Couldn't read file /var/run/ngcpcfg.port" >&2 + echo "ERROR: Couldn't read file ${NGCP_PORTFILE}" >&2 exit 1 fi diff --git a/scripts/build b/scripts/build index 54008c63..9fe7aa00 100755 --- a/scripts/build +++ b/scripts/build @@ -38,7 +38,14 @@ fi # Kill all previous started tt2-daemon Perl processes if they were not stopped properly killall tt2-daemon 2>/dev/null || true -rm -f /var/run/ngcpcfg.port + +if [ -n "${NGCP_PORTFILE:-}" ] ; then + log_debug "Using $NGCP_PORTFILE as tt2-daemon port file as set via 'NGCP_PORTFILE'." +else + NGCP_PORTFILE='/var/run/ngcpcfg.port' +fi + +rm -f "${NGCP_PORTFILE}" # Start new tt2-daemon Perl process "${HELPER}"/tt2-daemon @@ -142,7 +149,7 @@ fi # Kill all previous started tt2-daemon Perl processes killall tt2-daemon 2>/dev/null || true -rm -f /var/run/ngcpcfg.port +rm -f "${NGCP_PORTFILE}" exit "$RC" diff --git a/scripts/values b/scripts/values index bb8721a8..9e9d7ef0 100755 --- a/scripts/values +++ b/scripts/values @@ -42,7 +42,13 @@ TT_WRAPPER="${HELPER}/tt2-wrapper" # Kill all previous started tt2-daemon Perl processes if they were not stopped properly killall tt2-daemon 2>/dev/null || true -rm -f /var/run/ngcpcfg.port + +if [ -n "${NGCP_PORTFILE:-}" ] ; then + log_debug "Using $NGCP_PORTFILE as tt2-daemon port file as set via 'NGCP_PORTFILE'." +else + NGCP_PORTFILE='/var/run/ngcpcfg.port' +fi +rm -f "${NGCP_PORTFILE}" # Start new tt2-daemon Perl process "${HELPER}"/tt2-daemon --quiet @@ -71,7 +77,7 @@ fi # Kill all previous started tt2-daemon Perl processes killall tt2-daemon 2>/dev/null || true -rm -f /var/run/ngcpcfg.port +rm -f "${NGCP_PORTFILE}" exit "$RC"