GithubHelp home page GithubHelp logo

minecraft-init's Introduction

Init script for minecraft/bukkit servers

A init script that apart from starting and stopping the server correctly also has some extra features for running a mincraft/craftbukkit server.

Features

  • Utilization of ramdisk for world data, decreases lag when getting world chunks
  • Cleaning of server.log, a big log file slows down the server
  • Backup for worlds
  • Server updating and complete backup
  • Exclude files and directories from full backup by adding them to "exclude.list"

Requirements

screen, rsync

Access server console

screen -r minecraft

Exit the console

Ctrl+A D

Setup

  1. Symlink the minecraft file to /etc/init.d/minecraft, set the required premissions and update rc.d.

     sudo ln -s ~/minecraft-init/minecraft /etc/init.d/minecraft
     chmod 755  ~/minecraft-init/minecraft
     sudo update-rc.d minecraft defaults
    
  2. Edit the variables in config.example to your needs and rename it to config (leaving it in the same folder as the original minecraft script)

  3. Move your worlds to the folder specified by WORLDSTORAGE

  4. Edit crontab

    As the server user:

     crontab -e
    

    Add these lines:

     #m 	h 	dom	mon	dow	command
     02 	05 	*	*	*	/etc/init.d/minecraft backup
     55 	04 	*	*	*	/etc/init.d/minecraft log-roll
     */30 	* 	*	*	*	/etc/init.d/minecraft to-disk
    
  5. To load a world from ramdisk run:

     /etc/init.d/minecraft ramdisk WORLDNAME
    

    to disable ramdisk, run the same command again.

For more help with the script, run

/etc/init.d/minecraft help

Flattr this git repo

Good stuff

Backup rotation script good if you want some kind or rolling of the world backups.

minecraft-init's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minecraft-init's Issues

Seems like this script needs some updating....

Hey, thanks a ton for the script. Its been great since i started using it. BUT, with the release of MC 1.0, it seems there should be some updates to the script. Worlds are handled differently, etc.
Also, i was hoping to recommend that you add a feature to group world backups in folder according to their dates. At the moment they are all clustered in 1 folder, and for me who has the backup run hourly, the folder is getting to be huge. It would be great if it could group them into folders by their date. Thanks!

Worldgaurd not workign at all

When I run Bukkit RB from your script and attempt to define a new area (In WorldGaurd) I get several errors in the console

2012-05-29 09:05:30 [SEVERE] [WorldGuard] Error loading regions for world "Town": java.io.FileNotFoundException: /home/nick/mc/plugins/WorldGuard/worlds/Town/regions.yml
/home/nick/mc/plugins/WorldGuard/worlds/Town/regions.yml
2012-05-29 09:05:30 [SEVERE] java.io.FileNotFoundException: /home/nick/mc/plugins/WorldGuard/worlds/Town/regions.yml
2012-05-29 09:05:30 [SEVERE] at com.sk89q.worldguard.protection.databases.YAMLDatabase.(YAMLDatabase.java:60)
2012-05-29 09:05:30 [SEVERE] at com.sk89q.worldguard.protection.GlobalRegionManager.load(GlobalRegionManager.java:142)
2012-05-29 09:05:30 [SEVERE] at com.sk89q.worldguard.protection.GlobalRegionManager.get(GlobalRegionManager.java:229)
2012-05-29 09:05:30 [SEVERE] at com.sk89q.worldguard.bukkit.FlagStateManager.run(FlagStateManager.java:86)
2012-05-29 09:05:30 [SEVERE] at org.bukkit.craftbukkit.scheduler.CraftWorker.run(CraftWorker.java:34)
2012-05-29 09:05:30 [SEVERE] at java.lang.Thread.run(Thread.java:679)
2012-05-29 09:05:30 [SEVERE] java.lang.NullPointerException
2012-05-29 09:05:30 [SEVERE] at com.sk89q.worldguard.bukkit.FlagStateManager.run(FlagStateManager.java:88)
2012-05-29 09:05:30 [SEVERE] at org.bukkit.craftbukkit.scheduler.CraftWorker.run(CraftWorker.java:34)
2012-05-29 09:05:30 [SEVERE] at java.lang.Thread.run(Thread.java:679)

But when I run it just with the basic java -jar craftbukkit.jar everything works fine

also I haven't been able to import worlds with Multiverse and whenever I login I end up in a different world everytime...

Restart should stop on failure to shutdown.

Script Output

$ ./minecraft-init/minecraft restart
craftbukkit_server.jar is running... stopping.
craftbukkit_server.jar could not be shut down... still running.
skipping non-regular file "world"
world copied to disk
created link for world
created link for world_nether
created link for world_the_end
links checked
world copied to ram
craftbukkit_server.jar is now running.

SERVER

>say SERVER REBOOT IN 10 SECONDS.
17:46:05 [INFO] [Server] SERVER REBOOT IN 10 SECONDS.
>save-all
17:46:05 [INFO] CONSOLE: Forcing save..
17:46:05 [INFO] CONSOLE: Save complete.
>save-off
17:50:01 [INFO] CONSOLE: Disabling level saving..
>save-all
17:50:01 [INFO] CONSOLE: Forcing save..
17:50:02 [INFO] CONSOLE: Save complete.
>save-on
17:50:13 [INFO] CONSOLE: Enabling level saving..

