Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- #!/bin/bash
- #
- #
- ### BEGIN INIT INFO
- #
- # Provides: Minecraft StartScript v1.0
- #
- # Required-Start: $remote_fs $syslog
- #
- # Required-Stop: $remote_fs $syslog
- #
- # Default-Start: 2 3 4 5
- #
- # Default-Stop: 0 1 6
- #
- # Short-Description: Starts the minecraft server
- #
- # Description: Starts the minecraft server specified below. You can also create a cron job to sceduele restarts of your minecraft server (recommended).
- #
- ### END INIT INFO
- #
- #
- ########################
- #
- #
- #
- # Minecraft StartScript v1.0
- #
- # Copyright (C) 2011 by Silthus
- #
- #
- #
- #########################################
- #
- #
- #
- ###################
- #
- # CONFIGURATION #
- #
- #########################################
- #
- # NAME: user to start Minecraft from (dont run as root (u wont be able to anyways!))
- #
- # PATH: directory containing the Minecraft Server File (= working directory) (needs / at the end)
- #
- # BIN: your server executable, e.g.: minecraft_server.jar
- #
- # ID: a unique identifier for this screen session (like servers name)
- #
- # must be different for every server
- #
- #
- #
- # To restart your server every 6 hours at midnight, 6, 12 and 6 o clock put this line in your crontab:
- #
- # # Minute Hour Day of Month Month Day of Week Command
- #
- # (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
- #
- # 0 0,6,12,18 * * * /etc/init.d/minecraft restart
- #
- #
- #
- #
- NAME='minecraft'
- #
- PATH='/home/minecraft/bin/'
- #
- BIN='craftbukkit.jar'
- #
- ID='RaidCraft'
- #
- PARAMS='-Xms512M -Xmx2048M'
- #
- #
- #
- ############################
- #
- # ADVANCED CONFIGURATION #
- #
- #########################################
- #
- #
- # in case you have custom application paths, edit here
- #
- GREP='/bin/grep'
- #
- SCREEN='/usr/bin/screen'
- #
- JAVA='/usr/bin/java'
- #
- SLEEP='/bin/sleep'
- #
- #
- # colors: default, red, green, yellow, blue
- #
- D='\E[0m'
- #
- R='\E[1;31m'
- #
- G='\E[1;32m'
- #
- Y='\E[1;33m'
- #
- B='\E[1;34m'
- #
- #
- #
- ################################################
- #
- # do not edit below here #
- #
- # unless you REALLY know what you are doing !! #
- #
- ################################################
- #
- #
- #
- echo -e "\E[1;34;40m Minecraft StartScript ${Y}v1.0 ${B}by ${G}Silthus${D}"
- #
- #
- # check dependencies
- #
- if [ ! -x "$GREP" ]; then
- #
- echo -e "${R}Error: grep not found in ${B}'$GREP$'${D}"
- #
- echo -e "${Y}Install with your packet manager or edit advanced config!${D}"
- #
- exit 1
- #
- fi
- #
- if [ ! -x "$SCREEN" ]; then
- #
- echo -e "${R}Error: screen not found in ${B}'$SCREEN'${D}"
- #
- echo -e "${Y}Install with your packet manager or edit advanced config!${D}"
- #
- exit 1
- #
- fi
- #
- if [ ! -x "$JAVA" ]; then
- #
- echo -e "${R}Error: java not found in ${B}'$JAVA$'${D}"
- #
- echo -e "${Y}Install with your packet manager or edit advanced config!${D}"
- #
- exit 1
- #
- fi
- #
- if [ ! -x "$SLEEP" ]; then
- #
- echo -e "${R}Error: sleep not found in ${B}'$SLEEP$'${D}"
- #
- echo -e "${Y}Install with your packet manager or edit advanced config!${D}"
- #
- exit 1
- #
- fi
- #
- #
- # check for root permission
- #
- if [ $UID = 0 ]; then
- #
- ROOT=true
- #
- echo -e "${R}Do not run as ROOT!${D}"
- #
- exit 1
- #
- else
- #
- ROOT=false
- #
- fi
- #
- #
- cd $PATH
- #
- #
- #
- ###############
- #
- # functions #
- #
- #########################################
- #
- #
- start() {
- #
- echo -e "${Y}Starting ${B}$ID ${Y}...${D}"
- #
- #
- if status; then
- #
- echo -e "${R}Error: ${B}$ID ${R}is already running!${D}"
- #
- exit 1
- #
- fi
- #
- $SCREEN -AmdS $ID $JAVA $PARAMS -jar $BIN nogui
- #
- }
- #
- #
- stop() {
- #
- echo -e "${Y}Stopping ${B}$ID ${Y}...${D}"
- #
- #
- if ! status; then
- #
- echo -e "${R}Error: ${B}$ID ${R}is not running!${D}"
- #
- exit 1
- #
- fi
- #
- $SCREEN -S $ID -p 0 -X stuff "`printf "say Going down in 10 seconds! Saving world...\r"`"
- #
- echo -e "${B}Waiting 10 seconds for the World to save ...${D}"
- #
- $SLEEP 5
- #
- $SCREEN -S $ID -p 0 -X stuff "`printf "save-all\r"`"
- #
- $SLEEP 5
- #
- $SCREEN -S $ID -p 0 -X stuff "`printf "stop\r"`"
- #
- echo -e "${G}Shutting down ...${D}"
- #
- $SLEEP 2
- #
- }
- #
- #
- status() {
- #
- $SCREEN -ls | $GREP [.]$ID[[:space:]] > /dev/null
- #
- }
- #
- #
- attach() {
- #
- if ! status; then
- #
- echo -e "${R}Error: ${B}$ID ${R}is not running!${D}"
- #
- exit 1
- #
- fi
- #
- $SCREEN -S $ID -r
- #
- }
- #
- #
- #
- # parameter parsing
- #
- case "$1" in
- #
- start)
- #
- start
- #
- echo -e "${G} ... done.${D}"
- #
- ;;
- #
- #
- stop)
- #
- stop
- #
- echo -e "${G} ... done.${D}"
- #
- ;;
- #
- #
- restart)
- #
- status
- #
- $SCREEN -S $ID -p 0 -X stuff "`printf "say Restarting in 10 seconds! Saving world...\r"`"
- #
- echo -e "${B}Waiting 10 seconds for the World to save ...${D}"
- #
- $SLEEP 5
- #
- $SCREEN -S $ID -p 0 -X stuff "`printf "save-all\r"`"
- #
- $SLEEP 5
- #
- $SCREEN -S $ID -p 0 -X stuff "`printf "stop\r"`"
- #
- echo -e "${B}Waiting 10 seconds for the RAM to clear ...${D}"
- #
- $SLEEP 10
- #
- start
- #
- ;;
- #
- #
- status)
- #
- if status; then
- #
- echo -e "${B}$ID ${G}is running ${B}${D}"
- #
- else
- #
- echo -e "${B}$ID ${R}is not running!${D}"
- #
- fi
- #
- ;;
- #
- #
- attach)
- #
- attach
- #
- ;;
- #
- #
- *)
- #
- echo -e "${Y}Usage: $0 {${G}start${Y}|${R}stop${Y}|${B}restart${Y}|${B}status${Y}|${B}attach${Y}} ${Y}[ID]${D}"
- #
- echo -e "${Y}While attached press ${B}ctrl-a crlt-d ${Y}to stop watching without stopping the server!"
- #
- exit 1
- #
- ;;
- #
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement