Skip to content

Commit 31c741f

Browse files
committed
Revert apply_server_settings.pl changes on server shutdown to avoid bugs
1 parent 50b5b56 commit 31c741f

File tree

1 file changed

+78
-29
lines changed
  • Installers/Server/Linux/DEB/ermis-server-installer_all/opt/ermis-server

1 file changed

+78
-29
lines changed

Installers/Server/Linux/DEB/ermis-server-installer_all/opt/ermis-server/ermis-server.sh

100644100755
Lines changed: 78 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,81 @@
1515
# You should have received a copy of the GNU Affero General Public License
1616
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1717

18-
sudo ./apply_server_settings.pl
19-
20-
# Attempt to find server JAR file
21-
ERMIS_SERVER_JAR_FILE=$(find bin -maxdepth 1 -name "*.jar" -print -quit)
22-
23-
# Check if a JAR file was found
24-
if [ -z "$ERMIS_SERVER_JAR_FILE" ]; then
25-
echo "No JAR file found in the directory!"
26-
exit 1
27-
fi
28-
29-
VM_ARGUMENTS="
30-
-Djava.security.egd=file:/dev/./urandom
31-
-server
32-
-XX:+UseZGC
33-
--add-opens java.base/java.lang=ALL-UNNAMED
34-
--add-opens java.base/jdk.internal.misc=ALL-UNNAMED
35-
--add-opens java.base/java.nio=ALL-UNNAMED
36-
-Dio.netty.tryReflectionSetAccessible=true
37-
-Dfile.encoding=UTF-8"
38-
PROGRAM_ARGUMENTS=""
39-
40-
if [ -n "$JAVA_HOME" ]; then
41-
sudo $JAVA_HOME/bin/java -jar $VM_ARGUMENTS $ERMIS_SERVER_JAR_FILE $PROGRAM_ARGUMENTS
42-
else
43-
sudo java -jar $VM_ARGUMENTS $ERMIS_SERVER_JAR_FILE $PROGRAM_ARGUMENTS
44-
fi
45-
46-
sudo turnserver --log-file stdout --tls-listening-port=5439 --listening-port=5440
18+
debute_server () {
19+
sudo ./apply_server_settings.pl
20+
21+
# Attempt to find server JAR file
22+
ERMIS_SERVER_JAR_FILE=$(find bin -maxdepth 1 -name "*.jar" -print -quit)
23+
24+
# Check if a JAR file was found
25+
if [ -z "$ERMIS_SERVER_JAR_FILE" ]; then
26+
echo "No JAR file found in the directory!"
27+
exit 1
28+
fi
29+
30+
VM_ARGUMENTS="
31+
-Djava.security.egd=file:/dev/./urandom
32+
-server
33+
-XX:+UseZGC
34+
--add-opens java.base/java.lang=ALL-UNNAMED
35+
--add-opens java.base/jdk.internal.misc=ALL-UNNAMED
36+
--add-opens java.base/java.nio=ALL-UNNAMED
37+
-Dio.netty.tryReflectionSetAccessible=true
38+
-Dfile.encoding=UTF-8"
39+
PROGRAM_ARGUMENTS=""
40+
41+
if [ -n "$JAVA_HOME" ]; then
42+
sudo $JAVA_HOME/bin/java -jar $VM_ARGUMENTS $ERMIS_SERVER_JAR_FILE $PROGRAM_ARGUMENTS
43+
else
44+
sudo java -jar $VM_ARGUMENTS $ERMIS_SERVER_JAR_FILE $PROGRAM_ARGUMENTS
45+
fi
46+
47+
sudo turnserver --log-file stdout --tls-listening-port=5439 --listening-port=5440
48+
}
49+
50+
create_folder_backup_and_restore_once_process_dies () {
51+
touch /tmp/session.keepalive # File denoting process is active
52+
53+
kill_file_denoting_process_is_alive() {
54+
rm -f /tmp/session.keepalive # Kill file denoting process is active
55+
}
56+
57+
trap kill_file_denoting_process_is_alive EXIT
58+
# UPPERCASE IS CRUCIAL SINCE THE VARIABLES NOW ARE GLOBAL AND THE TRAP WORKS
59+
FOLDER="$1/"
60+
BACKUP="$1_backup/"
61+
62+
restore_backup() {
63+
echo "\nRestoring original folder: $BACKUP -> $FOLDER ..."
64+
sudo rm -rf "$FOLDER"
65+
sudo cp -r "$BACKUP" "$FOLDER"
66+
sudo chmod -R 777 "$FOLDER"
67+
sudo rm -rf "$BACKUP"
68+
}
69+
70+
# If backup exists then perform cleanup
71+
if [ -d "$BACKUP" ]; then
72+
restore_backup
73+
fi
74+
75+
(
76+
while [ -f /tmp/session.keepalive ]; do
77+
sleep 1
78+
done
79+
80+
echo "Parent shell died. Exiting subshell."
81+
trap restore_backup EXIT INT TERM
82+
) &
83+
84+
# Copy the original directory to a backup location
85+
sudo cp -r --no-preserve=ownership "$FOLDER" "$BACKUP"
86+
87+
echo "Created backup for server folder $FOLDER -> $BACKUP..."
88+
89+
# Folder automatically restored by subshell above
90+
}
91+
92+
create_folder_backup_and_restore_once_process_dies "/var/ermis-server/www"
93+
create_folder_backup_and_restore_once_process_dies "/etc/nginx"
94+
95+
debute_server

0 commit comments

Comments
 (0)