Starting when server already started causes server error

If you run /etc/init.d/minecraft start when the server is already running causes an error message to appear in server.

This seems to be cause by the check_links function. It seems to reset the links even if they are already setup and it does this even if the server is running which is bad.

I suppose the solution could be to either not change the links if they already exist or check for the server running much sooner.

I imagine to_ram() would have a similar issue.

ramdisk

How can i see if ramdisk is enabled? I try:

/etc/init.d/minecraft ramdisk world

then i get the following error:

World "world" not found.

How can i find out the world name?

Eliminating Date on Backups

In order for this script to properly work with the backups script you recommended, the world tar's can't have the dates appended to them. I've modified the source code partially to eliminate them being put into folders with the day, but it's still putting dates on the end of them. Could you change this and re-post it please? I don't know enough about shell scripting to do this. I just want to have it put them like this:

Backups Folder:
world
world_nether
world_end

instead of this:

Backups Folder:
world_03-07-2012
world_nether_03-07-2012
world_end_03-07-2012

mc_world_backup() {
    get_worlds
    today="" # If you don't want a folder for each day change to today=""
    for INDEX in ${!WORLDNAME[@]}
    do
        echo "Backing up minecraft ${WORLDNAME[$INDEX]}"

        case "$BACKUPFORMAT" in
            tar)
                path=`datepath $BACKUPPATH/${WORLDNAME[$INDEX]} .tar.bz2 .tar.bz2`
                as_user "tar -hcjf $path $MCPATH/${WORLDNAME[$INDEX]}"
                ;;
            zip)
                path=`datepath $BACKUPPATH/${WORLDNAME[$INDEX]} .zip .zip`
                as_user "zip -rq $path $MCPATH/${WORLDNAME[$INDEX]}"
                ;;
            *)
                echo "$BACKUPFORMAT is no supported backup format"
                ;;
        esac
    done
}

Update Command

First of all, absolutely love the work you're doing here. Thank you.

I just read the frontpage of bukkit.com and stumbled upon http://forums.bukkit.org/threads/introducing-dl-bukkit-org.59836/.

I was just wondering if the update command reflects the new changes? I does seem like there is a more intuitive way to download the latest version of Craftbukkit than before.

I don't know if this is relavant but just wanted to point you to it.

Whole-backup and DynMap (plugin)

I've stumbled into a problem after enabling DynMap high definition renders. The size of my DynMap folder is enormeous (22gb) and that in itself is not really a problem. What is a problem, however, is when I do whole-backup's, as they literally takes a few hours (I do them a few times a week).

Can I get around this problem in anyway? Excluding the DynMap plugin folder from the backup or something like that?

Has anyone else had this issue?

Could not get to work with su, changed to sudo

I don't know if I did something wrong, but as_user() does not work for me if it uses su - $USERNAME -c "$1". All such commands just silently fail. I am using Debian Wheezy.

as_user() starts working if I replace the su line with sudo -u $USERNAME bash -c "$1".

Nether support

It seems like the nether world is not supported for now. The first time I reached it through a portal, a server/world_nether folder was created on my craftbukkit installation (Build #935). So It seems like this nether world is neither on the ramdisk nor backed up.

As an aside, I could not break blocks nor build anything in the nether. Could it be related?

Idea: database backup

As I am sure you know, quite a few plugins rely on mysql databases and I think it could be smart if there were a script to backup those. Furthermore, it would be awesome if they could be included in the whole-backup script.

I am not technical and have no clue how difficult this would be to accomplish but it was just something.

Also I have another request which is not directly related to this .. but an option to chose if the whole-backup should be tar'ed. I would ease the process for remote backups.

Thank you :)

World reverted after update

I'm afraid I can't isolate this problem, but any suggestion would be fantastic--and it's a strange issue.

I'm not sure if any of this is relevant:

I have the ram cache turned off for all worlds.

When I updated minecraft last time (about a month ago) using this script, the script "Hung" in mid update and I ctrl-c'd it (It was probably doing a backup that took a lot longer than I expected)

Afterwards, one of my extra worlds had reverted from a "Just a few basic buildings" state to the state when i created it--blank. Since it had just gotten started I chalked it up as a learning experience, checked the symlinks (which may have been a problem, IIRC that world may have been created in the "Minecraft" directory, if so I moved it to the worldstorage directory and the script recreated the link and I went on with my life). It's been doing regular backups and everything.

I have checked the symlinks multiple times since then and they have been correct (I'm running Ubuntu if that matters). The world has been fine and we've been adding to it like crazy.

Just today I tried the update function again. It "hung" again (my bad). I ctrl-c'd it again and downloaded bukkit and minecraft by hand, but then I noticed that the new world had reverted, NOT to a completely blank state, but to the state I had lost the first time I updated (Meaning it brought back buildings that the first problem had wiped out and I hadn't seen for a month now)!

It''s extremely possible that by ctrl-c ing I interrupted the backup process, but if that's the case it shouldn't have changed the original world and it definitely shouldn't have reverted it to something I no longer had!

Really looking for any info as to where this world could have gone or what locations I could look in. I restored from the backup made last night and it didn't seem to do anything of interest. Very confused... Tried restoring from backups but they all seem to be the earlier image (the same one I have now).

Craftbukkit updates don't seem to work.

