Guest User

Untitled

a guest
Jan 12th, 2012
164
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # /etc/init.d/minecraft
  3. # version 0.4.2 2012-01-08 (YYYY-MM-DD)
  4.  
  5. ### BEGIN INIT INFO
  6. # Provides: minecraft
  7. # Required-Start: $local_fs $remote_fs
  8. # Required-Stop: $local_fs $remote_fs
  9. # Should-Start: $network
  10. # Should-Stop: $network
  11. # Default-Start: 2 3 4 5
  12. # Default-Stop: 0 1 6
  13. # Short-Description: Minecraft server
  14. # Description: Starts the minecraft server
  15. ### END INIT INFO
  16.  
  17. # chkconfig 2345 99 01
  18.  
  19. # Codecraft-init-script: Linux init script for starting minecraft as a service
  20. # Copyright (C) 2011-2012 Daniel Hodgson, William Haggerty, Codeprogrammers
  21. #
  22. # This program is free software; you can redistribute it and/or
  23. # modify it under the terms of the GNU General Public License
  24. # as published by the Free Software Foundation; either version 2
  25. # of the License, or (at your option) any later version.
  26. #
  27. # This program is distributed in the hope that it will be useful,
  28. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. # GNU General Public License for more details.
  31. #
  32. # You should have received a copy of the GNU General Public License
  33. # along with this program; if not, write to the Free Software
  34. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  35.  
  36. #Settings
  37. USERNAME="root"
  38. GROUPNAME="root"
  39. SCREEN_NAME="mc"
  40. BUILD=""
  41. SERVICE="craftbukkit.jar"
  42. INVOCATION="java -server -Xmx2G -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=2 -XX:+AggressiveOpts -jar craftbukkit-1.0.1-R1_r1.jar nogui"
  43. RAMDISK="false"
  44.  
  45. #File Paths/Names
  46. ROOT_PATH="/root"
  47. WORLD_DIR="worlds"
  48. SERVER_DIR="mc"
  49. RD_DIR="ramdisk"
  50. ROOT_BUPATH="$ROOT_PATH/archives"
  51.  
  52. #Messages (sent to minecraft server console with "say" command)
  53. SAVE_OFF_MSG="Serwer off..."
  54. SAVE_ON_MSG="Serwer on..."
  55. BACKUP_START_MSG="POCZATEK BACKUPU"
  56. BACKUP_RD_START_MSG="POCZATEK BACKUPU RAMDYSKU"
  57. BACKUP_DONE_MSG="BACKUP SERWERA SKONCZONY"
  58. BACKUP_FAIL_MSG="BACKUP SERWERA SIE NIE POWIODL"
  59. STOP_MSG="SERWER WYLACZT SIE ZA 15 SEKUND"
  60. RESTART_MSG="SERWER SIE RESTARTUJE"
  61.  
  62. ############################[ Script Start]#############################
  63.  
  64. lockfile="/var/lock/minecraft"
  65.  
  66. #Grabbing world name from $MC_PATH/server.properties
  67. WORLD_NAME=$(cat $ROOT_PATH/$SERVER_DIR/server.properties | fgrep 'level-name=' | sed -e s/.*level-name=//)
  68.  
  69. #Run commands as the user defined in the $USERNAME variable
  70. ME=`whoami`
  71. as_user() {
  72. if [ $ME == $USERNAME ]
  73. then
  74. bash -c "$1"
  75. else
  76. su - $USERNAME -c "$1"
  77. fi
  78. }
  79.  
  80.  
  81. #--------------------+
  82. # Starts the service |
  83. #--------------------+
  84. # If the service is already running, will alert the user and end the function.
  85. # If ramdisk feature is enabled, will attempt to mount and load the ramdisk.
  86. # If the service fails to start, and ramdisk feature is enabled, will attempt
  87. #+ to unload the ramdisk and unmount it.
  88. #--------------------+
  89.  
  90. mc_start() {
  91. if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
  92. then echo "Tried to start but $SERVICE was already running!"
  93. else echo "Starting $SERVICE"
  94.  
  95. if [ $RAMDISK == 'true' ]
  96. then
  97. if mount -l -t tmpfs | grep $ROOT_PATH/$RD_DIR > /dev/null
  98. then echo "Ramdisk Loaded"
  99. mcrd_load
  100. else echo "Loading Ramdisk"
  101. mcrd_mount
  102. mcrd_load
  103. fi
  104. fi
  105.  
  106. as_user "cd $ROOT_PATH/$SERVER_DIR && screen -dmS $SCREEN_NAME $INVOCATION" ; sleep 7
  107.  
  108. #Check to see if the service started successfully
  109. if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
  110. then echo "$SERVICE is now running."
  111. else echo "Could not start $SERVICE."
  112.  
  113. if [ $RAMDISK == 'true' ]
  114. then
  115. if mount -l -t tmpfs | grep $ROOT_PATH/$RD_DIR > /dev/null
  116. then echo "Unloading Ramdisk."
  117. mcrd_unload
  118. mcrd_unmount
  119. else echo "Ramdisk already unloaded!"
  120. fi
  121. fi
  122.  
  123. fi
  124. fi
  125. }
  126.  
  127.  
  128. #-------------------+
  129. # Stops the service |
  130. #-------------------+
  131. # Sends notice of impending shutdown as message to minecraft/bukkit console.
  132. # Notifies user if service fails to stop.
  133. #-------------------+
  134.  
  135. mc_stop() {
  136. if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
  137. then echo "$SERVICE is running... stopping."
  138.  
  139. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $STOP_MSG\"\015'" ; sleep 5
  140. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"save-all\"\015'" ; sleep 10
  141. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"stop\"\015'" ; sleep 3
  142.  
  143. else echo "$SERVICE was not running."
  144. fi
  145.  
  146. if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
  147. then echo "$SERVICE could not be shut down... still running."
  148. else echo "$SERVICE is shut down."
  149. fi
  150. }
  151.  
  152.  
  153. #----------------------+
  154. # Disables auto-saving |
  155. #----------------------+
  156. # Sends notice of disablement of auto-saving as message to minecraft/bukkit console.
  157. # Turns off automatic saving.
  158. # Saves all in-game changes and syncs to disk.
  159. #----------------------+
  160.  
  161. mc_saveoff() {
  162. if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
  163. then echo "$SERVICE is running... suspending saves"
  164.  
  165. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $SAVE_OFF_MSG\"\015'"
  166. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"save-off\"\015'"
  167. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"save-all\"\015'"
  168. sync ; sleep 5
  169.  
  170. else echo "$SERVICE was not running. Not suspending saves."
  171. fi
  172. }
  173.  
  174.  
  175. #---------------------+
  176. # Enables auto-saving |
  177. #---------------------+
  178. # Turns on automatic saving.
  179. # Sends notice of enablement of auto-saving as message to minecraft/bukkit console.
  180. #---------------------+
  181.  
  182. mc_saveon() {
  183. if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
  184. then echo "$SERVICE is running... re-enabling saves"
  185.  
  186. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"save-on\"\015'"
  187. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $SAVE_ON_MSG\"\015'"
  188.  
  189. else echo "$SERVICE was not running. Not resuming saves."
  190. fi
  191. }
  192.  
  193.  
  194. #-----------------------------+
  195. # Backup files from $REF_PATH |
  196. #-----------------------------+
  197. # Creates directory tree for backups if it doesn't exist.
  198. # Copies files from $REF_PATH into $REF_BUDIR.
  199. #-----------------------------+
  200.  
  201. backup() {
  202. echo "Backing Up $REF_BUDIR"
  203. cd $ROOT_BUPATH
  204.  
  205. if [ ! -d $REF_BUDIR ]
  206. then
  207. as_user "mkdir $ROOT_BUPATH/$REF_BUDIR"
  208. cd $REF_BUDIR
  209. else
  210. cd $REF_BUDIR
  211. fi
  212.  
  213. # Check for directories with the current datestamp
  214. if ls | grep $DATE > /dev/null
  215. then
  216. cd $DATE
  217. else
  218. as_user "mkdir $ROOT_BUPATH/$REF_BUDIR/$DATE"
  219. cd $DATE
  220. fi
  221.  
  222. # Check for directories with the curent timestamp.
  223. if ls | grep $TIME > /dev/null
  224. then
  225. TIME="$TIME"_`date "+%S"` # Appened the current seconds time to $bu_time
  226. as_user "mkdir $ROOT_BUPATH/$REF_BUDIR/$DATE/$TIME"
  227. as_user "cp -a $REF_PATH/* $ROOT_BUPATH/$REF_BUDIR/$DATE/$TIME"
  228. else
  229. as_user "mkdir $ROOT_BUPATH/$REF_BUDIR/$DATE/$TIME"
  230. as_user "cp -a $REF_PATH/* $ROOT_BUPATH/$REF_BUDIR/$DATE/$TIME"
  231. fi
  232.  
  233. echo "Backup finished"
  234. }
  235.  
  236.  
  237. #------------------------+
  238. # Check backup integrity |
  239. #------------------------+
  240. # Creat directory tree for checksums if it doesn't exist.
  241. # Tarballs reference files and backup files.
  242. # Runs a checksum of the two tarballs seperately.
  243. # Compares the checksums to check intergrity of backup.
  244. #------------------------+
  245.  
  246. backup_cksum() {
  247.  
  248. echo "Running checksum..."
  249. cd $ROOT_BUPATH
  250.  
  251. if [ -d chksum ]
  252. then cd chksum
  253.  
  254. if [ -d $REF_BUDIR ] # $REF_CSPATH = $ROOT_BUPATH/chksum/$REF_BUDIR. Since it seems as though we need to
  255. then cd $REF_BUDIR #+ use asbolute paths, we might as well make another variable to lighten the load.
  256.  
  257. if [ -d reference ]
  258. then
  259. rm -rf reference
  260. as_user "mkdir $REF_CSPATH/reference"
  261. else
  262. as_user "mkdir $REF_CSPATH/reference"
  263. fi
  264.  
  265. if [ -d backup ]
  266. then
  267. rm -rf backup
  268. as_user "mkdir $REF_CSPATH/backup"
  269. else
  270. as_user "mkdir $REF_CSPATH/backup"
  271. fi
  272.  
  273. else
  274. as_user "mkdir $REF_CSPATH ; cd $REF_CSPATH"
  275. as_user "mkdir $REF_CSPATH/reference ; mkdir $REF_CSPATH/backup"
  276. fi
  277.  
  278. else
  279. as_user "mkdir $ROOT_BUPATH/chksum ; cd $ROOT_BUPATH/chksum"
  280. as_user "mkdir $REF_CSPATH ; cd $REF_CSPATH"
  281. as_user "mkdir $REF_CSPATH/reference ; mkdir $REF_CSPATH/backup"
  282. fi
  283.  
  284. as_user "cd $REF_PATH ; tar -cf checksum.tar *"
  285. as_user "mv $REF_PATH/checksum.tar $REF_CSPATH/reference"
  286.  
  287. as_user "cd $ROOT_BUPATH/$REF_BUDIR/$DATE/$TIME ; tar -cf checksum.tar *"
  288. as_user "mv $ROOT_BUPATH/$REF_BUDIR/$DATE/$TIME/checksum.tar $REF_CSPATH/backup"
  289.  
  290. cd $REF_CSPATH
  291. REF_checksum=$(ls reference | cksum) # Set $REF_checksum to the value of the checksum of the current worlds' tarball
  292. BACKUP_checksum=$(ls backup | cksum) # Set $BACKUP_checksum to the value of the checksum of the newest backup's tarball
  293.  
  294.  
  295. # Compare the values of the checksums
  296. if [ "$REF_checksum" = "$BACKUP_checksum" ]
  297. then
  298. echo "Backup Successful"
  299. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $BACKUP_DONE_MSG\"\015'"
  300. else
  301. echo "Backup failed! The reference and backup contents do not match!"
  302. echo "Worlds: $REF_checksum" ; echo "Backup: $BACKUP_checksum"
  303. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $BACKUP_FAIL_MSG\"\015'"
  304. fi
  305.  
  306. }
  307.  
  308.  
  309. #-------------------+
  310. # Mount the ramdisk |
  311. #-------------------+
  312. # Checks status of ramdisk; if ramdisk mounted, notifies user and ends function.
  313. # If the $ROOT_PATH/$RD_DIR doesn't exist, aborts the script.
  314. # If $ROOT_PATH/$RD_DIR exists, mounts ramdisk in that directory as root.
  315. # Gives ownership of data in ramdisk to $USERNAME and $GROUPNAME.
  316. # If ramdisk fails to mount, aborts the script.
  317. #-------------------+
  318.  
  319. # Will probably add later the ability to make $ROOT_PATH/$RD_DIR if it doesn't exist
  320.  
  321. mcrd_mount() {
  322. if mount -l -t tmpfs | grep $ROOT_PATH/$RD_DIR > /dev/null
  323. then echo "Ramdisk already mounted"
  324. else
  325.  
  326. if [ ! -d $ROOT_PATH/$RD_DIR ]
  327. then echo "Aborting service startup! $ROOT_PATH/$RD_DIR does not exist!" ; exit 1
  328. else echo "Mounting ramdisk at $ROOT_PATH/$RD_DIR"
  329. mount -t tmpfs -o size=$RD_SIZE tmpfs $ROOT_PATH/$RD_DIR
  330. sleep 3
  331. chown $USERNAME:$GROUPNAME $ROOT_PATH/$RD_DIR # Make sure that $USERNAME and members of $GROUPNAME can access the data in the ramdisk
  332. fi
  333.  
  334. if mount -l -t tmpfs | grep $ROOT_PATH/$RD_DIR > /dev/null
  335. then echo "Ramdisk mounted at $ROOT_PATH/$RD_DIR"
  336. else echo "Aborting service startup! Could not mount Ramdisk!" ; exit 1
  337. fi
  338. fi
  339. }
  340.  
  341.  
  342. #----------------------+
  343. # Unmounts the ramdisk |
  344. #----------------------+
  345. # Checks if ramdisk is mounted at $ROOT_PATH/$RD_DIR.
  346. # If ramdisk is mounted at $ROOT_PATH/$RD_DIR, attempts to unmount as root.
  347. #----------------------+
  348.  
  349. mcrd_unmount() {
  350. if mount -l -t tmpfs | grep $ROOT_PATH/$RD_DIR > /dev/null
  351. then echo "Ramdisk mounted at $ROOT_PATH/$RD_DIR.... unmounting"
  352. umount $ROOT_PATH/$RD_DIR
  353. sleep 3
  354. else echo "Ramdisk was not mounted at $ROOT_PATH/$RD_DIR"
  355. fi
  356.  
  357. if mount -l -t tmpfs | grep $ROOT_PATH/$RD_DIR > /dev/null
  358. then echo "Could not unmount ramdisk at $ROOT_PATH/$RD_DIR"
  359. else echo "Ramdisk unmounted"
  360. fi
  361. }
  362.  
  363.  
  364. #---------------+
  365. # Loads ramdisk |
  366. #---------------+
  367. # Checks status of service; if service is not running, attempts to load ramdisk.
  368. # Loads all worlds in $WORLD_DIR into ramdisk under "worlds" directory.
  369. # Appends ".old" to symbolic links in $SERVER_DIR which point to $WORLD_DIR.
  370. # Creates symbolic links to $RD_DIR/worlds in $SERVER_DIR.
  371. #---------------+
  372.  
  373. mcrd_load() {
  374. if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null # Is service running?
  375. then echo "Cannot load ramdisk, $SERVICE is running! "
  376. else echo "Loading ramdisk..."
  377.  
  378. if [ ! -d "$ROOT_PATH/$RD_DIR/worlds" ]
  379. then
  380. as_user "mkdir $ROOT_PATH/$RD_DIR/worlds"
  381. fi
  382.  
  383. if [ ! -d "$ROOT_PATH/$WORLD_DIR/$WORLD_NAME" ] # Checking for the existance of a world using the name defined in server.properties
  384. then echo "$WORLD_NAME is not in $ROOT_PATH/$WORLD_DIR !" # If no world exists, tell the user
  385. else cd $ROOT_PATH/$WORLD_DIR # If the world does exist, cd to $ROOT_PATH/$WORLD_DIR
  386.  
  387. for dir in * # For each folder in $ROOT_PATH/$WORLD_DIR,
  388. do
  389.  
  390. if [ ! -d "$ROOT_PATH/$RD_DIR/worlds/$dir" ] # We are going to make sure it does not reside on the RAMDISK
  391. then javwc=`expr match "$dir" '.*[0-9]'` # Expression to filter out the world backups (ignore something ending with a number)
  392.  
  393. 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
  394. then
  395. cp -R $dir $ROOT_PATH/$RD_DIR/worlds # Copy the world from $ROOT_PATH/$WORLD_DIR to $ROOT_PATH/$RD_DIR
  396. chown -R $USERNAME:$GROUPNAME $ROOT_PATH/$RD_DIR/worlds
  397.  
  398. if [ -d "$ROOT_PATH/$SERVER_DIR/$dir" ] # Are there folders or symlinks already in $ROOT_PATH/$SERVER_DIR?
  399. then as_user "mv $ROOT_PATH/$SERVER_DIR/$dir '$ROOT_PATH/$SERVER_DIR/$dir'.old" # Rename them with the suffix ".old"
  400. fi
  401. as_user "ln -s $ROOT_PATH/$RD_DIR/worlds/$dir $ROOT_PATH/$SERVER_DIR/$dir" # Setup the symlinks to the worlds on the RAMDISK
  402.  
  403. fi
  404. fi
  405. done
  406. fi # Close if statement "world exist?"
  407. fi # Close if statement "running?"
  408. }
  409.  
  410.  
  411. #-----------------+
  412. # Unloads ramdisk |
  413. #-----------------+
  414. # Appends [date +"-%F-%H.%M"] to worlds in $WORLD_DIR
  415. # Copies worlds from ramdisk back to $WORLD_DIR
  416. # Deletes symbolic links in $SERVER_DIR which point to worlds on ramdisk.
  417. # Removes '.old' from symbolic links in $SERVER_DIR which point to $WORLD_DIR.
  418. #-----------------+
  419.  
  420. mcrd_unload() {
  421. if mount -l -t tmpfs | grep $ROOT_PATH/$RD_DIR > /dev/null # Check if the Ramdisk is mounted
  422. then
  423.  
  424. if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null # Is service running?
  425. then echo "Can't unload ramdisk, $SERVICE is still running!"
  426. else
  427.  
  428. if [ ! -d "$ROOT_PATH/$RD_DIR/worlds/$WORLD_NAME" ] # Check if $WORLD_NAME (whatevere it was named in server.properties) exists in $ROOT_PATH/$RD_DIR
  429. then echo "Nothing in $ROOT_PATH/$RD_DIR to backup!" # Not found! Warn user!
  430. else echo "Saving ramdisk to disk." # Else we have found something and will continue with the regime, warn user we are beginning
  431.  
  432. cd $ROOT_PATH/$RD_DIR/worlds # Make sure we are in the $ROOT_PATH/$RD_DIR for the next series of commands
  433. filedate=$(date +"-%F-%H.%M") # Set up our datestamp here.
  434.  
  435. for dir in * # For each directory inside $ROOT_PATH/$RD_DIR, we are going to perform the following series of commands
  436. do
  437.  
  438. if [ -d "$dir" ] && [ -f "$dir/level.dat" ] # Make sure it is a directory and verify itis a world by looking for "level.dat" inside of it.
  439. then
  440.  
  441. 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
  442. then
  443. echo "Renaming $dir to $dir$filedate" # We tell the user what we are going to do
  444. 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
  445. fi
  446.  
  447. echo "$dir being copied to disk" # Tell the user we are copying the RAMDISK
  448. 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
  449.  
  450. else echo "Nothing copied from ramdisk." # If no world folders are found, we tell the user.
  451. fi
  452.  
  453. done # END for loop (directory inside $ROOT_PATH/$RD_DIR)
  454. fi
  455.  
  456. cd $ROOT_PATH/$SERVER_DIR
  457.  
  458. for dir in *
  459. do
  460. if [ -d "$dir".old ] && [ -f "$dir/level.dat" ]
  461. then
  462. rm -rf $dir # Remove the links pointing to the world directories on the ramdisk
  463. as_user "cd $ROOT_PATH/$SERVER_DIR ; mv '$dir'.old $dir" # Remove ".old" from the name of the links pointing to the world directories on the hard disk
  464. fi
  465. done
  466.  
  467. fi
  468.  
  469. else echo "Nothing to save, ramdisk not mounted at $ROOT_PATH/$RD_DIR" # Service not running, nothing to save
  470. fi
  471. }
  472.  
  473.  
  474. #---------------------+
  475. # Commandline parsing |
  476. #---------------------+
  477. # start: Starts the service
  478. # stop: Stops the service
  479. # restart: Restarts the service (if not running, starts the service)
  480. # status: Tells user whether service is running or not
  481. # worldbackup: Runs a backup for worlds in either $WORLD_DIR or $RD_DIR/worlds
  482. # rdbackup: Makes a backup of the entire $RD_DIR directory
  483. #---------------------+
  484.  
  485. case "$1" in
  486. start)
  487. mc_start
  488. touch $lockfile
  489. ;;
  490.  
  491. stop)
  492. mc_stop
  493. if [ $RAMDISK == 'true' ]
  494. then
  495. mcrd_unload
  496. mcrd_unmount
  497. fi
  498. rm -f $lockfile
  499. ;;
  500.  
  501. restart)
  502. if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
  503. then
  504. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $RESTART_MSG\"\015'"
  505. mc_stop
  506. mc_start
  507. else
  508. echo "$SERVICE was not running... "
  509. mc_start
  510. fi
  511. ;;
  512.  
  513. status)
  514. if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
  515. then echo "$SERVICE is running."
  516. else echo "$SERVICE is not running."
  517. fi
  518. ;;
  519.  
  520. worldbackup)
  521. DATE=$(date "+%Y-%m-%d")
  522. TIME=$(date "+%H-%M")
  523. REF_BUDIR="$WORLD_DIR"
  524. REF_CSPATH="$ROOT_BUPATH/chksum/$WORLD_DIR"
  525. if [ $RAMDISK == 'true' ] && mount -l -t tmpfs | grep $ROOT_PATH/$RD_DIR > /dev/null
  526. then REF_PATH="$ROOT_PATH/$RD_DIR/worlds"
  527. else REF_PATH="$ROOT_PATH/$WORLD_DIR"
  528. fi
  529.  
  530. if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
  531. then
  532. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $BACKUP_START_MSG\"\015'"
  533. fi
  534.  
  535. mc_saveoff
  536. backup
  537. backup_cksum
  538. mc_saveon
  539. ;;
  540.  
  541. rdbackup)
  542. DATE=$(date "+%Y-%m-%d")
  543. TIME=$(date "+%H-%M")
  544. REF_BUDIR="$RD_DIR"
  545. REF_CSPATH="$ROOT_BUPATH/chksum/$RD_DIR"
  546. REF_PATH="$ROOT_PATH/$RD_DIR"
  547. if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
  548. then
  549. as_user "screen -p 0 -S $SCREEN_NAME -X eval 'stuff \"say $BACKUP_RD_START_MSG\"\015'"
  550. fi
  551.  
  552. if mount -l -t tmpfs | grep $ROOT_PATH/$RD_DIR > /dev/null
  553. then
  554. mc_saveoff
  555. backup
  556. backup_cksum
  557. mc_saveon
  558. else echo "Ramdisk not mounted, nothing to do."
  559. fi
  560. ;;
  561.  
  562. *)
  563. echo "Usage: /etc/init.d/minecraft {start|stop|restart|status|worldbackup|rdbackup}"
  564. exit 1
  565. ;;
  566. esac
  567.  
  568. exit 0
RAW Paste Data