forked from ant-media/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_ant-media-server.sh
executable file
·563 lines (485 loc) · 20.3 KB
/
install_ant-media-server.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
#!/bin/bash
#
# Download latest ant media server and run this script by giving the zip file
# ./install_ant-media-server.sh ant-media-server-*.zip
# If you want to save setting from previous installation add argument true
# ./install_ant-media-server.sh ant-media-server-*.zip true
# -s : install as a service or not
# -r : restore settings
# -i : ant media server zip file
AMS_BASE=/usr/local/antmedia
BACKUP_DIR="/usr/local/antmedia-backup-"$(date +"%Y-%m-%d_%H-%M-%S")
SAVE_SETTINGS=false
INSTALL_SERVICE=true
ANT_MEDIA_SERVER_ZIP_FILE=
OTHER_DISTRO=false
SERVICE_FILE=/etc/systemd/system/antmedia.service
DEFAULT_JAVA="$(readlink -f "$(which java)" 2> /dev/null | rev | cut -d "/" -f3- | rev)"
LOG_DIRECTORY="/var/log/antmedia"
TOTAL_DISK_SPACE="$(df / --total -k -m --output=avail | tail -1 | xargs)"
ARCH=`uname -m`
RED='\033[0;31m'
NC='\033[0m'
#version that is being installed. It's get filled below
VERSION=
update_script () {
SCRIPT_NAME="$0"
remote_file="$(curl -sL https://raw.githubusercontent.com/ant-media/Scripts/master/install_ant-media-server.sh | md5sum | cut -d ' ' -f 1)"
local_file="$(md5sum $0 | cut -d '' -f 1 )"
if [ "$remote_file" != "$local_file" ]; then
wget -O $0 -q https://raw.githubusercontent.com/ant-media/Scripts/master/install_ant-media-server.sh
chmod +x $0
echo "Updated the installation script. Please rerun the script."
exit 1
fi
}
usage() {
echo ""
echo "Usage:"
echo "$0 OPTIONS"
echo ""
echo "OPTIONS:"
echo " -i -> Provide Ant Media Server Zip file name. Mandatory"
echo " -r -> Restore settings flag. It can accept true or false. Optional. Default value is false"
echo " -s -> Install Ant Media Server as a service. It can accept true or false. Optional. Default value is true"
echo " -d -> Install Ant Media Server on other Linux operating systems. Default value is false"
echo " -u -> Update Ant Media Server new installation script. Default value is false"
echo " -l -> Activate the license."
echo ""
echo "Sample usage:"
echo "$0 -i name-of-the-ant-media-server-zip-file"
echo "$0 -i name-of-the-ant-media-server-zip-file -r true -s true"
echo "$0 -i name-of-the-ant-media-server-zip-file -i false"
echo "$0 -i name-of-the-ant-media-server-zip-file -d true"
echo "$0 -i name-of-the-ant-media-server-zip-file -l \"XXXX-XXXX-XXXX\" "
echo "$0 -u"
echo ""
}
SUDO="sudo"
if ! [ -x "$(command -v sudo)" ]; then
SUDO=""
fi
disk_usage(){
if [ $SAVE_SETTINGS == "true" ]; then
if [ $(($(du -sm $AMS_BASE | cut -f 1)*2)) -ge $TOTAL_DISK_SPACE ]; then
echo "Disk space is not enough."
exit 1
fi
fi
}
# Restore settings
restore_settings() {
webapps=("LiveApp" "WebRTC*" "root")
for i in ${webapps[*]}; do
while [ ! -d $AMS_BASE/webapps/$i/WEB-INF/ ]; do
sleep 1
done
if [ -d $BACKUP_DIR/webapps/$i/ ]; then
cp -p -r $BACKUP_DIR/webapps/$i/WEB-INF/red5-web.properties $AMS_BASE/webapps/$i/WEB-INF/red5-web.properties
if [ -d $BACKUP_DIR/webapps/$i/streams/ ]; then
if [ -L $BACKUP_DIR/webapps/$i/streams ]; then
ii=`echo $BACKUP_DIR/webapps/$i/streams | cut -d "/" -f 6`
ln -sf $(readlink -f $BACKUP_DIR/webapps/$i/streams) $AMS_BASE/webapps/$ii/streams
else
cp -p -r $BACKUP_DIR/webapps/$i/streams/ $AMS_BASE/webapps/$i/
fi
fi
fi
done
diff_webapps=$(diff <(ls $AMS_BASE/webapps/) <(ls $BACKUP_DIR/webapps/) | awk -F">" '{print $2}' | xargs)
if [ ! -z "$diff_webapps" ]; then
for custom_app in $diff_webapps; do
mkdir $AMS_BASE/webapps/$custom_app
unzip $AMS_BASE/StreamApp*.war -d $AMS_BASE/webapps/$custom_app
sleep 2
cp -p $BACKUP_DIR/webapps/$custom_app/WEB-INF/red5-web.properties $AMS_BASE/webapps/$custom_app/WEB-INF/red5-web.properties
if [ -d $BACKUP_DIR/webapps/$custom_app/streams/ ]; then
cp -p -r $BACKUP_DIR/webapps/$custom_app/streams/ $AMS_BASE/webapps/$custom_app/
fi
done
fi
find $BACKUP_DIR/ -type f -iname "*.db" -exec cp -p {} $AMS_BASE/ \;
#jee-container holds beans. SSL restoring and cluster restorign require coping
cp -p "$BACKUP_DIR/conf/"{red5.properties,jee-container.xml,instanceId} "$AMS_BASE/conf"
#tokenGenerator has been removed in 2.6 so remove the tokenGeneraator class from the jee-container in 2.6 and later version
TOKEN_GENERATOR_REMOVED_VERSION=2.6
if [ "$(printf '%s\n' "$TOKEN_GENERATOR_REMOVED_VERSION" "$VERSION" | sort -V | head -n1)" == "$TOKEN_GENERATOR_REMOVED_VERSION" ]; then
#remove token generator from jee-container.xml
$SUDO sed -i '/<bean[[:space:]]*id="tokenGenerator"[[:space:]]*class="io.antmedia.filter.TokenGenerator"[[:space:]]*\/>/d' $AMS_BASE/conf/jee-container.xml
$SUDO sed -i '/<property[[:space:]]*name="tokenGenerator"[[:space:]]*ref="tokenGenerator"[[:space:]]*\/>/d' $AMS_BASE/conf/jee-container.xml
fi
#SSL Restore
if [ $(grep -o -E '<!-- https start -->|<!-- https end -->' $BACKUP_DIR/conf/jee-container.xml | wc -l) == "2" ]; then
cp -p $BACKUP_DIR/conf/{chain.pem,privkey.pem,fullchain.pem,truststore.jks,keystore.jks} $AMS_BASE/conf/
fi
if [ $(grep 'nativeLogLevel=' $AMS_BASE/conf/red5.properties | wc -l) == "0" ]; then
$SUDO echo "nativeLogLevel=ERROR" >> $AMS_BASE/conf/red5.properties
fi
if [ $(grep 'http.ssl_certificate_chain_file=' $AMS_BASE/conf/red5.properties | wc -l) == "0" ]; then
$SUDO echo "http.ssl_certificate_chain_file=conf/chain.pem" >> $AMS_BASE/conf/red5.properties
fi
if [ $(grep 'SSLCertificateChainFile' $AMS_BASE/conf/jee-container.xml | wc -l) == "0" ]; then
$SUDO sed -i '/<entry key="SSLCertificateFile.*/a <entry key="SSLCertificateChainFile" value="${http.ssl_certificate_chain_file}" />' $AMS_BASE/conf/jee-container.xml
fi
# This is a fix in upgrading versions that uses Http11Nio2Protocol
# I think we can delete the following two lines after 6 months because it will become useless.
# Sep 25, 21 - mekya
if [ $(grep 'Http11AprProtocol' $AMS_BASE/conf/jee-container.xml | wc -l) != "0" ]; then
$sudo sed -i 's/org.apache.coyote.http11.Http11AprProtocol/org.apache.coyote.http11.Http11Nio2Protocol/g' $AMS_BASE/conf/jee-container.xml
fi
if [ $? -eq "0" ]; then
echo "Settings are restored."
else
echo "Settings are not restored. Please send the log of this console to [email protected]"
fi
}
#Get the linux distribution
distro () {
os_release="/etc/os-release"
if [ -f "$os_release" ]; then
. $os_release
msg="We are supporting Ubuntu 18.04, Ubuntu 20.04, Ubuntu 22.04, Ubuntu 24.04, Centos 8, Centos 9, RockyLinux 8, RockyLinux 9, AlmaLinux 8 and AlmaLinux 9"
if [ "$OTHER_DISTRO" == "true" ]; then
echo -e """\n- OpenJDK 11 (openjdk-11-jdk)\n- De-archiver (unzip)\n- Commons Daemon (jsvc)\n- Apache Portable Runtime Library (libapr1)\n- SSL Development Files (libssl-dev)\n- Video Acceleration (VA) API (libva-drm2)\n- Video Acceleration (VA) API - X11 runtime (libva-x11-2)\n- Video Decode and Presentation API Library (libvdpau-dev)\n- Crystal HD Video Decoder Library (libcrystalhd-dev)\n"""
read -p 'Are you sure that the above packages are installed? Y/N ' CUSTOM_PACKAGES
CUSTOM_PACKAGES=${CUSTOM_PACKAGES^}
if [ "$CUSTOM_PACKAGES" == "N" ]; then
echo "Interrupted by user"
exit 1
fi
read -p "Enter JVM Path (default: $DEFAULT_JAVA): " CUSTOM_JVM
if [ -z "$CUSTOM_JVM" ]; then
$SUDO apt-get update && $SUDO apt-get install coreutils
CUSTOM_JVM=$DEFAULT_JAVA
fi
elif [ "$ID" == "ubuntu" ] || [ "$ID" == "centos" ] || [ "$ID" == "rocky" ] || [ "$ID" == "almalinux" ] || [ "$ID" == "rhel" ] || [ "$ID" == "debian" ]; then
if [ "$VERSION_ID" == "18.04" ] && [ "aarch64" == $ARCH ]; then
echo -e "ARM architecture is supported on Ubuntu 20.04. For 18.04 installation, use the link below to install.\nhttps://github.com/ant-media/Ant-Media-Server/wiki/Frequently-Asked-Questions#how-can-i-install-the-ant-media-server-on-ubuntu-1804-with-arm64"
exit 1
fi
if [[ $VERSION_ID != 18.04 ]] && [[ $VERSION_ID != 20.04 ]] && [[ $VERSION_ID != 22.04 ]] && [[ $VERSION_ID != 24.04 ]] && [[ $VERSION_ID != 8* ]] && [[ $VERSION_ID != 9* ]] && [[ $VERSION_ID != 12 ]] && [[ $VERSION_ID != 11 ]]; then
echo $msg
exit 1
fi
else
echo $msg
exit 1
fi
fi
}
check_version() {
if [ "$VERSION_ID" = "22.04" ]; then
echo -e "${RED}You can install AMS v2.6 or higher on Ubuntu 22.04${NC}"
exit 1
fi
if [ "$VERSION_ID" = "9" ]; then
echo -e "${RED}You can install AMS v2.6 or higher on Centos/AlmaLinux/RockyLinux 9${NC}"
exit 1
fi
}
check_enterprise_file() {
local retry_count=0
local max_retries=3
local remote_file
local local_file
while [ $retry_count -lt $max_retries ]; do
remote_file="$(curl -sL https://antmedia.io/download/latest-version.md5 | cut -d ' ' -f 1)"
local_file="$(md5sum "$ANT_MEDIA_SERVER_ZIP_FILE" | cut -d ' ' -f 1)"
if [ "$local_file" != "$remote_file" ]; then
echo "Downloaded file MD5 checksum is different from remote file MD5 checksum. Retrying download. Attempt: $((retry_count+1))"
curl --progress-bar -o "$ANT_MEDIA_SERVER_ZIP_FILE" "$check_license"
((retry_count++))
else
echo "Downloaded file MD5 checksum matches remote file MD5 checksum."
return 0
fi
done
echo "Failed to download the file after $max_retries attempts. Please re-run script again or check the internet connection"
exit 1
}
#Just checks if the latest ioperation is successfull
check() {
OUT=$?
if [ $OUT -ne 0 ]; then
echo "There is a problem in installing the ant media server. Please send the log of this console to [email protected]"
exit $OUT
fi
}
# Start
while getopts 'i:s:r:d:l:hu' option
do
case "${option}" in
s) INSTALL_SERVICE=${OPTARG};;
i) ANT_MEDIA_SERVER_ZIP_FILE=${OPTARG};;
r) SAVE_SETTINGS=${OPTARG};;
d) OTHER_DISTRO=${OPTARG};;
u) UPDATE="true";;
l) LICENSE_KEY=${OPTARG};;
h) usage
exit 1;;
esac
done
disk_usage
distro
if [ "$UPDATE" == "true" ]; then
update_script
fi
if [ -z "$ANT_MEDIA_SERVER_ZIP_FILE" ]; then
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
#Added curl package for the minimal OS installations.
$SUDO apt-get update
$SUDO apt-get install jq curl -y
check
elif [ "$ID" == "centos" ] || [ "$ID" == "almalinux" ] || [ "$ID" == "rocky" ] || [ "$ID" == "rhel" ]; then
$SUDO yum -y install jq curl
fi
if [ -z "${LICENSE_KEY}" ]; then
echo "Downloading the latest version of Ant Media Server Community Edition."
curl --progress-bar -o ams_community.zip -L "$(curl -s -H "Accept: application/vnd.github+json" https://api.github.com/repos/ant-media/Ant-Media-Server/releases/latest | jq -r '.assets[0].browser_download_url')"
ANT_MEDIA_SERVER_ZIP_FILE="ams_community.zip"
elif [ -n "${LICENSE_KEY}" ]; then
check_license=$(curl -s https://api.antmedia.io/?license="${LICENSE_KEY}" | tr -d "\"")
if [ "$check_license" == "401" ]; then
echo "Invalid license key. Please check your license key."
exit 1
else
VERSION_NAME=$(curl -s https://antmedia.io/download/latest-version.json | jq -r '.versionName')
echo "The license key is valid. Downloading the latest version ($VERSION_NAME) of Ant Media Server Enterprise Edition."
curl --progress-bar -o ams_enterprise.zip "$check_license"
ANT_MEDIA_SERVER_ZIP_FILE="ams_enterprise.zip"
check_enterprise_file
fi
fi
fi
if [ -z "$ANT_MEDIA_SERVER_ZIP_FILE" ]; then
# it means the previous parameters are used.
echo "Using old syntax to match the parameters. It's deprecated. Learn the new way by typing $0 -h"
ANT_MEDIA_SERVER_ZIP_FILE=$1
if [ ! -z "$2" ]; then
SAVE_SETTINGS=$2
fi
fi
if [ -z "$ANT_MEDIA_SERVER_ZIP_FILE" ]; then
echo "Please give the Ant Media Server zip file as parameter"
usage
exit 1
fi
SUDO="sudo"
if ! [ -x "$(command -v sudo)" ]; then
SUDO=""
fi
REQUIRED_VERSION="2.6"
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
$SUDO apt-get update -y
$SUDO apt-get install unzip zip libva-drm2 libva-x11-2 libvdpau-dev -y
$SUDO unzip -o $ANT_MEDIA_SERVER_ZIP_FILE "ant-media-server/ant-media-server.jar" -d /tmp/
VERSION=$(unzip -p /tmp/ant-media-server/ant-media-server.jar | grep -a "Implementation-Version"|cut -d' ' -f2 | tr -d '\r')
# If the version is lower than 2.6 and the architecture is x86_64, install the libcrystalhd-dev package.
# Additionally, arm64 architecture does not have libcrystalhd-dev and the following check will fix the installation problem in ARM.
# After 2.6, there is no dependency to libcrystalhd-dev
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]; then
check_version
if [ "x86_64" == $ARCH ]; then
$SUDO apt-get install libcrystalhd-dev -y
check
fi
fi
elif [ "$ID" == "centos" ] || [ "$ID" == "rocky" ] || [ "$ID" == "almalinux" ] || [ "$ID" == "rhel" ]; then
$SUDO yum -y install epel-release
$SUDO yum -y install unzip zip libva libvdpau
$SUDO unzip -o $ANT_MEDIA_SERVER_ZIP_FILE "ant-media-server/ant-media-server.jar" -d /tmp/
VERSION=$(unzip -p /tmp/ant-media-server/ant-media-server.jar | grep -a "Implementation-Version"|cut -d' ' -f2 | tr -d '\r')
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]; then
check_version
$SUDO yum -y install libcrystalhd
check
fi
if [ ! -L /usr/lib/jvm/java-11-openjdk-amd64 ]; then
find /usr/lib/jvm/ -maxdepth 1 -type d -iname "java-11*" | head -1 | xargs -i ln -s {} /usr/lib/jvm/java-11-openjdk-amd64
check
fi
ports=("5080" "443" "80" "5443" "1935")
for i in ${ports[*]}
do
firewall-cmd --add-port=$i/tcp --permanent > /dev/null 2>&1
done
firewall-cmd --add-port=5000-65000/udp --permanent > /dev/null 2>&1
firewall-cmd --reload > /dev/null 2>&1
fi
unzip $ANT_MEDIA_SERVER_ZIP_FILE
check
if [[ $VERSION == 2.1\.+.* || $VERSION == 2.0* || $VERSION == 1.* ]]; then
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
$SUDO apt-get install openjdk-8-jre -y
$SUDO apt purge openjfx libopenjfx-java libopenjfx-jni -y
$SUDO apt install openjfx=8u161-b12-1ubuntu2 libopenjfx-java=8u161-b12-1ubuntu2 libopenjfx-jni=8u161-b12-1ubuntu2 -y
$SUDO apt-mark hold openjfx libopenjfx-java libopenjfx-jni -y
$SUDO update-java-alternatives -s java-1.8.0-openjdk-amd64
elif [ "$ID" == "centos" ]; then
$SUDO yum -y install java-1.8.0-openjdk
if [ ! -L /usr/lib/jvm/java-8-openjdk-amd64 ]; then
ln -s /usr/lib/jvm/java-1.8.* /usr/lib/jvm/java-8-openjdk-amd64
fi
fi
$SUDO sed -i '/JAVA_HOME="\/usr\/lib\/jvm\/java-11-openjdk-amd64"/c\JAVA_HOME="\/usr\/lib\/jvm\/java-8-openjdk-amd64"' $AMS_BASE/antmedia
$SUDO sed -i '/Environment=JAVA_HOME="\/usr\/lib\/jvm\/java-11-openjdk-amd64"/c\Environment=JAVA_HOME="\/usr\/lib\/jvm\/java-8-openjdk-amd64"' $AMS_BASE/antmedia
elif [[ $VERSION == 2.4* || $VERSION == 2.3* || $VERSION == 2.2* ]]; then
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
$SUDO apt-get update -y
$SUDO apt-get install openjdk-11-jdk -y
check
fi
elif [[ $VERSION == 2.5* || $VERSION == 2.6* || $VERSION == 2.7* ]]; then
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
$SUDO apt-get update -y
$SUDO apt-get install openjdk-11-jre-headless -y
check
elif [ "$ID" == "centos" ] || [ "$ID" == "almalinux" ] || [ "$ID" == "rocky" ] || [ "$ID" == "rhel" ]; then
$SUDO yum -y install java-11-openjdk-headless tzdata-java
ln -s $(readlink -f $(which java) | rev | cut -d "/" -f3- | rev) /usr/lib/jvm/java-11-openjdk-amd64
fi
echo "export JAVA_HOME=\/usr\/lib\/jvm\/java-11-openjdk-amd64/" >>~/.bashrc
source ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
echo "JAVA_HOME : $JAVA_HOME"
find /usr/lib/jvm/ -maxdepth 1 -type d -iname "java-11*" | head -1 | xargs -i update-alternatives --set java {}/bin/java
else
# with 2.8 we start to use java17
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
$SUDO apt-get update -y
$SUDO apt-get install openjdk-17-jre-headless -y
check
elif [ "$ID" == "centos" ] || [ "$ID" == "almalinux" ] || [ "$ID" == "rocky" ] || [ "$ID" == "rhel" ]; then
$SUDO yum -y install java-17-openjdk-headless tzdata-java
ln -s $(readlink -f $(which java) | rev | cut -d "/" -f3- | rev) /usr/lib/jvm/java-17-openjdk-amd64
fi
echo "export JAVA_HOME=\/usr\/lib\/jvm\/java-17-openjdk-amd64/" >>~/.bashrc
source ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/
echo "JAVA_HOME : $JAVA_HOME"
find /usr/lib/jvm/ -maxdepth 1 -type d -iname "java-17*" | head -1 | xargs -i update-alternatives --set java {}/bin/java
fi
if ! [ -d $AMS_BASE ]; then
$SUDO mv ant-media-server $AMS_BASE
check
else
$SUDO mv $AMS_BASE $BACKUP_DIR
check
$SUDO mv ant-media-server $AMS_BASE
check
fi
# use ln because of the jcvr bug: https://stackoverflow.com/questions/25868313/jscv-cannot-locate-jvm-library-file
$SUDO mkdir -p $JAVA_HOME/lib/amd64
$SUDO ln -sfn $JAVA_HOME/lib/server $JAVA_HOME/lib/amd64/
if [ "$INSTALL_SERVICE" == "true" ]; then
if ! [ -x "$(command -v systemctl)" ]; then
$SUDO cp $AMS_BASE/antmedia /etc/init.d
$SUDO update-rc.d antmedia defaults
$SUDO update-rc.d antmedia enable
check
else
$SUDO chmod 644 $AMS_BASE/antmedia.service
$SUDO cp -p $AMS_BASE/antmedia.service /etc/systemd/system/
if [ "$OTHER_DISTRO" == "true" ]; then
sed -i "s#=JAVA_HOME.*#=JAVA_HOME=$CUSTOM_JVM#g" $SERVICE_FILE
fi
if [ "aarch64" == $ARCH ]; then
$SUDO update-java-alternatives -s java-1.11.*-openjdk-arm64
sed -i "s#=JAVA_HOME.*#=JAVA_HOME=$DEFAULT_JAVA_ARM#g" $SERVICE_FILE
fi
$SUDO echo 'antmedia ALL=(ALL) NOPASSWD: /bin/bash enable_ssl.sh*' > /etc/sudoers.d/antmedia
$SUDO systemctl daemon-reload
$SUDO systemctl enable antmedia
check
fi
fi
# create log directory if not exist
if [ ! -d "$LOG_DIRECTORY" ]
then
#delete if there is a symbolic link or something
$SUDO rm -rf $LOG_DIRECTORY
#create log
$SUDO mkdir $LOG_DIRECTORY
fi
# create a logrotate config file
cat << EOF | $SUDO tee /etc/logrotate.d/antmedia > /dev/null
/var/log/antmedia/antmedia-error.log {
daily
create 644 antmedia antmedia
rotate 7
maxsize 50M
compress
delaycompress
copytruncate
notifempty
sharedscripts
postrotate
reload rsyslog >/dev/null 2>&1 || true
endscript
}
/var/log/antmedia/0.0.0.0_access*.log {
daily
create 644 antmedia antmedia
rotate 7
maxsize 50M
compress
delaycompress
copytruncate
notifempty
sharedscripts
postrotate
reload rsyslog >/dev/null 2>&1 || true
endscript
}
EOF
check
$SUDO ln -sf $LOG_DIRECTORY $AMS_BASE/log
check
$SUDO touch $AMS_BASE/log/antmedia-error.log
check
OS=`uname | tr "[:upper:]" "[:lower:]"`
PLATFORM=$OS-$ARCH
echo "PLATFORM:$PLATFORM"
if [ -d "$AMS_BASE/lib/native-$PLATFORM" ] ; then
$SUDO mv $AMS_BASE/lib/native-$PLATFORM $AMS_BASE/lib/native
$SUDO rm -r $AMS_BASE/lib/native-*
fi
if ! [ $(getent passwd | grep antmedia.*$AMS_BASE) ] ; then
$SUDO useradd -d $AMS_BASE/ -s /bin/false -r antmedia
check
fi
$SUDO chown -R antmedia:antmedia $AMS_BASE/
check
$SUDO chown -R antmedia:antmedia $LOG_DIRECTORY
check
if [ "$INSTALL_SERVICE" == "true" ]; then
$SUDO service antmedia stop &
wait $!
$SUDO service antmedia start
check
fi
# set the license key
if [ -n "${LICENSE_KEY}" ]; then
sed -i $SED_COMPATIBILITY 's/server.licence_key=.*/server.licence_key='$LICENSE_KEY'/' $AMS_BASE/conf/red5.properties
fi
if [ "$?" -eq "0" ]; then
if [ "$SAVE_SETTINGS" == "true" ]; then
sleep 5
restore_settings
check
$SUDO chown -R antmedia:antmedia $AMS_BASE/
check
if [ "$INSTALL_SERVICE" == "true" ]; then
$SUDO service antmedia restart
check
fi
fi
if [ "$INSTALL_SERVICE" == "false" ]; then
echo "Ant Media Server is installed. You have the whole control and manage to run the start.sh in the $AMS_BASE"
echo "because you prefer to not have the service installation. Type $0 -h for usage info "
else
echo "Ant Media Server is installed and started."
fi
else
echo "There is a problem in installing the ant media server. Please send the log of this console to [email protected]"
fi