While the url in your script works in a webbrowser, it doesn't seem to fetch the file for some reason. there is also an http redirect link available, but that didn't seem to work either when i plugged it in place of the url you provided in your script.

script url on line 267 = http://ci.bukkit.org/job/dev-CraftBukkit/lastSuccessfulBuild/artifact/target/
http redirect provided by bukkit.org = http://repo.bukkit.org/service/local/artifact/maven/redirect?g=org.bukkit&a=craftbukkit&v=RELEASE&r=releases

World not being loaded

Hi,
I am using the stock minecraft-server.jar no craftbucket or anything and non of the worlds in "worldstorage" load. I only have one. I think his is because the world name is never called during invocation?

When ever I start the server with the script it makes the corresponding world folders in the server directory but then generate a new world in /world each time.

...Ok never mind I fixed it...

Perhaps for the benefit of other n00bs like me something like the following could be put in the help/doc:
[When using the minecraft-sever.jar ensure the server.properties file specifies the world as it in the world storage directory.]

I had ignored the server.properties file completely.
Thanks for the otherwise great script.

No Auto-Restart

This is more of a request but I would like to be able to restart the server if Java crashes.

Can't connect to screen

Everything seems to be running perfectly with the script except I can't seem to be able to connect to the screen with the server console. (Server is running under the user "minecraft" on my server) I log in as administrator to my server.

I've tried:
screen -x minecraft
sudo screen -x minecraft

All of which get: There is no screen to be attached matching minecraft.

I've also tried:
sudo su minecraft
then
screen -x minecraft

Which gives: Cannot open your terminal '/dev/pts/5' - please check.

(I've tried all of the commands with the -r flag instead of -x flag and get the same result.

Any help would be greatly appreciated.

Bukkit.yml world-container support

Hi, I'm relatively new to server administration on this level :) and here's my problem. Your script is perfect for ramdisk management, but I wanted to set world-container option (useful as it's handled by Multiverse) to worldstorage in my bukkit.yml and got messages like:

rsync: change_dir "/home/fb/mc/world" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.8]
world copied to disk
rsync: change_dir "/home/fb/mc/world_nether" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.8]
world_nether copied to disk
rsync: change_dir "/home/fb/mc/world_the_end" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.8]

while stopping the server. Everything seems to work properly, but I'd rather avoid any unpleasant suprises, so just tell me - is there a reason to be concerned? Should I rather work with default world-container?

English isn't my native language, but I hope you can see my point.

Timed start/stop

What about timed start and stops e.g. : ./minecraft stop 10 (server stop in 10 seconds)
This could be also broadcasted on the server then.

Backup files only contain a link

The backup files created by the crontab entry "/etc/init.d/minecraft backup" only contain a link :

lrwxrwxrwx minecraft/minecraft 0 2011-05-21 08:06 world -> /dev/shm/world

Error when running 'backup' and 'whole-backup'

Hi there,

When running either 'backup' or 'whole-backup' I receive the following error, resulting in the server hanging:

