I only changed the USER_NAME variable. The script is in the /etc/init.d folder.
Output from those commands:
$ screen -r 22161.minecraft-world
Cannot open your terminal '/dev/pts/5' - please check.
$ screen -r 22014.minecraft-world
Cannot open your terminal '/dev/pts/5' - please check.
That's after a sudo su www-data.
I don't expect you to fix my problems with this, since the script wasn't really intended for this use, but really appreciate all of your assistance. It's be nice to have help at least trying to figure it out!
I only changed the USER_NAME variable. The script is in the /etc/init.d folder.
Output from those commands:
$ screen -r 22161.minecraft-world
Cannot open your terminal '/dev/pts/5' - please check.
$ screen -r 22014.minecraft-world
Cannot open your terminal '/dev/pts/5' - please check.
That's after a sudo su www-data.
I don't expect you to fix my problems with this, since the script wasn't really intended for this use, but really appreciate all of your assistance. It's be nice to have help at least trying to figure it out!
I don't know the password for the www-data account since I didn't specifically create it. Looking around online it doesn't have a password of its own that can be accessed.
I don't know the password for the www-data account since I didn't specifically create it. Looking around online it doesn't have a password of its own that can be accessed.
You don't need the password for the www-data user.
This sequence of commands should show you the contents of the two screens, assuming you are still connected via /dev/pts/5, and screen -ls still outputs the same info:
151 recipes
16 achievements
2011-06-30 14:37:31 [INFO] Starting minecraft server version Beta 1.7_01
2011-06-30 14:37:31 [INFO] Loading properties
2011-06-30 14:37:31 [INFO] Starting Minecraft server on *:25565
2011-06-30 14:37:31 [WARNING] **** FAILED TO BIND TO PORT!
2011-06-30 14:37:31 [WARNING] The exception was: java.net.BindException: Address already in use
2011-06-30 14:37:31 [WARNING] Perhaps a server is already running on that port?
screen -r 22014.minecraft-world
2011-06-30 14:37:08 [INFO] Starting minecraft server version Beta 1.7_01
2011-06-30 14:37:08 [INFO] Loading properties
2011-06-30 14:37:08 [INFO] Starting Minecraft server on *:25565
2011-06-30 14:37:08 [WARNING] **** FAILED TO BIND TO PORT!
2011-06-30 14:37:08 [WARNING] The exception was: java.net.BindException: Address already in use
2011-06-30 14:37:08 [WARNING] Perhaps a server is already running on that port?
151 recipes
16 achievements
2011-06-30 14:37:31 [INFO] Starting minecraft server version Beta 1.7_01
2011-06-30 14:37:31 [INFO] Loading properties
2011-06-30 14:37:31 [INFO] Starting Minecraft server on *:25565
2011-06-30 14:37:31 [WARNING] **** FAILED TO BIND TO PORT!
2011-06-30 14:37:31 [WARNING] The exception was: java.net.BindException: Address already in use
2011-06-30 14:37:31 [WARNING] Perhaps a server is already running on that port?
screen -r 22014.minecraft-world
2011-06-30 14:37:08 [INFO] Starting minecraft server version Beta 1.7_01
2011-06-30 14:37:08 [INFO] Loading properties
2011-06-30 14:37:08 [INFO] Starting Minecraft server on *:25565
2011-06-30 14:37:08 [WARNING] **** FAILED TO BIND TO PORT!
2011-06-30 14:37:08 [WARNING] The exception was: java.net.BindException: Address already in use
2011-06-30 14:37:08 [WARNING] Perhaps a server is already running on that port?
I am surprised that both screens complain about not being about to bind to the port.
Do you have two startup scripts in the /etc/init.d directory, is that the reason there is two worlds starting? I'm grasping for answers right now..
I am surprised that both screens complain about not being about to bind to the port.
Do you have two startup scripts in the /etc/init.d directory, is that the reason there is two worlds starting? I'm grasping for answers right now..
Yes. I have /etc/init.d/minecraft_server and /etc/init.d/minecraft_server_www. The first one is set to USER_NAME=myusername and the _www is set to USER_NAME=www-data. Both files are owned by myusername and in the www-data group with 755 permissions.
I can run all commands locally just fine via the first one. My CGI (.sh) scripts listed previously look at the _www file. I did this to avoid the username mismatch error. I am a Linux newbie, so perhaps moving it out of the /etc/init.d file would be correct? I didn't realize what that folder did specifically until now.
Yes. I have /etc/init.d/minecraft_server and /etc/init.d/minecraft_server_www. The first one is set to USER_NAME=myusername and the _www is set to USER_NAME=www-data. Both files are owned by myusername and in the www-data group with 755 permissions.
I can run all commands locally just fine via the first one. My CGI (.sh) scripts listed previously look at the _www file. I did this to avoid the username mismatch error. I am a Linux newbie, so perhaps moving it out of the /etc/init.d file would be correct? I didn't realize what that folder did specifically until now.
I never took into account that someone might want to have two copies of the script running at the same time. I can make some changes to the script that should make it work since you were able to help identify the section of code that needs to be modified. However, each copy of the script is going to need to use a different port, say 25565 and 25566. You will either need to modify the DEFAULT_PORT variable or change the worlds.conf file that gets generated.
The easiest solution is to pick one of the scripts and delete it:
Each script serves a different purpose.
minecraft_server I use for the server to run. I run the scripts locally from it.
minecraft_server_www Is supposed to be looking at the same server (I guess now that assumption was wrong?) and use the apache username in the file so the website can access it.
Despite the permissions allowing www-data to access all of my minecraft server's files and the minecraft_server file it fails when I try to set it as user www-data and run commands from the minecraft_server file.
Each script serves a different purpose.
minecraft_server I use for the server to run. I run the scripts locally from it.
minecraft_server_www Is supposed to be looking at the same server (I guess now that assumption was wrong?) and use the apache username in the file so the website can access it.
Despite the permissions allowing www-data to access all of my minecraft server's files and the minecraft_server file it fails when I try to set it as user www-data and run commands from the minecraft_server file.
It won't work that way. Just have the www-data run the minecraft server so that apache can have the access it needs.
I got the scripts to run from the website. Finally! If anyone else wants to run them from a web interface do the following steps.
1. Set the USER_NAME variable in /etc/init.d/minecraft_server to www-data
2. Make sure www-data is part of the admin group. Make sure the permissions on your Minecraft server files and the /etc/init.d/minecraft_server include www-data as the user or the group. "chmod 755" and "chgrp www-data" can be used for this. www-data needs access to all of the files in order for the scripts to work fully.
3. Your website needs to have Apache configured with CGI and able to run .sh files. Here's an example of my START.sh file in my /home/www/cgi-bin/ directory:
To call this script from my webpage I use a standard HTML link:
<a href="./cgi-bin/START.sh">Start - Turn-on/restart the server and all worlds.</a>
4. Make sure you're patient with running the start, restart, and update scripts. They take quite a while. Also, look at your
/var/logs/apache2/error.log
if you run into trouble.
Setting up a webpage to activate/manage the server was a fun task. It's made management of the server easier for normal running circumstances for me and my friends (especially the less tech-savvy ones).
Again, BIG THANK YOU!! to sandain! Your script is great and serves many purposes, once I figure out what Linux wanted from me. (: Your assistance has made this possible; I had no idea about www-data running the scripts and that was the root of my problems (I needed the permissions setup for it).
Good luck to anyone trying this. The script run and managed locally works beautifully!
I got the scripts to run from the website. Finally! If anyone else wants to run them from a web interface do the following steps.
1. Set the USER_NAME variable in /etc/init.d/minecraft_server to www-data
2. Make sure www-data is part of the admin group. Make sure the permissions on your Minecraft server files and the /etc/init.d/minecraft_server include www-data as the user or the group. "chmod 755" and "chgrp www-data" can be used for this. www-data needs access to all of the files in order for the scripts to work fully.
3. Your website needs to have Apache configured with CGI and able to run .sh files. Here's an example of my START.sh file in my /home/www/cgi-bin/ directory:
To call this script from my webpage I use a standard HTML link:
<a href="./cgi-bin/START.sh">Start - Turn-on/restart the server and all worlds.</a>
4. Make sure you're patient with running the start, restart, and update scripts. They take quite a while. Also, look at your
/var/logs/apache2/error.log
if you run into trouble.
Setting up a webpage to activate/manage the server was a fun task. It's made management of the server easier for normal running circumstances for me and my friends (especially the less tech-savvy ones).
Again, BIG THANK YOU!! to sandain! Your script is great and serves many purposes, once I figure out what Linux wanted from me. (: Your assistance has made this possible; I had no idea about www-data running the scripts and that was the root of my problems (I needed the permissions setup for it).
Good luck to anyone trying this. The script run and managed locally works beautifully!
Nice job Nevra! I'm glad that you were able to get this working! Thanks for the write-up too; as soon as I get the new hard drive for my currently broken server, I might give this a try myself.
Thank you for the great script! It has made running my server a breeze. I recently moved my server to a ramdisk with a symbolic link in the worlds directory to my /dev/shm partition. This unfortunately broke my backup cron script because tar by default does not follow symbolic links it archives the link instead. To fix this I added a -h to the backup tar command and all was right in the world.
Thanks again for coding this script for the community :smile.gif:
Registered just to say, thank you for this script. It's made running my group's minecraft servers a pleasure. I've had to make a few tweaks to the script(Mostly disabling the whole 'restart the server on a SEVERE error'. It liked restarting the server several times in a row.), but for the most part, this has worked as-is for about half a dozen maps now.
800 Lines of bash, I must say that's quite an accomplishment (because bash comparisons are my least favorite in the world)!
Just two mentions:
1) You might consider 'nice'-ing, or 'ionice'ing the mapping. Probably nice should be enough though.
2) Should minecraft be run as 'root' (a la 'sudo')? Should be equivalent in performance and function to run the commands from an unprivileged user, no?
(root would still need to be used for iptables, of course)
800 Lines of bash, I must say that's quite an accomplishment (because bash comparisons are my least favorite in the world)!
There are no Bashisms in this script, I went to great length to avoid using any Bash extensions so that this script would work under any POSIX compliant shell, including Dash (the newish default system shell in Debian land). There are a number of Perl one-liners in the code to handle the messy pattern matching, but every *NIX out there comes with Perl installed by default, AFAIK. I could switch the code over to using awk instead of Perl with a little effort, I just like programming in Perl.
1) You might consider 'nice'-ing, or 'ionice'ing the mapping. Probably nice should be enough though.
2) Should minecraft be run as 'root' (a la 'sudo')? Should be equivalent in performance and function to run the commands from an unprivileged user, no?
(root would still need to be used for iptables, of course)
1) I'll look into using nice. Have you noticed c10t causing excess lag on your system? All of my test systems are multi-core, and since the Minecraft server cannot use more than a single core itself, I have yet to see an issue.
2) The shell script itself can be run as root (or a user account if you choose), so that it can be used in your system's startup process. The Minecraft server process is not run as root, that would be a security hazard. The USER_NAME variable declares which account to use, defaulting to 'minecraft'. Take a look at the internal method execute(), it is used by all other methods when submitting a command to the OS.
Registered just to say, thank you for this script. It's made running my group's minecraft servers a pleasure. I've had to make a few tweaks to the script(Mostly disabling the whole 'restart the server on a SEVERE error'. It liked restarting the server several times in a row.), but for the most part, this has worked as-is for about half a dozen maps now.
I added the SEVERE error catching when powered rails first hit MC, my servers kept locking up due to a MC bug. I found that it was easy to catch the error with the script and issue a restart command to the server before the lockup happened via the code in the script. Since this bug has since been fixed, I have no issue removing this code from the script, if you think it is worth it.
I am however curious as to why you are having SEVERE errors happening on your sever in the first place, I haven't seen that message type in my logs since that bug was fixed.
Thank you for the great script! It has made running my server a breeze. I recently moved my server to a ramdisk with a symbolic link in the worlds directory to my /dev/shm partition. This unfortunately broke my backup cron script because tar by default does not follow symbolic links it archives the link instead. To fix this I added a -h to the backup tar command and all was right in the world.
Thanks again for coding this script for the community :smile.gif:
It looks like I will be pushing a new version of the script out in the near future. I'll have tar follow symbolic links by default in that new version, it makes sense.
There are no Bashisms in this script, I went to great length to avoid using any Bash extensions so that this script would work under any POSIX compliant shell, including Dash (the newish default system shell in Debian land). There are a number of Perl one-liners in the code to handle the messy pattern matching, but every *NIX out there comes with Perl installed by default, AFAIK. I could switch the code over to using awk instead of Perl with a little effort, I just like programming in Perl.
My apologies, should be more specific. I suppose as I have largely adopted bash to be my main shell, I tend to refer to them as bash script despite the shell-agnostic use you have in your own scripts. Perl is actually quite nice and definitely available everywhere. I myself wrote it out in python, expecting that all *NIX systems would be carrying that by default as well.
1) I'll look into using nice. Have you noticed c10t causing excess lag on your system? All of my test systems are multi-core, and since the Minecraft server cannot use more than a single core itself, I have yet to see an issue.
2) The shell script itself can be run as root (or a user account if you choose), so that it can be used in your system's startup process. The Minecraft server process is not run as root, that would be a security hazard. The USER_NAME variable declares which account to use, defaulting to 'minecraft'. Take a look at the internal method execute(), it is used by all other methods when submitting a command to the OS.
1) I personally haven't run into c10t mapping issues, but for the most part, I consider mapping to be lower priority by far, and thus even a CPU deprioritizing seems to have only upsides . In fact, I recently built in support for pigmap as an alternative mapper (which is substantially more CPU-heavy, IO heavy, and RAM hogging), but with ionice (idle mode), I can guarantee zero impact to the server, even if mapping during live gameplay.
I saw the execute() command, but I was more focusing on the 'usage' example provided in the top posting. Its simply just an observation and edge case if in fact the user running that command is not in /etc/sudoers. And with /etc/init.d, isn't sudo redundant? Shouldn't the script be ultimately run by 'root' anyway, even if the processes that spawn are from the new, unprivileged user?
Output from those commands:
That's after a sudo su www-data.
I don't expect you to fix my problems with this, since the script wasn't really intended for this use, but really appreciate all of your assistance. It's be nice to have help at least trying to figure it out!
This should give you access to that terminal.
I don't know the password for the www-data account since I didn't specifically create it. Looking around online it doesn't have a password of its own that can be accessed.
You don't need the password for the www-data user.
This sequence of commands should show you the contents of the two screens, assuming you are still connected via /dev/pts/5, and screen -ls still outputs the same info:
screen -r 22014.minecraft-world
I am surprised that both screens complain about not being about to bind to the port.
Do you have two startup scripts in the /etc/init.d directory, is that the reason there is two worlds starting? I'm grasping for answers right now..
Yes. I have /etc/init.d/minecraft_server and /etc/init.d/minecraft_server_www. The first one is set to USER_NAME=myusername and the _www is set to USER_NAME=www-data. Both files are owned by myusername and in the www-data group with 755 permissions.
I can run all commands locally just fine via the first one. My CGI (.sh) scripts listed previously look at the _www file. I did this to avoid the username mismatch error. I am a Linux newbie, so perhaps moving it out of the /etc/init.d file would be correct? I didn't realize what that folder did specifically until now.
I never took into account that someone might want to have two copies of the script running at the same time. I can make some changes to the script that should make it work since you were able to help identify the section of code that needs to be modified. However, each copy of the script is going to need to use a different port, say 25565 and 25566. You will either need to modify the DEFAULT_PORT variable or change the worlds.conf file that gets generated.
The easiest solution is to pick one of the scripts and delete it:
minecraft_server I use for the server to run. I run the scripts locally from it.
minecraft_server_www Is supposed to be looking at the same server (I guess now that assumption was wrong?) and use the apache username in the file so the website can access it.
Despite the permissions allowing www-data to access all of my minecraft server's files and the minecraft_server file it fails when I try to set it as user www-data and run commands from the minecraft_server file.
It won't work that way. Just have the www-data run the minecraft server so that apache can have the access it needs.
1. Set the USER_NAME variable in /etc/init.d/minecraft_server to www-data
2. Make sure www-data is part of the admin group. Make sure the permissions on your Minecraft server files and the /etc/init.d/minecraft_server include www-data as the user or the group. "chmod 755" and "chgrp www-data" can be used for this. www-data needs access to all of the files in order for the scripts to work fully.
3. Your website needs to have Apache configured with CGI and able to run .sh files. Here's an example of my START.sh file in my /home/www/cgi-bin/ directory:
To call this script from my webpage I use a standard HTML link:
4. Make sure you're patient with running the start, restart, and update scripts. They take quite a while. Also, look at your if you run into trouble.
Setting up a webpage to activate/manage the server was a fun task. It's made management of the server easier for normal running circumstances for me and my friends (especially the less tech-savvy ones).
Again, BIG THANK YOU!! to sandain! Your script is great and serves many purposes, once I figure out what Linux wanted from me. (: Your assistance has made this possible; I had no idea about www-data running the scripts and that was the root of my problems (I needed the permissions setup for it).
Good luck to anyone trying this. The script run and managed locally works beautifully!
Thanks I wanted to look into doing something like this, thanks for the write up
Nice job Nevra! I'm glad that you were able to get this working! Thanks for the write-up too; as soon as I get the new hard drive for my currently broken server, I might give this a try myself.
Thanks again for coding this script for the community :smile.gif:
Just two mentions:
1) You might consider 'nice'-ing, or 'ionice'ing the mapping. Probably nice should be enough though.
2) Should minecraft be run as 'root' (a la 'sudo')? Should be equivalent in performance and function to run the commands from an unprivileged user, no?
(root would still need to be used for iptables, of course)
There are no Bashisms in this script, I went to great length to avoid using any Bash extensions so that this script would work under any POSIX compliant shell, including Dash (the newish default system shell in Debian land). There are a number of Perl one-liners in the code to handle the messy pattern matching, but every *NIX out there comes with Perl installed by default, AFAIK. I could switch the code over to using awk instead of Perl with a little effort, I just like programming in Perl.
1) I'll look into using nice. Have you noticed c10t causing excess lag on your system? All of my test systems are multi-core, and since the Minecraft server cannot use more than a single core itself, I have yet to see an issue.
2) The shell script itself can be run as root (or a user account if you choose), so that it can be used in your system's startup process. The Minecraft server process is not run as root, that would be a security hazard. The USER_NAME variable declares which account to use, defaulting to 'minecraft'. Take a look at the internal method execute(), it is used by all other methods when submitting a command to the OS.
I added the SEVERE error catching when powered rails first hit MC, my servers kept locking up due to a MC bug. I found that it was easy to catch the error with the script and issue a restart command to the server before the lockup happened via the code in the script. Since this bug has since been fixed, I have no issue removing this code from the script, if you think it is worth it.
I am however curious as to why you are having SEVERE errors happening on your sever in the first place, I haven't seen that message type in my logs since that bug was fixed.
It looks like I will be pushing a new version of the script out in the near future. I'll have tar follow symbolic links by default in that new version, it makes sense.
My apologies, should be more specific. I suppose as I have largely adopted bash to be my main shell, I tend to refer to them as bash script despite the shell-agnostic use you have in your own scripts. Perl is actually quite nice and definitely available everywhere. I myself wrote it out in python, expecting that all *NIX systems would be carrying that by default as well.
1) I personally haven't run into c10t mapping issues, but for the most part, I consider mapping to be lower priority by far, and thus even a CPU deprioritizing seems to have only upsides . In fact, I recently built in support for pigmap as an alternative mapper (which is substantially more CPU-heavy, IO heavy, and RAM hogging), but with ionice (idle mode), I can guarantee zero impact to the server, even if mapping during live gameplay.
I saw the execute() command, but I was more focusing on the 'usage' example provided in the top posting. Its simply just an observation and edge case if in fact the user running that command is not in /etc/sudoers. And with /etc/init.d, isn't sudo redundant? Shouldn't the script be ultimately run by 'root' anyway, even if the processes that spawn are from the new, unprivileged user?