-
Notifications
You must be signed in to change notification settings - Fork 0
/
sm_manager.sh
853 lines (729 loc) · 24.7 KB
/
sm_manager.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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
#!/bin/bash
#
# Simple Server Manager
#
# Description Following
#
#
#
#
#
#
#
#
#
# Begin Functions
# Load server config - param: directory to look in
sm_loadserver() {
if [ -z "$1" ]
then
sm_failserver No_Server
SPATH=""
CFGPATH=""
else
# Load Config
SPATH="./"
SPATH+=$1
SPATH+="/"
DNAME=$1
CFGPATH=$SPATH
CFGPATH+=$CONFIGNAME
if [ -f $CFGPATH ]
then source $CFGPATH
else sm_failserver No_Config
fi
fi
}
# Set Failsave config values - param: Add to name
sm_failserver() {
if [ -z "$1" ]
then
# Set Failsave Values (No parameter)
NAME="ERROR"
else
NAME="ERROR ("
NAME+="$1"
NAME+=")"
fi
PORT=""
SCREENID=""
}
# Display Statusline of current loaded config
sm_summary() {
TLENGHT=0 # Coloumn is now 0
# Form Line
# Name
let TLENGHT=30 # Reserve chars (color codes!)
LINE+="$(tput setaf 6)"
LINE+=$NAME
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE+=" "
done
# Port
let TLENGHT+=24 # Reserve chars (color codes!)
LINE+="$(tput sgr 0) Port: $(tput setaf 3)"
LINE+=$PORT
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE+=" "
done
# Version
let TLENGHT+=32 # Reserve chars (color codes!)
LINE+="$(tput sgr 0) Version: $(tput setaf 3)"
TMP=$SPATH
TMP+="StarMade/version.txt"
if [ -f $TMP ]
then TMP2=$(cat $TMP)
else TMP2="error"
fi
LINE+=${TMP2%#*}
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE+=" "
done
# Screen
let TLENGHT+=32 # Reserve chars (color codes!)
LINE+="$(tput sgr 0) Screen: $(tput setaf 4)"
LINE+=$SCREENID
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE+=" "
done
# Status
let TLENGHT+=38 # Reserve chars (color codes!)
LINE+="$(tput sgr 0) Status: "
sm_cstatus
case $CSTATUS in
ru*|sta*) LINE+="$(tput setaf 2)$CSTATUS$(tput sgr 0)" ;; # running, starting (green)
sto*|cr*) LINE+="$(tput setaf 1)$CSTATUS$(tput sgr 0)" ;; # stopped, crashed (red)
un*) LINE+="$(tput setaf 5)$CSTATUS$(tput sgr 0)" ;; # unknown (orange)
*) LINE+="$(tput setaf 3)$CSTATUS$(tput sgr 0)" ;; # anything else (yellow)
esac
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE+=" "
done
# Output
echo "$LINE $(tput sgr 0)"
}
# Screen stuff - stop server
sm_stop() {
if [ -n "$1" ]
then
echo "stop" > $WANTPATH
if [ -f $SPATH/StarMade/logs/log.txt.0.lck ]
then
echo "shutdown" > $INFOPATH
if [ -n "$SCREENID" ]
then
screen -S "$SCREENID" -p 0 -X stuff "/server_message_broadcast error \"Server-Manager\\\nShutdown initiated\\\nNO RESTART\"`echo -ne '\015'`"
screen -S "$SCREENID" -p 0 -X stuff "/shutdown 300`echo -ne '\015'`"
fi
else
echo "stopped" > $INFOPATH
fi
fi
}
# Screen stuff - restart server
sm_restart() {
if [ -n "$1" ]
then
echo "restart" > $WANTPATH
if [ -f $INFOPATH ]
then
echo "shutdown" > $INFOPATH
fi
if [ -n "$SCREENID" ]
then
screen -S "$SCREENID" -p 0 -X stuff "/server_message_broadcast error \"Server-Manager\\\nRestarting Server\"`echo -ne '\015'`"
screen -S "$SCREENID" -p 0 -X stuff "/shutdown 180`echo -ne '\015'`"
fi
fi
}
# Screen stuff - update server
sm_update() {
if [ -n "$1" ]
then
sm_getupdate "$UPDCHAN"
echo "Channel: dev"
echo "Current Zip: $CURZIP"
echo "Current Version: $CURVER"
echo "Channel: installed"
TMP=$SPATH
TMP+="StarMade/version.txt"
if [ -f $TMP ]
then INSTVER=$(cat $TMP)
else INSTVER="error"
fi
echo "Installed Version: $INSTVER"
if [ "$CURVER" = "$INSTVER" ]
then
# Version matching - All fine
echo "No Update Needed"
else
# Version not matching
echo "Update found"
echo "update" > $WANTPATH
echo "shutdown" > $INFOPATH
if [ -n "$SCREENID" ]
then
screen -S "$SCREENID" -p 0 -X stuff "/server_message_broadcast info \"Server-Manager\\\nUpdate to Version:\\\n$CURVER\"`echo -ne '\015'`"
screen -S "$SCREENID" -p 0 -X stuff "/shutdown 300`echo -ne '\015'`"
fi
sleep 5
fi
fi
}
# Update - Channel
sm_getupdate() {
if [ -z "$1" ]
then
# Error Param - Do all?
echo "No parameter given"
exit 0
elif [ "$1" = "rel" ]
then
# Load Release Channel
wget -q --user dev --password dev -O tmp.html $RELPATH
RELEASE_URL=`cat tmp.html | grep -o -E "[^<>]*?.zip" | tail -1`
rm tmp.html
if [ -f $RELEASE_URL ]
then
echo "Found local copy of $RELEASE_URL unsing it for updates."
else
wget --user dev --password dev $RELPATH/$RELEASE_URL
fi
CURZIP=$RELEASE_URL
elif [ "$1" = "dev" ]
then
# Load dev Channel
wget -q --user dev --password dev -O tmp.html $DEVPATH
DEV_URL=`cat tmp.html | grep -o -E "[^<>]*?.zip" | tail -1`
rm tmp.html
if [ -f $DEV_URL ]
then
echo "Found local copy of $DEV_URL using it for updates."
else
wget --user dev --password dev $DEVPATH/$DEV_URL
fi
CURZIP=$DEV_URL
elif [ "$1" = "manual" ]
then
# Load Manual Files
echo "X"
else
echo "Error Detected - Script malfunction"
sleep 5
exit 0
fi
# CURZIP defined - prepare comparing of variables
CURVER=$(unzip -p $CURZIP version.txt)
}
# Get Current Status
sm_cstatus() {
INFOPATH=$SPATH
INFOPATH+=$STATUSNAME
if [ -f $INFOPATH ]
then
CSTATUS="$(cat $INFOPATH)" # Content managed by loopscript/UPD requests
else
CSTATUS="unknown"
fi
}
# Get Wanted Status
sm_wstatus() {
WANTPATH=$SPATH
WANTPATH+=$STATUSWANT
if [ -f $WANTPATH ]
then
WSTATUS="$(cat $WANTPATH)" # Content managed by Controlscript
else
WSTATUS="unknown"
fi
}
# Main Menu
sm_mainmenu() {
clear
echo "MainMenu"
echo ""
if [ -n "$SERVER1" ]
then
# Load Config
sm_loadserver $SERVER1
LINE="1: "
sm_summary
fi
if [ -n "$SERVER2" ]
then
# Load Config
sm_loadserver $SERVER2
LINE="2: "
sm_summary
fi
if [ -n "$SERVER3" ]
then
# Load Config
sm_loadserver $SERVER3
LINE="3: "
sm_summary
fi
if [ -n "$SERVER4" ]
then
# Load Config
sm_loadserver $SERVER4
LINE="4: "
sm_summary
fi
if [ -n "$SERVER5" ]
then
# Load Config
sm_loadserver $SERVER5
LINE="5: "
sm_summary
fi
}
# Mainmenu (input)
sm_maininput() {
echo "Maininput - $INPUT"
# Input to Server
if [ "$INPUT" = "1" ]
then
PROGSTATE=1
sm_loadserver $SERVER1
elif [ "$INPUT" = "2" ]
then
PROGSTATE=1
sm_loadserver $SERVER2
elif [ "$INPUT" = "3" ]
then
PROGSTATE=1
sm_loadserver $SERVER3
elif [ "$INPUT" = "4" ]
then
PROGSTATE=1
sm_loadserver $SERVER4
elif [ "$INPUT" = "5" ]
then
PROGSTATE=1
sm_loadserver $SERVER5
elif [ "$INPUT" = "r" ]
then
$PROGSTATE=0
fi
}
# Servermenu (Display)
sm_servermenu() {
clear
echo "ServerMenu"
echo ""
TLENGHT=30
# Name
LINE="Servername: $(tput setaf 6)"
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE=" $LINE"
done
LINE+=$NAME
echo "$LINE $(tput sgr 0)"
# Port
LINE="Port: $(tput setaf 6)"
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE=" $LINE"
done
LINE+=$PORT
echo "$LINE $(tput sgr 0)"
# Version
LINE="Version: $(tput setaf 6)"
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE=" $LINE"
done
TMP=$SPATH
TMP+="StarMade/version.txt"
if [ -f $TMP ]
then
TMP2=$(cat $TMP)
LINE+=${TMP2%#*}
else
TMP2=""
fi
echo "$LINE $(tput sgr 0)"
# Build
LINE="Build: $(tput setaf 6)"
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE=" $LINE"
done
TMP=$SPATH
TMP+="StarMade/version.txt"
if [ -f $TMP ]
then
TMP2=$(cat $TMP)
LINE+=${TMP2#*#}
else
TMP2=""
fi
echo "$LINE $(tput sgr 0)"
# Expected status
LINE="Expected Status: $(tput setaf 6)"
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE=" $LINE"
done
sm_wstatus
case $WSTATUS in
ru*|sta*) LINE+="$(tput setaf 2)$WSTATUS" ;; # running, starting (green)
sto*|cr*) LINE+="$(tput setaf 1)$WSTATUS" ;; # stopped, crashed (red)
un*) LINE+="$(tput setaf 5)$WSTATUS" ;; # unknown (orange)
*) LINE+="$(tput setaf 3)$WSTATUS" ;; # anything else (yellow)
esac
echo "$LINE $(tput sgr 0)"
# Current Status
LINE="Current Status: $(tput setaf 6)"
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE=" $LINE"
done
sm_cstatus
case $CSTATUS in
ru*|sta*) LINE+="$(tput setaf 2)$CSTATUS" ;; # running, starting (green)
sto*|cr*) LINE+="$(tput setaf 1)$CSTATUS" ;; # stopped, crashed (red)
un*) LINE+="$(tput setaf 5)$CSTATUS" ;; # unknown (orange)
*) LINE+="$(tput setaf 3)$CSTATUS" ;; # anything else (yellow)
esac
echo "$LINE $(tput sgr 0)"
# Path
LINE="Folder: $(tput setaf 6)"
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE=" $LINE"
done
LINE+=$SPATH
echo "$LINE $(tput sgr 0)"
# CFG-Path
LINE="Config: $(tput setaf 6)"
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE=" $LINE"
done
LINE+=$CFGPATH
echo "$LINE $(tput sgr 0)"
# ScreenID
LINE="SceenID: $(tput setaf 6)"
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE=" $LINE"
done
LINE+=$SCREENID
echo "$LINE $(tput sgr 0)"
# UPD
LINE="Update Mode: $(tput setaf 6)"
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE=" $LINE"
done
if [ -z "$UPDCHAN" ]
then
LINE+="Off"
else
LINE+="$UPDCHAN"
fi
echo "$LINE $(tput sgr 0)"
# LOG
LINE="Timestamp (log): "
TMP=$SPATH
TMP+="StarMade/logs/log.txt.0"
TIME1=$(date +%s)
if [ -f $TMP ]
then TIME2=$(stat -c %Y $TMP)
else TIME2=0
fi
let DIFF=( $TIME1 - $TIME2 )
if [ $DIFF -lt 300 ]
then LINE+="$(tput setaf 2)"
else LINE+="$(tput setaf 1)"
fi
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE=" $LINE"
done
LINE+=$DIFF
LINE+=" seconds ago"
echo "$LINE $(tput sgr 0)"
# Startup
LINE="Last start: $(tput setaf 6)"
TMP=$SPATH
TMP+="StarMade/logs/log.txt.0.lck"
TIME1=$(date +%s)
if [ -f $TMP ]
then TIME2=$(stat -c %Z $TMP)
else TIME2=0
fi
let DIFF=( $TIME1 - $TIME2 )
while [ ${#LINE} -lt $TLENGHT ] # TempExtension - Looking for better way to do this
do LINE=" $LINE"
done
let DIFF=( $DIFF / 3600 )
LINE+=$DIFF
LINE+=" hours ago"
echo "$LINE $(tput sgr 0)"
sm_wstatus
if [ "$WSTATUS" != "run" ]
then echo "1: $(tput setaf 2)start$(tput sgr 0)"
else echo "1:"
fi
if [ "$WSTATUS" = "run" ]
then echo "2: $(tput setaf 2)restart$(tput sgr 0)"
else echo "2:"
fi
if [ "$WSTATUS" != "stop" ]
then echo "3: $(tput setaf 2)stop$(tput sgr 0)"
else echo "3:"
fi
if [ "$WSTATUS" != "update" -a -n "$UPDCHAN" ]
then echo "4: $(tput setaf 2)update$(tput sgr 0)"
else echo "4:"
fi
if [ -n "RELPATH" -o -n "DEVPATH" ]
then echo "5: $(tput setaf 2)change Update source$(tput sgr 0)"
else echo "5:"
fi
echo "r: $(tput setaf 3)return to main$(tput sgr 0)"
}
# Mainmenu (input)
sm_serverinput() {
sm_wstatus
if [ "$INPUT" = "1" -a "$WSTATUS" != "run" ]
then
# Start Server
sm_start $SPATH
elif [ "$INPUT" = "2" -a "$WSTATUS" = "run" ]
then
# Restart Server
sm_restart $SPATH
elif [ "$INPUT" = "3" -a "$WSTATUS" != "stop" ]
then
# Stop Server
sm_stop $SPATH
elif [ "$INPUT" = "4" -a "$WSTATUS" != "update" ]
then
# Update Server
sm_update $SPATH
elif [ "$INPUT" = "r" ]
then
PROGSTATE=0
fi
}
# End Functions
# Begin Main Code
# Load settings
if [ -f sm_config.cfg ]
then
source "sm_config.cfg"
PROGSTATE=0
else
PROGSTATE=200
fi
if [ -z $1 ]
then
# No Params - MenuMode
INPUT=""
while [ $PROGSTATE -lt 100 ]
# PROGSTATES
# 0 = Mainmenu
# 1-9 = Servermenu
# 100 = Exit
do
# Mainmenu
if [ $PROGSTATE -eq 0 ]
then sm_mainmenu
elif [ $PROGSTATE -ge 1 ]
then sm_servermenu
fi
# Wait for Input
echo "q: $(tput setaf 1)quit$(tput sgr 0)"
printf "Input:"
read INPUT
# Process input (Menu)
if [ $PROGSTATE -eq 0 ]
then sm_maininput
elif [ $PROGSTATE -eq 1 ]
then sm_serverinput
fi
# Process input (Global)
if [ "$INPUT" = "q" ]
then PROGSTATE=100
fi
done
else
# Parameter added - Loopmode
if [ "$1" = "loop" ]
# Loopmode to spawn in screen
then
# load config
if [ -f "./sm_config.cfg" ]
then
echo "Reloading main config"
source ./sm_config.cfg
else
echo "Warning - Main Config file missing"
exit 0
fi
# Load Server
if [ -n "$2" ]
then
echo "Loading Server $2"
sm_loadserver $2
else
echo "This mode is designated to use by manager itself"
echo "Parameters required: 2"
exit 2
fi
# Validate server
if [ -f $CFGPATH ]
then
echo "Config loaded from $CFGPATH"
echo "Changing to: $(pwd)/$DNAME"
cd $(pwd)/$DNAME
# Check config sanity
# Wanted status?
if [ -f $STATUSWANT ]
then
WSTATUS=$(cat $STATUSWANT)
echo "Expected Status: $WSTATUS"
else
echo "Could not read wanted status, please start this script via Server-Manager"
exit 0
fi
# Current status
if [ -f $STATUSNAME ]
then
CSTATUS=$(cat $STATUSNAME)
echo "Current Status: $CSTATUS"
else
echo "Could not read current status..."
if [ -f ./StarMade/logs/log.txt.0.lck ]
then
echo "...Server seems running, please remove $(pwd)/$DNAME/StarMade/logs/log.txt.0.lck"
exit 0
else
echo "...Server not running creating statusfile"
echo "stopped" > $STATUSNAME
fi
fi
else
echo "Error - No Config file found at $CFGPATH"
exit 0
fi
# Mark Current status
echo "Starting" > $STATUSNAME
# Entering loop - base config OK
while true;
do
# Reload main config
if [ -f "./../sm_config.cfg" ]
then
echo "Reloading main config"
source ./../sm_config.cfg
else
echo "Warning - Main Config file missing"
exit 0
fi
# Prequel (Reload Server) - Begin Main Loop
if [ -f $CONFIGNAME ]
then
echo "Config (re)loaded from $CONFIGNAME"
source $CONFIGNAME
# Check config sanity
# Wanted status?
if [ -f $STATUSWANT ]
then
WSTATUS=$(cat $STATUSWANT)
echo "Expected Status: $WSTATUS"
else
echo "Could not read wanted status, file missing ($STATUSWANT)"
echo "ConfigError - Wanted status" > $STATUSNAME
exit 0
fi
# Current status
if [ -f $STATUSNAME ]
then
CSTATUS=$(cat $STATUSNAME)
echo "Current Status: $CSTATUS"
else
echo "Could not read wanted status, file missing ($STATUSWANT)"
echo "ConfigError - Current status" > $STATUSNAME
exit 0
fi
else
echo "Error - No Config file found at $CONFIGNAME"
exit 0
fi
# Prequel Passed - ready to work
# Update Current Status
if [ "$CSTATUS" = "running" ]
then
# Reaching prestart, while expected running -> assume crash
# or manual shutdown (avoid false positive on crash by taillog?)
echo "crashed" > $STATUSNAME
CSTATUS="crashed"
else
echo "stopped" > $STATUSNAME
CSTATUS="stopped"
fi
# Save Logs
LOGNAME="Build"
if [ -f ./StarMade/version.txt ]
then
TMP=$(cat ./StarMade/version.txt)
LOGNAME+=${TMP#*#}
else
LOGNAME+="undef"
fi
LOGNAME+="-$DNAME-"
if [ "$CSTATUS" = "crashed" ]
then
LOGNAME+="crash"
else
LOGNAME+="$WSTATUS"
fi
LOGNAME+="on$(date '+%Y%m%d-%H%M%S')"
mv -f ./StarMade/logs $LOGDIR/$LOGNAME
# Update
if [ "$WSTATUS" = "update" ]
then
echo "updating" > $STATUSNAME
CSTATUS="updating"
echo "run" > $STATUSWANT
WSTATUS="run"
cd ..
sm_getupdate $UPDCHAN
cd $DNAME
unzip -o ./../$CURZIP -d $(pwd)/StarMade
fi
# Go for Startup
if [ "$WSTATUS" = "stop" ]
then
echo "Shutdown requested, NOT restarting."
sleep 5
exit 0
fi
# Pause before start
echo "(re)entering loop"
echo "Name: $NAME"
echo "Port: $PORT"
echo "Path: $(pwd)"
echo "MAX-MEMORY: $MAXMEM"
echo "MIN-MEMORY: $MINMEM"
echo "Hit ctrl + c now, to exit loop (5sec)"
sleep 5
echo "starting...."
echo "running" > $STATUSNAME
cd StarMade
if [ "$PORT" = "4242" ]
then
java -Dcom.sun.management.jmxremote.host=144.76.174.130 -Dcom.sun.management.jmxremote.port=3333 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -XX:-OmitStackTraceInFastThrow -Xms$MINMEM -Xmx$MAXMEM -jar StarMade.jar -server -port:$PORT
else
java -XX:-OmitStackTraceInFastThrow -Xms$MINMEM -Xmx$MAXMEM -jar StarMade.jar -server -port:$PORT
fi
cd ..
echo "exited...."
done
PROGSTATE=130
sleep 5
elif [ "$1" = "config" ]
# Config mode (Create?)
then
echo "Configmode"
PROGSTATE=180
sleep 5
fi
fi
echo "Exited (5 sec delay) PROG: $PROGSTATE"
sleep 5