2011-12-19 10:36:01 [INFO] �[35m[Server] Backing up world.�[0m
2011-12-19 10:36:01 [INFO] CONSOLE: Disabling level saving..�[0m
2011-12-19 10:36:01 [INFO] CONSOLE: Forcing save..�[0m
2011-12-19 10:36:01 [INFO] CONSOLE: Save complete.�[0m
2011-12-19 10:36:51 [INFO] CONSOLE: Enabling level saving..�[0m
2011-12-19 10:36:51 [INFO] �[35m[Server] Backup complete.�[0m
2011-12-19 10:36:51 [SEVERE] net.minecraft.server.WorldConlictException: The save is being accessed from another location, aborting
2011-12-19 10:36:51 [SEVERE] at net.minecraft.server.WorldNBTStorage.checkSession(WorldNBTStorage.java:68)
2011-12-19 10:36:51 [SEVERE] at net.minecraft.server.World.l(World.java:2641)
2011-12-19 10:36:51 [SEVERE] at net.minecraft.server.World.y(World.java:274)
2011-12-19 10:36:51 [SEVERE] at net.minecraft.server.World.save(World.java:264)
2011-12-19 10:36:51 [SEVERE] at net.minecraft.server.World.doTick(World.java:1735)
2011-12-19 10:36:51 [SEVERE] at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:514)
2011-12-19 10:36:51 [SEVERE] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:425)
2011-12-19 10:36:51 [SEVERE] at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
2011-12-19 10:36:51 [SEVERE] Unexpected exception
net.minecraft.server.WorldConlictException: The save is being accessed from another location, aborting
at net.minecraft.server.WorldNBTStorage.checkSession(WorldNBTStorage.java:68)
at net.minecraft.server.World.l(World.java:2641)
at net.minecraft.server.World.y(World.java:274)
at net.minecraft.server.World.save(World.java:264)
at net.minecraft.server.World.doTick(World.java:1735)
at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:514)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:425)
at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)

Might just be me but "could not process X ..."

I'm having trouble using your init.d script for some strange reason. I have a different type of folder structure:
/var/minecraft/pure/ <- Base
/var/minecraft/pure/ <- World base folder (world and world_neteher).

I'm getting this warning:

  • case "$1" in
  • check_links
  • for INDEX in '${!WORLDNAME[@]}'
  • [[ -L /var/minecraft/pure/world ]]
  • [[ ! -a /var/minecraft/pure/world ]]
  • echo 'could not process world. please move all worlds to /var/minecraft/pure.'
    could not process world. please move all worlds to /var/minecraft/pure.
  • exit 1

I know it is something simple since it fails with the first check... so what am I missing?

ahh, /etc/passwd :) used nologin for the user I created damn my paranoia (sorry to bother you!).

Multiple small issues

I'd love the control over my server this would give me, but I'm having a few issues with it.

Primarily, when running the start command, it seems bukkit is working at first, I don't believe it ever really starts. I can't connect to the server remotely at all, and running 'top' does show a java process owned by the minecraft user—but it never gets above 1% CPU usage on a fairly tiny server.
Secondarily, running the stop command reports successfully stopping bukkit, but the aforementioned java process never goes away and on running start it complains that it's already running.

These two are almost assuredly related.

Finally, despite 755 permissions, when trying to link the worlds files, permission is regularly denied. This happens when accessing both the disk and ramdisk. Running the links command does the same.

service minecraft start
ls: cannot access /home/minecraft/FractalSoup: No such file or directory
ln: creating symbolic link `/home/minecraft/FractalSoup': Permission denied

Backups are corrupted?

I tried to extract a backup of my survival_nether world;

minecraft@bacardi:~$ tar -jxvf survival_nether_2012-03-01.tar.bz2

bzip2: Compressed file ends unexpectedly;
        perhaps it is corrupted?  *Possible* reason follows.
bzip2: Inappropriate ioctl for device
        Input file = (stdin), output file = (stdout)

It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.

You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.

tar: Child returned status 2
tar: Error is not recoverable: exiting now

Is there a special way to extract backups, or are the files really corrupted? I get the same for all the backups I have stored.

to_disk() doesn't check to see if world isn't a ramdisk

Calling minecraft stop reports that it has moved several worlds from ramdisk even though only one is actually on the ramdisk.

I currently only have the main world folder put on the ram disk and not the world_nether and world_the_end but they get copied to disk anyway. I'm unsure if this actually hurts anything but figured I'd point it out.

Cannot find screen

Hi,

i installed your scrip, the server is running but when i typ in with Putty:
screen -r minecraft, it say's:

There is no screen to be resumed matching minecraft.

but when I "/etc/init.d/minecraft restart"
so restart the server, then can I connect with the screen,
any Idea how to fix this?

already thanks,
Greetings Kiwi.

Will not work on OpenSUSE 12.1

Hello there.
Im having some issues with getting the script to work on OpenSUSE 12.1. ive followed the instructions to the letter... Im having a problem getting the script to activate and when it does it gives me a permission denied even under root.. here is the output of my ssh:

linux-pcbl:/home/minecraft # ln -s minecraft /etc/init.d/
linux-pcbl:/home/minecraft # chkconfig --set minecraft on
minecraft: unknown service
linux-pcbl:/home/minecraft # insserv minecraft
insserv: minecraft: Too many levels of symbolic links
linux-pcbl:/home/minecraft #

and also:

linux-pcbl:/home/minecraft # ln /home/minecraft/minecraft /etc/init.d/minecraft
linux-pcbl:/home/minecraft # chkconfig --set minecraft on
insserv: script minecraft is not an executable regular file, skipped!
insserv: Service network is missed in the runlevels 2 to use service webmin
linux-pcbl:/home/minecraft # /etc/init.d/minecraft start
-bash: /etc/init.d/minecraft: Permission denied

I cannot understand whats going on to be honest.. im not really a noob when it comes to linux or opensuse to that fact as the last start script i used from this one:

!/bin/bash

/etc/init.d/minecraft

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: Init script for minecraft/bukkit server, with rolling logs and use of ramdisk for less lag.

END INIT INFO

Created by Ahtenus

Based on http://www.minecraftwiki.net/wiki/Server_startup_script

Support for multiworld by Benni-chan

Log rolls without needing restarts by Solorvox

### SETTINGS

Name of server.jar file

SERVICE="craftbukkit-1.0.1-R1.jar"

Name to use for the screen instance

SCREEN="minecraft"

User that should run the server

USERNAME="minecraft"

Path to minecraft directory

MCPATH="/home/${USERNAME}/Server"

Number of CPUs/cores to use

CPU_COUNT=4

Initial memory usage

INITMEM="2048M"

Maximum amount of memory to use

MAXMEM="3072M"

Remember: give the ramdisk enough space, subtract from the total amount

of RAM available the size of your map and the RAM-consumption of your base system.

INVOCATION="java -Xmx$MAXMEM -Xms$INITMEM -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts -jar $SERVICE nogui"

Where the world backups should go

BACKUPPATH="/home/${USERNAME}/minebak"

Where the logs are copied with log-roll

LOGPATH="${MCPATH}/logs"

Where the whole minecraft directory is copied when whole-backup is executed

WHOLEBACKUP="/home/${USERNAME}/serverbak"

Where the worlds are located on the disk. Can not be the same as MCPATH.

WORLDSTORAGE="${MCPATH}/worldstorage"

Path to the the mounted ramdisk default in Ubuntu: /dev/shm

RAMDISK="/dev/shm"

use tar or zip files for world backup

BACKUPFORMAT="tar"

ME=whoami
as_user() {
if [ $ME == $USERNAME ] ; then
bash -c "$1"
else
su - $USERNAME -c "$1"
fi
}
datepath() {
# datepath path filending-to-check returned-filending
if [ -e $1date +%F$2 ]
then
echo $1date +%FT%T$3
else
echo $1date +%F$3
fi
}
mc_start() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "Tried to start but $SERVICE was already running!"
else
echo "$SERVICE was not running... starting."
cd $MCPATH
as_user "cd $MCPATH && screen -dmS $SCREEN $INVOCATION"
sleep 7
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "$SERVICE is now running."
else
echo "Could not start $SERVICE."
fi
fi
}

mc_saveoff() {
if ps ax | 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 -X eval 'stuff "save-off"\015'"
as_user "screen -p 0 -S $SCREEN -X eval 'stuff "save-all"\015'"
sync
sleep 10
else
echo "$SERVICE was not running. Not suspending saves."
fi
}

mc_saveon() {
if ps ax | 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 -X eval 'stuff "save-on"\015'"
else
echo "$SERVICE was not running. Not resuming saves."
fi
}

mc_stop() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "$SERVICE is running... stopping."
as_user "screen -p 0 -S $SCREEN -X eval 'stuff "save-all"\015'"
sleep 10
as_user "screen -p 0 -S $SCREEN -X eval 'stuff "stop"\015'"
sleep 7
else
echo "$SERVICE was not running."
fi
if ps ax | 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
}
log_roll() {
if [ ! -d $LOGPATH ]; then
as_user "mkdir -p $LOGPATH"
fi
path=datepath $LOGPATH/server_ .log.gz .log
as_user "cp $MCPATH/server.log $path && gzip $path"
# only if previous command was successful
if [ $? -eq 0 ]; then
# turnacate the existing log without restarting server
as_user "cp /dev/null $MCPATH/server.log"
as_user "echo "Previous logs rolled to $path" > $MCPATH/server.log "
else
echo "Failed to rotate logs to $LOGPATH/server_$path.log.gz"
fi

}
get_worlds() {
a=1
for NAME in $(ls $WORLDSTORAGE)
do
if [ -d $WORLDSTORAGE/$NAME ]
then
WORLDNAME[$a]=$NAME
if [ -e $WORLDSTORAGE/$NAME/ramdisk ]
then
WORLDRAM[$a]=true
else
WORLDRAM[$a]=false
fi
a=$a+1
fi
done
}
mc_whole_backup() {
as_user "mkdir -p $WHOLEBACKUP"
path=datepath $WHOLEBACKUP/mine_
as_user "cp -rP $MCPATH $path"
}
mc_world_backup() {
get_worlds
today="date +%F" # If you don't want a folder for each day change to today=""
for INDEX in ${!WORLDNAME[@]}
do
echo "Backing up minecraft ${WORLDNAME[$INDEX]}"
as_user "mkdir -p $BACKUPPATH${today}"

    case "$BACKUPFORMAT" in
        tar)
            path=`datepath $BACKUPPATH${today}/${WORLDNAME[$INDEX]}_ .tar.bz2 .tar.bz2`
            as_user "tar -hcjf $path $MCPATH/${WORLDNAME[$INDEX]}"
            ;;
        zip)
            path=`datepath $BACKUPPATH${today}/${WORLDNAME[$INDEX]}_ .zip .zip`
            as_user "zip -rq $path $MCPATH/${WORLDNAME[$INDEX]}"
            ;;
        *)
            echo "$BACKUPFORMAT is no supported backup format"
            ;;
    esac
done

}
check_links() {
get_worlds
for INDEX in ${!WORLDNAME[@]}
do
if [[ -L $MCPATH/${WORLDNAME[$INDEX]} || ! -a $MCPATH/${WORLDNAME[$INDEX]} ]]
then
link=ls -l $MCPATH/${WORLDNAME[$INDEX]} | awk '{print $11}'
if ${WORLDRAM[$INDEX]}
then
if [ "$link" != "$RAMDISK/${WORLDNAME[$INDEX]}" ]
then
as_user "rm -f $MCPATH/${WORLDNAME[$INDEX]}"
as_user "ln -s $RAMDISK/${WORLDNAME[$INDEX]} $MCPATH/${WORLDNAME[$INDEX]}"
echo "created link for ${WORLDNAME[$INDEX]}"
fi
else
if [ "$link" != "${WORLDSTORAGE}/${WORLDNAME[$INDEX]}" ]
then
as_user "rm -f $MCPATH/${WORLDNAME[$INDEX]}"
as_user "ln -s ${WORLDSTORAGE}/${WORLDNAME[$INDEX]} $MCPATH/${WORLDNAME[$INDEX]}"
echo "created link for ${WORLDNAME[$INDEX]}"
fi
fi
else
echo "could not process ${WORLDNAME[$INDEX]}. please move all worlds to ${WORLDSTORAGE}."
exit 1
fi
done
echo "links checked"
}
to_ram() {
get_worlds
for INDEX in ${!WORLDNAME[@]}
do
if ${WORLDRAM[$INDEX]}
then
if [ -L $MCPATH/${WORLDNAME[$INDEX]} ]
then
as_user "rsync -rt --exclude 'ramdisk' ${WORLDSTORAGE}/${WORLDNAME[$INDEX]}/ $RAMDISK/${WORLDNAME[$INDEX]}"
echo "${WORLDNAME[$INDEX]} copied to ram"
fi
fi
done
}
to_disk() {
get_worlds
for INDEX in ${!WORLDNAME[@]}
do
as_user "rsync -rt --exclude 'ramdisk' $MCPATH/${WORLDNAME[$INDEX]}/ ${WORLDSTORAGE}/${WORLDNAME[$INDEX]}"
echo "${WORLDNAME[$INDEX]} copied to disk"
done
}
mc_update() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "$SERVICE is running! Will not start update."
else
### update minecraft_server.jar
echo "Updating minecraft_server.jar...."
MC_SERVER_URL=http://minecraft.net/`wget -q -O - http://www.minecraft.net/download.jsp | grep minecraft_server.jar | cut -d " -f 2 as_user "cd $MCPATH && wget -q -O $MCPATH/minecraft_server.jar.update $MC_SERVER_URL" if [ -f $MCPATH/minecraft_server.jar.update ] then ifdiff $MCPATH/minecraft_server.jar $MCPATH/minecraft_server.jar.update >/dev/null`
then
echo "You are already running the latest version of the Minecraft server."
as_user "rm $MCPATH/minecraft_server.jar.update"
else
as_user "mv $MCPATH/minecraft_server.jar.update $MCPATH/minecraft_server.jar"
echo "Minecraft successfully updated."
fi
else
echo "Minecraft update could not be downloaded."
fi

    ### update craftbukkit

    echo "Updating craftbukkit...."
    as_user "cd $MCPATH && wget -q -O $MCPATH/craftbukkit.jar.update http://ci.bukkit.org/job/dev-CraftBukkit/promotion/latest/Recommended/artifact/target/craftbukkit-1.0.1-R1.jar"
    if [ -f $MCPATH/craftbukkit.jar.update ]
    then
        if `diff $MCPATH/craftbukkit-1.0.1-R1.jar $MCPATH/craftbukkit.jar.update > /dev/null`
        then
            echo "You are already running the latest version of CraftBukkit."
            as_user "rm $MCPATH/craftbukkit.jar.update"
        else
            as_user "mv $MCPATH/craftbukkit.jar.update $MCPATH/craftbukkit-1.0.1-R1.jar"
            echo "CraftBukkit successfully updated."
        fi
    else
        echo "CraftBukkit update could not be downloaded."
    fi
fi

}
change_ramdisk_state() {
if [ ! -e $WORLDSTORAGE/$1 ]
then
echo "World "$1" not found."
exit 1
fi

if [ -e $WORLDSTORAGE/$1/ramdisk ]
then
    rm $WORLDSTORAGE/$1/ramdisk
    echo "removed ramdisk flag from \"$1\""
else
    touch $WORLDSTORAGE/$1/ramdisk
    echo "added ramdisk flag to \"$1\""
fi
echo "changes will only take effect after server is restarted." 

}

case "$1" in
start)
# Starts the server
check_links
to_ram
mc_start
;;
stop)
# Stops the server
as_user "screen -p 0 -S $SCREEN -X eval 'stuff "say SERVER SHUTTING DOWN!"\015'"
mc_stop
to_disk
;;
restart)
# Restarts the server
as_user "screen -p 0 -S $SCREEN -X eval 'stuff "say SERVER REBOOT IN 10 SECONDS."\015'"
mc_stop
to_disk
check_links
to_ram
mc_start
;;
backup)
# Backups world
as_user "screen -p 0 -S $SCREEN -X eval 'stuff "say Backing up world."\015'"
mc_saveoff
to_disk
mc_world_backup
mc_saveon
as_user "screen -p 0 -S $SCREEN -X eval 'stuff "say Backup complete."\015'"
;;
whole-backup)
# Backup everything
mc_whole_backup
;;
update)
#update minecraft_server.jar and craftbukkit.jar (thanks karrth)
as_user "screen -p 0 -S $SCREEN -X eval 'stuff "say SERVER UPDATE IN 10 SECONDS."\015'"
mc_stop
to_disk
mc_whole_backup
mc_update
check_links
mc_start
;;
to-disk)
# Writes from the ramdisk to disk, in case the server crashes.
# Using ramdisk speeds things up a lot, especially if you allow
# teleportation on the server.
mc_saveoff
to_disk
mc_saveon
;;
connected)
# Lists connected users
as_user "screen -p 0 -S $SCREEN -X eval 'stuff list\015'"
sleep 3s
tac $MCPATH/server.log | grep -m 1 "Connected"
;;
log-roll)
# Moves and Gzips the logfile, a big log file slows down the
# server A LOT (what was notch thinking?)
# The existing log is turnacated to 0 file size.

    log_roll
    ;;
