lsof is not needed anymore

This commit is contained in:
Trevor Johnston 2018-12-14 11:34:03 -05:00
parent e9e705b763
commit 49fe1e02c4
3 changed files with 2 additions and 49 deletions

View file

@ -25,8 +25,8 @@ LABEL shadowbox.outline-ss-server_version="${SS_VERSION}"
ARG GITHUB_RELEASE
LABEL shadowbox.github.release="${GITHUB_RELEASE}"
# lsof for Shadowbox, curl for detecting our public IP.
RUN apk add --no-cache lsof curl
# We use curl to detect the server's public IP.
RUN apk add --no-cache curl
COPY src/shadowbox/scripts scripts/
COPY src/shadowbox/scripts/update_mmdb.sh /etc/periodic/weekly/update_mmdb

View file

@ -60,19 +60,3 @@ function listen(): Promise<net.Server> {
});
});
}
describe('getUsedPorts', () => {
it('returns used port', async () => {
const server = await listen();
const serverPort = server.address().port;
const usedPorts = await get_port.getUsedPorts();
expect(usedPorts).toContain(serverPort);
const onceClosed = new Promise((resolve, reject) => {
server.on('close', () => resolve());
});
server.close();
await onceClosed;
expect(await get_port.getUsedPorts()).not.toContain(serverPort);
});
});

View file

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import * as child_process from 'child_process';
import * as net from 'net';
const MAX_PORT = 65535;
@ -66,36 +65,6 @@ function getRandomPortOver1023() {
return Math.floor(Math.random() * (MAX_PORT + 1 - MIN_PORT) + MIN_PORT);
}
// Returns the list of ports used by either TCP or UDP.
export function getUsedPorts(): Promise<Set<number>> {
return new Promise((resolve, reject) => {
child_process.exec('lsof -P -i -F n', (error, stdout, stderr) => {
const tcpPorts = new Set<number>();
if (error) {
if (error.code === 1) {
// Empty list case
return resolve(tcpPorts);
}
return reject(error);
}
for (const line of stdout.split(/\r?\n/)) {
if (line.length === 0 || line[0] !== 'n') {
continue;
}
const parts = line.split(':');
if (parts.length !== 2) {
continue;
}
const port = parseInt(parts[1], 10);
if (port) {
tcpPorts.add(port);
}
}
resolve(tcpPorts);
});
});
}
interface ServerError extends Error {
code: string;
}