-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathminecraft
More file actions
executable file
·692 lines (552 loc) · 23.7 KB
/
minecraft
File metadata and controls
executable file
·692 lines (552 loc) · 23.7 KB
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
#!/bin/bash
# /etc/init.d/minecraft
# version 0.4.3 2012-01-11 (YYYY-MM-DD)
### BEGIN INIT INFO
# Provides: minecraft
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Minecraft server
# Description: Starts the minecraft server
### END INIT INFO
# chkconfig 2345 99 01
# Codecraft-init-script: Linux init script for starting minecraft as a service
# Copyright (C) 2011-2012 Daniel Hodgson, William Haggerty, Codeprogrammers
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#Settings are in /etc/<SCRIPTNAME>.conf
############################[ Script Start]#############################
SCRIPTNAME="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"
lockfile="/var/lock/"$SCRIPTNAME
echo "Reading settings from /etc/$SCRIPTNAME.conf."
configfile="/etc/$SCRIPTNAME.conf"
configfile_secured="/tmp/$SCRIPTNAME.conf"
# check if the file contains something we don't want
if egrep -q -v '^#|^[^ ]*=[^;]*' "$configfile"; then
echo "The configuration file is not clean! Cleaning it."
# filter the original to a new file
egrep '^#|^[^ ]*=[^;&]*' "$configfile" > "$configfile_secured"
configfile="$configfile_secured"
fi
source $configfile
#Grabbing world name from $MC_PATH/server.properties
WORLD_NAME=$(cat $ROOT_PATH/$SERVER_DIR/$BUILD/server.properties | fgrep 'level-name=' | sed -e s/.*level-name=//)
#Grabbing world container folder from $ROOT_PATH/$SERVER_DIR/$BUILD/bukkit.yml
WORLD_CONTAINER="$ROOT_PATH/$SERVER_DIR/$BUILD" # Init $WORLD_CONTAINER
if [ -f "$ROOT_PATH/$SERVER_DIR/$BUILD/bukkit.yml" ]
then
if [[ $(cat $ROOT_PATH/$SERVER_DIR/$BUILD/bukkit.yml | fgrep 'world-container:' | sed -e 's/^[ \t]*//') != \#* ]]
then WORLD_CONTAINER=$(cat $ROOT_PATH/$SERVER_DIR/$BUILD/bukkit.yml | fgrep 'world-container:' | sed -e s/.*world-container:// | sed -e s/#.*// | sed -e 's/^[ \t]*//;s/[ \t]*$//')
else WORLD_CONTAINER="$ROOT_PATH/$SERVER_DIR/$BUILD"
fi
else WORLD_CONTAINER="$ROOT_PATH/$SERVER_DIR/$BUILD"
fi
#Check for Absolute Path
if [[ $WORLD_CONTAINER != /* ]]
then WORLD_CONTAINER=$ROOT_PATH/$SERVER_DIR/$BUILD/$WORLD_CONTAINER
fi
#Run commands as the user defined in the $USERNAME variable
ME=`whoami`
as_user() {
if [ $ME == $USERNAME ]
then
bash -c "$1"
else
su - $USERNAME -c "$1"
fi
}
#--------------------+
# Starts the service |
#--------------------+
# If the service is already running, will alert the user and end the function.
# If ramdisk feature is enabled, will attempt to mount and load the ramdisk.
# If the service fails to start, and ramdisk feature is enabled, will attempt
#+ to unload the ramdisk and unmount it.
#--------------------+
mc_start() {
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then echo "Tried to start but $SERVICE was already running!"
else echo "Starting $SERVICE."
# Checking for the existance of the world using the name defined in server.properties
if [ ! -d "$ROOT_PATH/$WORLD_DIR/$WORLD_NAME" ]
then
echo "Aborting service startup!"
echo "$WORLD_NAME is not in $ROOT_PATH/$WORLD_DIR!" # If no world exists, tell the user and abort
exit 1
fi
mc_link # link $WORLD_DIR to $WORLD_CONTAINER
if [ $RAMDISK == 'true' ]
then
mcrd_mount
mcrd_load
fi
as_user "cd $ROOT_PATH/$SERVER_DIR/$BUILD && screen -dmS $SCREEN_NAME $INVOCATION" ; sleep 7
#Check to see if the service started successfully
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then echo "$SERVICE is now running."
else echo "Could not start $SERVICE."
if [ $RAMDISK == 'true' ]
then
if mount -l -t $RD_TYPE | grep $ROOT_PATH/$RD_DIR > /dev/null
then echo "Unloading Ramdisk."
mcrd_unload
mcrd_unmount
else echo "Ramdisk already unloaded!"
fi
fi
fi
fi
}
#-------------------+
# Stops the service |
#-------------------+
# Sends notice of impending shutdown as message to minecraft/bukkit console.
# Notifies user if service fails to stop.
#-------------------+
mc_stop() {
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then echo "$SERVICE is running. stopping."
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $STOP_MSG\"\015'" ; sleep 5
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"save-all\"\015'" ; sleep 5
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"stop\"\015'" ; sleep 5
else echo "$SERVICE was not running."
fi
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then echo "$SERVICE could not be shut down. still running."
else echo "$SERVICE is shut down."
fi
}
#----------------------+
# Disables auto-saving |
#----------------------+
# Sends notice of disablement of auto-saving as message to minecraft/bukkit console.
# Turns off automatic saving.
# Saves all in-game changes and syncs to disk.
#----------------------+
mc_saveoff() {
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then echo "$SERVICE is running. suspending saves."
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $SAVE_OFF_MSG\"\015'"
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"save-off\"\015'"
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"save-all\"\015'"
sync ; sleep 5
else echo "$SERVICE was not running. Not suspending saves."
fi
}
#---------------------+
# Enables auto-saving |
#---------------------+
# Turns on automatic saving.
# Sends notice of enablement of auto-saving as message to minecraft/bukkit console.
#---------------------+
mc_saveon() {
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then echo "$SERVICE is running. re-enabling saves"
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"save-on\"\015'"
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $SAVE_ON_MSG\"\015'"
else echo "$SERVICE was not running. Not resuming saves."
fi
}
#-----------------------------+
# Backup files from $REF_PATH |
#-----------------------------+
# Creates directory tree for backups if it doesn't exist.
# Copies files from $REF_PATH into $REF_BUDIR.
#-----------------------------+
backup() {
echo "Backing Up $REF_BUDIR."
cd $ROOT_BUPATH
if [ ! -d $REF_BUDIR ]
then
as_user "mkdir $ROOT_BUPATH/$REF_BUDIR"
cd $REF_BUDIR
else
cd $REF_BUDIR
fi
# Check for directories with the current datestamp
if ls | grep $DATE > /dev/null
then
cd $DATE
else
as_user "mkdir $ROOT_BUPATH/$REF_BUDIR/$DATE"
cd $DATE
fi
# Check for directories with the curent timestamp.
if ls | grep $TIME > /dev/null
then
TIME="$TIME"_`date "+%S"` # Appened the current seconds time to $bu_time
as_user "mkdir $ROOT_BUPATH/$REF_BUDIR/$DATE/$TIME"
cd $REF_PATH
for dir in *
do
if [[ $dir != *.old ]]
then
as_user "cp -aL $REF_PATH/$dir $ROOT_BUPATH/$REF_BUDIR/$DATE/$TIME"
fi
done
else
as_user "mkdir $ROOT_BUPATH/$REF_BUDIR/$DATE/$TIME"
cd $REF_PATH
for dir in *
do
if [[ $dir != *.old ]]
then
as_user "cp -aL $REF_PATH/$dir $ROOT_BUPATH/$REF_BUDIR/$DATE/$TIME"
fi
done
fi
echo "Backup finished"
}
#------------------------+
# Check backup integrity |
#------------------------+
# Creat directory tree for checksums if it doesn't exist.
# Tarballs reference files and backup files.
# Runs a checksum of the two tarballs seperately.
# Compares the checksums to check intergrity of backup.
#------------------------+
backup_cksum() {
echo "Running checksum."
cd $ROOT_BUPATH
if [ -d chksum ]
then cd chksum
if [ -d $REF_BUDIR ] # $CS_PATH = $ROOT_BUPATH/chksum/$REF_BUDIR. Since it seems as though we need to
then cd $REF_BUDIR #+ use asbolute paths, we might as well make another variable to lighten the load.
if [ -d reference ]
then
rm -rf reference
as_user "mkdir $CS_PATH/reference"
else
as_user "mkdir $CS_PATH/reference"
fi
if [ -d backup ]
then
rm -rf backup
as_user "mkdir $CS_PATH/backup"
else
as_user "mkdir $CS_PATH/backup"
fi
else
as_user "mkdir $CS_PATH ; cd $CS_PATH"
as_user "mkdir $CS_PATH/reference ; mkdir $CS_PATH/backup"
fi
else
as_user "mkdir $ROOT_BUPATH/chksum ; cd $ROOT_BUPATH/chksum"
as_user "mkdir $CS_PATH ; cd $CS_PATH"
as_user "mkdir $CS_PATH/reference ; mkdir $CS_PATH/backup"
fi
as_user "cd $REF_PATH ; tar -chf checksum.tar * --exclude=*.old"
as_user "mv $REF_PATH/checksum.tar $CS_PATH/reference"
as_user "cd $ROOT_BUPATH/$REF_BUDIR/$DATE/$TIME ; tar -chf checksum.tar *"
as_user "mv $ROOT_BUPATH/$REF_BUDIR/$DATE/$TIME/checksum.tar $CS_PATH/backup"
cd $CS_PATH
REF_checksum=$(ls reference | cksum) # Set $REF_checksum to the value of the checksum of the current worlds' tarball
BACKUP_checksum=$(ls backup | cksum) # Set $BACKUP_checksum to the value of the checksum of the newest backup's tarball
# Compare the values of the checksums
if [ "$REF_checksum" = "$BACKUP_checksum" ]
then
echo "Backup Successful."
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $BACKUP_DONE_MSG\"\015'"
else
echo "Backup failed! The reference and backup contents do not match!"
echo "Worlds: $REF_checksum" ; echo "Backup: $BACKUP_checksum"
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $BACKUP_FAIL_MSG\"\015'"
fi
}
#---------------+
# Links worlds |
#---------------+
# Checks status of service; if service is not running, attempts to link worlds.
# Appends ".old" to symbolic links in $WORLD_CONTAINER which point to $WORLD_DIR and $WORLD_DIR.
# Creates symbolic links to $WORLD_DIR in $WORLD_CONTAINER.
#---------------+
mc_link() {
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null # Is service running?
then echo "Cannot link worlds to $WORLD_CONTAINER, $SERVICE is running! "
else echo "Linking worlds to $WORLD_CONTAINER ..."
# Process worlds in $WORLD_DIR
cd $ROOT_PATH/$WORLD_DIR # cd to $ROOT_PATH/$WORLD_DIR
for dir in * # For each folder in $ROOT_PATH/$WORLD_DIR,
do
if [ ! -d "$WORLD_CONTAINER/$dir" ] # We are going to make sure it does not reside on the $WORLD_CONTAINER"
then javwc=`expr match "$dir" '.*\.[0-9][0-9]'` # Expression to filter out the world backups (ignore something ending with a number)
if [ -d "$dir" ] && [ -f "$ROOT_PATH/$WORLD_DIR/$dir/level.dat" ] && [ $javwc -eq 0 ] # Make sure it is a directory, and that it has a level.dat file in it, and the it IS NOT a backup
then
chown -R $USERNAME:$GROUPNAME "$ROOT_PATH/$WORLD_DIR/$dir"
if [ -d "$WORLD_CONTAINER/$dir" ] # Are there folders or symlinks already in $WORLD_CONTAINER?
then as_user "mv $WORLD_CONTAINER/$dir '$WORLD_CONTAINER/$dir'.old" # Rename them with the suffix ".old"
fi
as_user "ln -s $ROOT_PATH/$WORLD_DIR/$dir $WORLD_CONTAINER/$dir" # Setup the symlinks to the worlds in $WORLD_DIR
fi
fi
done
fi # Close if statement "running?"
}
#-------------------+
# Mount the ramdisk |
#-------------------+
# Checks status of ramdisk; if ramdisk mounted, notifies user and ends function.
# If the $ROOT_PATH/$RD_DIR doesn't exist, aborts the script.
# If $ROOT_PATH/$RD_DIR exists, mounts ramdisk in that directory as root.
# Gives ownership of data in ramdisk to $USERNAME and $GROUPNAME.
# If ramdisk fails to mount, aborts the script.
#-------------------+
mcrd_mount() {
if mount -l -t $RD_TYPE | grep $ROOT_PATH/$RD_DIR > /dev/null
then echo "Ramdisk already mounted!"
else
if [ ! -d $ROOT_PATH/$RD_DIR ]
then as_user "mkdir $ROOT_PATH/$RD_DIR"
fi
if [ ! -d $ROOT_PATH/$RD_DIR ]
then echo "Aborting service startup! $ROOT_PATH/$RD_DIR does not exist!" ; exit 1
else echo "Mounting ramdisk at $ROOT_PATH/$RD_DIR."
mount -t $RD_TYPE -o size=$RD_SIZE $RD_TYPE $ROOT_PATH/$RD_DIR
sleep 3
chown $USERNAME:$GROUPNAME $ROOT_PATH/$RD_DIR # Make sure that $USERNAME and members of $GROUPNAME can access the data in the ramdisk
fi
if mount -l -t $RD_TYPE | grep $ROOT_PATH/$RD_DIR > /dev/null
then echo "Ramdisk mounted at $ROOT_PATH/$RD_DIR."
else echo "Aborting service startup! Could not mount Ramdisk!" ; exit 1
fi
fi
}
#----------------------+
# Unmounts the ramdisk |
#----------------------+
# Checks if ramdisk is mounted at $ROOT_PATH/$RD_DIR.
# If ramdisk is mounted at $ROOT_PATH/$RD_DIR, attempts to unmount as root.
#----------------------+
mcrd_unmount() {
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null # Is service running?
then echo "Can't unmount ramdisk, $SERVICE is still running!"
elif [ "$mcrd_status" = "1" ]
then echo "Can't unmount ramdisk, ramdisk not unloaded!"
elif [ "$mcrd_status" = "0" ]
then
if mount -l -t $RD_TYPE | grep $ROOT_PATH/$RD_DIR > /dev/null
then echo "Ramdisk mounted at $ROOT_PATH/$RD_DIR. unmounting."
while mount -l -t $RD_TYPE | grep $ROOT_PATH/$RD_DIR > /dev/null
do
sleep 2
umount $ROOT_PATH/$RD_DIR
sleep 1
done
if [ ! "$(ls -A $ROOT_PATH/$RD_DIR)" ] # If $ROOT_PATH/$RD_DIR is empty remove it.
then as_user "rmdir $ROOT_PATH/$RD_DIR"
fi
echo "Ramdisk unmounted."
else echo "Ramdisk was not mounted at $ROOT_PATH/$RD_DIR."
fi
else echo "Could not unmount ramdisk."
fi
}
#---------------+
# Loads ramdisk |
#---------------+
# Checks status of service; if service is not running, attempts to load ramdisk.
# Loads all worlds in $WORLD_DIR into ramdisk under "worlds" directory.
# Appends ".old" to symbolic links in $WORLD_CONTAINER which point to $WORLD_DIR.
# Creates symbolic links to $RD_DIR/worlds in $WORLD_CONTAINER.
#---------------+
mcrd_load() {
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null # Is service running?
then echo "Cannot load ramdisk, $SERVICE is running! "
else echo "Loading ramdisk."
if [ ! -d "$ROOT_PATH/$RD_DIR/worlds" ]
then
as_user "mkdir $ROOT_PATH/$RD_DIR/worlds"
fi
cd $ROOT_PATH/$WORLD_DIR # If the world does exist, cd to $ROOT_PATH/$WORLD_DIR
for dir in * # For each folder in $ROOT_PATH/$WORLD_DIR,
do
if [ ! -d "$ROOT_PATH/$RD_DIR/worlds/$dir" ] # We are going to make sure it does not reside on the RAMDISK
then javwc=`expr match "$dir" '.*\.[0-9][0-9]'` # Expression to filter out the world backups (ignore something ending with a number)
if [ -d "$dir" ] && [ -f "$ROOT_PATH/$WORLD_DIR/$dir/level.dat" ] && [ $javwc -eq 0 ] # Make sure it is a directory, and that it has a level.dat file in it, and the it IS NOT a backup
then
cp -R $dir $ROOT_PATH/$RD_DIR/worlds # Copy the world from $ROOT_PATH/$WORLD_DIR to $ROOT_PATH/$RD_DIR
chown -R $USERNAME:$GROUPNAME $ROOT_PATH/$RD_DIR/worlds
if [ -d "$WORLD_CONTAINER/$dir" ] # Are there folders or symlinks already in $WORLD_CONTAINER?
then as_user "mv $WORLD_CONTAINER/$dir '$WORLD_CONTAINER/$dir'.old" # Rename them with the suffix ".old"
fi
as_user "ln -s $ROOT_PATH/$RD_DIR/worlds/$dir $WORLD_CONTAINER/$dir" # Setup the symlinks to the worlds on the RAMDISK
fi
fi
done
echo "Ramdisk Loaded."
fi # Close if statement "running?"
}
#-----------------+
# Unloads ramdisk |
#-----------------+
# Appends [date +"-%F-%H.%M"] to worlds in $WORLD_DIR
# Copies worlds from ramdisk back to $WORLD_DIR
# Deletes symbolic links in $WORLD_CONTAINER which point to worlds on ramdisk.
# Removes '.old' from symbolic links in $WORLD_CONTAINER which point to $WORLD_DIR.
#-----------------+
mcrd_unload() {
if mount -l -t $RD_TYPE | grep $ROOT_PATH/$RD_DIR > /dev/null # Check if the Ramdisk is mounted
then
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null # Is service running?
then echo "Can't unload ramdisk, $SERVICE is still running!"
mcrd_status="1" # Could not unload ramdisk, notify other functions of failure
else
if ls $ROOT_PATH/$RD_DIR/worlds/* | grep level.dat > /dev/null # Check if $WORLD_NAME (whatevere it was named in server.properties) exists in $ROOT_PATH/$RD_DIR
then echo "Saving ramdisk to disk." # Else we have found something and will continue with the regime, warn user we are beginning
cd $ROOT_PATH/$RD_DIR/worlds # Make sure we are in the $ROOT_PATH/$RD_DIR for the next series of commands
filedate=$(date +"-%F-%H.%M") # Set up our datestamp here.
for dir in * # For each directory inside $ROOT_PATH/$RD_DIR, we are going to perform the following series of commands
do
if [ -d "$dir" ] && [ -f "$dir/level.dat" ] # Make sure it is a directory and verify it is a world by looking for "level.dat" inside of it.
then
if [ -d "$ROOT_PATH/$WORLD_DIR/$dir" ] # Now we check to see if the world folder we found already exists in the $ROOT_PATH/$WORLD_DIR
then
echo "Renaming $dir to $dir$filedate" # We tell the user what we are going to do
as_user "mv $ROOT_PATH/$WORLD_DIR/$dir $ROOT_PATH/$WORLD_DIR/$dir$filedate" # Then rename the found folder with a datestamp on the end of it's name
fi
echo "$dir being copied to disk" # Tell the user we are copying the RAMDISK
as_user "cp -R $ROOT_PATH/$RD_DIR/worlds/$dir $ROOT_PATH/$WORLD_DIR" # Copy the world from $ROOT_PATH/$RD_DIR to $ROOT_PATH/$WORLD_DIR
else echo "Nothing copied from ramdisk." # If no world folders are found, we tell the user.
fi
done # END for loop (directory inside $ROOT_PATH/$RD_DIR)
else echo "Nothing in $ROOT_PATH/$RD_DIR to backup!" # Not found! Warn user!
fi
cd $WORLD_CONTAINER
for dir in *
do
if [ -d "$dir".old ] && [ -f "$dir/level.dat" ]
then
rm -rf $dir # Remove the links pointing to the world directories on the ramdisk
as_user "cd $WORLD_CONTAINER ; mv '$dir'.old $dir" # Remove ".old" from the name of the links pointing to the world directories on the hard disk
fi
done
mcrd_status="0" # Ramdisk successfully unloaded, notify other functions of success
fi
else echo "Nothing to save, ramdisk not mounted at $ROOT_PATH/$RD_DIR" # Service not running, nothing to save
fi
}
#---------------------+
# Commandline parsing |
#---------------------+
# start: Starts the service
# stop: Stops the service
# restart: Restarts the service (if not running, starts the service)
# status: Tells user whether service is running or not
# worldbackup: Runs a backup for worlds in either $WORLD_DIR or $RD_DIR/worlds
# rdbackup: Makes a backup of the entire $RD_DIR directory
#---------------------+
case "$1" in
start)
mc_start
touch $lockfile
;;
stop)
mc_stop
if [ $RAMDISK == 'true' ]
then
mcrd_unload
mcrd_unmount
fi
rm -f $lockfile
;;
restart)
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $RESTART_MSG\"\015'"
mc_stop
mc_start
else
echo "$SERVICE was not running. "
mc_start
fi
;;
status)
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then echo "$SERVICE is running."
else echo "$SERVICE is not running."
fi
;;
backup)
case "$2" in
worlds)
DATE=$(date "+%Y-%m-%d")
TIME=$(date "+%H-%M")
REF_BUDIR="$WORLD_DIR"
CS_PATH="$ROOT_BUPATH/chksum/$WORLD_DIR"
REF_PATH="$ROOT_PATH/$WORLD_DIR"
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $BACKUP_START_MSG\"\015'"
fi
mc_saveoff
backup
backup_cksum
mc_saveon
;;
ramdisk)
DATE=$(date "+%Y-%m-%d")
TIME=$(date "+%H-%M")
REF_BUDIR="$RD_DIR"
CS_PATH="$ROOT_BUPATH/chksum/$RD_DIR"
REF_PATH="$ROOT_PATH/$RD_DIR"
if ps -U $USERNAME x | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $BACKUP_RD_START_MSG\"\015'"
fi
if mount -l -t $RD_TYPE | grep $ROOT_PATH/$RD_DIR > /dev/null
then
mc_saveoff
backup
backup_cksum
mc_saveon
else echo "Ramdisk not mounted, nothing to do."
fi
;;
*)
echo ""
echo "Usage /etc/init.d/minecraft backup {worlds|ramdisk}"
echo ""
echo "Backup options:"
echo ""
echo " worlds - Backs up worlds to backup directory"
echo " ramdisk - Backs up entire ramdisk directory to backup directory"
echo ""
exit 1
;;
esac
;;
*)
echo ""
echo "Usage: /etc/init.d/minecraft {start|stop|restart|status|backup [option]}"
echo ""
echo "Start - Starts the Minecraft server"
echo "Stop - Stops the Minecraft server (Unmounts ramdisk if enabled)"
echo "Restart - Restarts the Minecraft server (Doesn't unmount ramdisk)"
echo "Status - Displays status of the Minecraft server (Running or not)"
echo "Backup - Backs up data to the backup directory"
echo ""
echo "Backup options:"
echo ""
echo " worlds - Backs up worlds to backup directory"
echo " ramdisk - Backs up entire ramdisk directory to backup directory"
echo ""
exit 1
;;
esac
exit 0