Skip to content

Commit 5df90da

Browse files
committed
Rework sys port validation using lsof.
1 parent d9f6cb1 commit 5df90da

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

bin/v-change-sys-port

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,22 @@ PORT=$1
1616
source $HESTIA/func/main.sh
1717
source $HESTIA/conf/hestia.conf
1818

19-
# Define not usable ports
20-
BUSY_PORTS=('80' '443' '8080' '8443')
21-
19+
# Functions
2220
is_port_valid() {
23-
2421
# Check if PORT is numeric
2522
if [[ ! $PORT =~ ^[0-9]+$ ]]; then
26-
echo 'Port should contains a numeric value only!'
27-
log_event $E_NOTEXIST "$ARGUMENTS"
28-
exit $E_NOTEXIST
23+
echo "Port should contains a numeric value only!"
24+
log_event $E_INVALID "$ARGUMENTS"
25+
exit $E_INVALID
2926
fi
3027

3128
# Check if PORT is already used
32-
for BUSY_PORT in ${BUSY_PORTS[@]}; do
33-
if [ "$BUSY_PORT" = "$PORT" ]; then
34-
echo 'Port is already used by Hestia, please set anotherone!'
35-
log_event $E_NOTEXIST "$ARGUMENTS"
36-
exit $E_NOTEXIST
37-
fi
38-
done
29+
BUSY_PORT=$(lsof -i:$PORT)
30+
if [ ! -z "$BUSY_PORT" ]; then
31+
echo "Port is already used by Hestia, please set anotherone!"
32+
log_event $E_INUSE "$ARGUMENTS"
33+
exit $E_INUSE
34+
fi
3935
}
4036

4137

0 commit comments

Comments
 (0)