last)
    # greps for recently logged in users
    echo Recently logged in users:
    cat $MCPATH/server.log | awk '/entity|conn/ {sub(/lost/,"disconnected");print $1,$2,$4,$5}'
    ;;
status)
    # Shows server status
    if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
    then
        echo "$SERVICE is running."
    else
        echo "$SERVICE is not running."
    fi
    ;;
version)
    echo Craftbukkit version `awk '/Craftbukkit/ {sub(/\)/, ""); print $12}' $MCPATH/server.log`
    ;;
links)
    check_links
    ;;
ramdisk)
    change_ramdisk_state $2
    ;;
worlds)
    get_worlds
    for INDEX in ${!WORLDNAME[@]}
    do
        if ${WORLDRAM[$INDEX]}
        then
            echo "${WORLDNAME[$INDEX]} (ramdisk)"
        else
            echo ${WORLDNAME[$INDEX]}
        fi
    done
    ;;
help)
    echo "Usage: /etc/init.d/minecraft command"
    echo 
    echo "start - Starts the server"
    echo "stop - stops the server"
    echo "restart - restarts the server"
    echo "backup - backups the worlds defined in the script"
    echo "whole-backup - backups the entire server folder"
    echo "update - fetches the latest version of minecraft.jar server and Bukkit"
    echo "log-roll - Moves and gzips the logfile"
    echo "to-disk - copies the worlds from the ramdisk to worldstorage"
    echo "connected - lists connected users"
    echo "status - Shows server status"
    echo "version - returs Bukkit version"
    echo "links - creates nessesary symlinks"
    echo "last - shows recently connected users"
    echo "worlds - shows a list of available worlds"
    echo "ramdisk WORLD - toggles ramdisk configuration for WORLD"
    ;;
