MT#16391 Don't hardcode tt2-daemon's port file

For testing without root permissions we need a different path
than /var/run/ngcpcfg.port.

Change-Id: I268d5c61a8caa0f7fe737813c02cafa92db79a35
changes/14/13414/5
Michael Prokop 8 years ago
parent e06c458e22
commit d62433cf93

@ -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 {

@ -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

@ -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"

@ -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"

Loading…
Cancel
Save