*)
    echo "No such command see /etc/init.d/minecraft help"
    exit 1
    ;;

esac

exit 0
That one...
works just fine

Overviewer usage outdated

Hi!

Overviewer has been developing recently.

Firstly, it's preferred installation method is now via apt package manager. It installs overviewer.py into /usr/bin and the rest of Overviewer into some other place. Because of that, the $OVPATH directory is now confusing.

Secondly, Overviewer configuration syntax and structure have changed. You should now provide paths to worlds within Overviewer config, not command line. Also, --settings has changed to --config.

According to Overviewer developer agrif, the correct Overviewer command is the following:

python overviewer.py --config=/path/to/config.txt

Don't take my considerations for granted, please double-check before modifying your beautiful code.

Automatic restart

It would be cool if someone could add an automatic restart paramter to start the script with. It should warn the users longer then and check if the server is still reacting and killing it if not.
And also, what about this check? Can the script check if the server is still working, like if its frozen?

Add date to ouput

To make log files easier to track. Not every line needs to be dated, just insert one line with the date. To make reading appened cron output logs easier. I'm guessing make a date() funtion and call it later on. so it outputs only one date line per backup/restart/log-roll etc...

Problem in update Craftbukkit routine

Hello,

I discovered a problem in the update routine of craftbukkit in your sourcecode.
If the user renamed craftbukkit and set the variable accordingly to reflect the newly named file, the diff of the hardcoded filename will fail because it does not exist.

Regards,
Tobias

trouble with getting the script to work

THIS WAS MY OLD ISSUE LOOK TOWARDS THE BOTTOM

well i am sort of new to linux but i managed the setup to what i believe was right but i cant get it to work i tried to use the help command you supplied but it just gives me a message saying rename config.example to config i have already done that and it just tells me to do it when i use screen minecraft it says no such script.

forget that i got it to work very nicely thank you but do you know how i can get the screen to work in ssh?

Unknown id

Hi, I'm getting the following error:

unknown ID: kiwi

but the thing is I launch from it from the kiwi acc:

kiwi@bubblegum:~$ /etc/init.d/minecraft start
: No such file or directoryi
links checked
: No such file or directoryi
: No such file or directory 73: cd: /home/kiwi
Unknown id: kiwi

directory looks like following:

http://screencast.com/t/LhboFds4
everything is in that file, I don't get it

already thanks: kiwi

Datepath makes invalid paths

When trying to do a log-roll, I run into this error message:

mv: cannot move /home/mineadmin/server.log' to/home/mineadmin/logs/server_05/29/2011.log': No such file or directory

i think the problem is in the date "05/29/2011" as it is looking for the directory "05" and the sub directory "29"

Unknown id: v

I have everything setup (I think) and when I initiate it or even type /etc/init.d/minecraft start it gives me this:

links checked
craftbukkit-1.0.0-SNAPSHOT.jar was not running... starting.
Unknown id: v
Could not start craftbukkit-1.0.0-SNAPSHOT.jar.

I am not sure if its because I am using it with bukkit 1.0.0 or if I installed screen wrong. man screen says I should setup my terminals but I don't know how to do that beyond tset. Looking at your code the problem occurs when it tries to set the command -v into screen?

Using the init script to manage multiple servers on a single machine

I have been using your script to run a single server on a single machine, and i wanted to use a second copy of the script (mc1 and mc2 for this example) so that i could have a test server running in conjunction with the live server, that i can test plugins on, etc, without having to affect the main server.

the issue i've run into is if i'm running the script (mc2) for the main server, mc1 sees it online even though i've defined everything different in the config files for the servers.

server 1's config1 file

CB_JAR="craftbukkit_server.jar"
SERVICE=$CB_JAR
CB_RELEASE="stable"
SCREEN="mctest"
USERNAME="v"
MCPATH="/home/${USERNAME}/minecraft/server1"
CPU_COUNT=1
INITMEM="2048M"
MAXMEM="2048M"
INVOCATION="java -Xmx$MAXMEM -Xms$INITMEM -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts -jar $SERVICE nogui"
BACKUPPATH="/home/${USERNAME}/minecraft/minebak"
LOGPATH="/home/${USERNAME}/minecraft/logs/server1"
WHOLEBACKUP="/home/${USERNAME}/minecraft/serverbak/server1"
WORLDSTORAGE="${MCPATH}/worldstorage"
BACKUPFORMAT="tar"
RAMDISK="/dev/shm"```

Server 2 config2 file
```MC_JAR="minecraft_server.jar"
CB_JAR="craftbukkit_server.jar"
SERVICE=$CB_JAR
CB_RELEASE="stable"
SCREEN="mclive"
USERNAME="v"
MCPATH="/home/${USERNAME}/minecraft/server2"
CPU_COUNT=1
INITMEM="2048M"
MAXMEM="2048M"
INVOCATION="java -Xmx$MAXMEM -Xms$INITMEM -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts -jar $SERVICE nogui"
BACKUPPATH="/home/${USERNAME}/minecraft/minebak"
LOGPATH="/home/${USERNAME}/minecraft/logs/server2"
WHOLEBACKUP="/home/${USERNAME}/minecraft/serverbak/server2"
WORLDSTORAGE="${MCPATH}/worldstorage"
BACKUPFORMAT="tar"
RAMDISK="/dev/shm"```

minecraft version doesn't return a version when running craftbukkit

When using the command minecraft version at the command prompt, the following is returned..

host@host:$minecraft version
Craftbukkit version
host@host:
$

if you connect to the server screen, the following is returned for the version:

18:56:30 [INFO] This server is running CraftBukkit version git-Bukkit-1.1-R4-b1938jnks (MC: 1.1) (Implementing API version 1.1-R4)

is there any way to grep this from the log? i'm afraid my skill with grep is rather limited, and have been unable to make this function as i'd like. I'll continue to experiment.

Improvements and Bugfixes

I wouldn't really call this an issue, more of an improvement on a previous issue. The project is forked on my page, and I fixed the script to remove every file in the world backups directory and not just remove them selectively by name, so that if there are leftover files or it got stopped mid backup, it will remove all the leftover scraps of data. This makes for a cleaner approach to cleaning up the world backups folder. Of course, it only does this if the backup script compatibility is enabled, for safety reasons. This code is already tested, so please merge it into the main branch, as this is a major improvement over my other solution and that was only intended to be a workaround. (Because the conditional loops, it was wiping the backups folder every time it backed up one world, which resulted in only the last world remaining.) If you want to take a look at the code, look at the last 2 commits. For future reference, how would I contact you to request a merge in the future?

Function request

Could the init script be modified to include the switch 'version'? "/etc/init.d/minecraft version" would output which version of craftbukkit is currently being run. 1.7, 1.7.01, etc.

Silent failure on insufficient memory

When incorrectly setting the starting and max memory to high in the config file there is no indication upon starting the server that something went wrong. By copying the init and running it manually in terminal outputs a verbose error letting you know that there was to much memory allocated or something along the lines, could this message perhaps be caught and used to let users know why the server won't start somehow?

Script not working in Debian when running with different user

The script does not run under debian 6.0.5 (and previous versions) due to a permissions problem which occurs when using screen and su togehter. There are bugreports for this in the debian bug tracking system but they are all set to "won't fix" (see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=637925).

The problem is that su changes the current user but not the owner of the current terminal. After suing to the user minecraft the /dev/tty* is still owned by root. Screen tries to access it but has no permissions because it runs with user minecraft. Thus screen fails and the server does not start.

A possible solution could be to execute screen with root and su inside of screen but I'm not sure if this actually works. A quick test showed it could:

Does not work:
su minecraft -s /bin/bash -c "cd /opt/minecraft && screen -dmS Test touch a"

Works:
screen -dmS Test su minecraft -s /bin/bash -c "cd /opt/minecraft && touch a"

No 'Worlds' Listed

Hi all,

I'm using the script to launch a bukkit server. It launches a stock world named 'world'.

I can connect to the server with no problems. Everything seems to work.

But if I do '/etc/init.d/minecraft worlds' I see nothing listed. Since nothing is listed, I am unable to use the ramdisk option.

Also, there is no documentation on running multiple worlds. I guess I could have several instances of the script run. Is that the proper way?

Thanks.

Distribute the 'config' file instead of the 'config.example' file.

By distributing the file as "config" instead of "config.example" you do two things:

  • Make it easier for new users to get it up and running. I know that I didn't see the instructions to rename it for a while. (this isn't very important).
  • When the config gets updated on github and we pull from the repository, it will generate diffs for us that let the users easily notice where parts of the config change. It also has the added benefit of keeping all their custom settings (that didn't change) as well as clearly marking the parts that did change.

Script crashes every time i log out

Hi i was hoping you could help me with my problem. I have gotten the script running well, though I access my server with putty through ssh. Everytime i log out of ssh while server is running, it crashes and just stops working. I have tried running it in a screen as well as nohup to no avail. PLEASE HELP ME ive been struggling with this for days now. Thanks!

Backup Script Still Making Date folder

It's still making the folder for the date when the mode for compatibility with the backup rolling script is enabled in the config file. It still works fine, but it's kind of annoying, and should be fixed because every day it makes one more empty folder, and after a week you'd have seven folders. Eventually it would get kinda messy.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.