[]SOLVED[] Linux Start Script

Discussion in 'Bukkit Discussion' started by Rjames426, May 8, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Rjames426

    Hey guys I am trying to setup a Bukkit server for a friend on his Linux distro, I got the server to run and everything but was wondering if theres a way to run the server just by double clicking the .sh file (like you do on Windows BAT file) instead of typing the directory in the terminal everytime. (I HAVE CHECKED THE WIKI)

    If this is possible can someone send me there folder with this configed or explain it to me so i have a better understanding

    SOLVED ON MY OWN.
     
  2. Offline

    Fabrikantje

    Please show the others how you did it. :)
     
  3. Offline

    Rjames426

    I wanted the script to start the server in the terminal without having to type commands or cd into the folder (as we all are familiar with how Windows handles it), I started out by typing in the command, as you would normally in terminal (cd Desktop/BukkitServer), and used "java -Xmx1024M -Xms1024M -jar craftbukkit.jar" to execute the JAR. I had a small hunch and decided to place these commands in a my Run.sh file and "Run in Terminal", I got an error saying it could not cd into "Desktop/BukkitServer", then realized I don't need the cd into "Desktop/BukkitServer" since this is where the Run.sh file is executing anyways.

    END RESULT: Typing "java -Xmx1024M -Xms1024M -jar craftbukkit.jar" into my Run.sh (located in the server directory) and running it in the terminal gave me the results i wanted.

    IF YOU WOULD LIKE ME TO WRITE A FULL TUTORIAL (that is easier to understand) LEAVE A COMMENT BELOW!
     
  4. Offline

    tfuller82

    Hello. I'm very much new here but wanted to expand on this for anyone who comes across it looking for help. It's actually a very good idea to have the "cd" line of your script to make things more portable. From what I understand you tried cd /Desktop/BukkitServer. The reason that did not work is because this line implies that Desktop is located in the root directory. When it actually exists at /home/<usermame>/Desktop/. You could also just use the global variable for the home directory which is $HOME. Here is an example of how you could make a simple startup script.
    Code:
    #/bin/bash
     
    cd $HOME/Desktop/BukkitServer/
     
    screen -S bukkit -d -m java -Xincgc -Xmx1G -jar craftbukkit.jar
    
    What this would do is launch your server in a screen. You could then get to your console from the terminal by typing screen -r bukkit. Think of screen as a way to multitask with the command line. screen -ls would list any sessions you have open and screen -r <session_name> would reattach to it. (ctrl) + a and then pressing d would detach from a connected screen session.

    Now to expand even farther, let's setup a script to automatically backup your world just in case anything happens. First Make a directory in your BukkitServer directory called Backup and then create a script with the following lines.

    Code:
    #!/bin/bash
     
    year=`date +%Y`
    month=`date +%m`
    day=`date +%d`
    hour=`date +%H`
     
    cd $HOME/Desktop/BukkitServer/Backup
     
    find $HOME/Desktop/BukkitServer/Backup/* -mtime +5 -exec rm {} \;
     
    zip -9 -r $year.$month.$day.$hour.bukkit.zip $HOME/Desktop/BukkitServer/
    
    This script would delete any backups that are more than 5 days old while creating a new backup each time it is run. For instance a backup ran today at 6pm would have the following filename. 2012.05.10.18.bukkit.zip

    Now, I'm sure you would like this script to run automatically so you don't have to worry about it. Let's say you named it backup.sh and have it in your BukkitServer directory. To set this script to run automatically you can use what is called a cron job. A cron job will run at times you designate. In your terminal type crontab -e. You will probably get a question asking which editor to use. I always use nano because it's easiest for me. Assuming you don't have any other cron jobs setup you will see a file that is nothing but comments. Add this line at the bottom:

    Code:
    0 0,6,12,18 * * * $HOME/Desktop/BukkitServer/backup.sh
    
    You can do research if your interested in all the ins and outs of cron jobs but for simplicity's sake this will run your backup script at 12 AM, 6 AM, 12 PM, and 6 PM. You can adjust the second column accordingly to change the amount and times it is run.

    I realize this is probably way more than what you're asking for but I wanted to make my first post here as helpful as possible. Also, I am by no means a linux expert and have learned a lot in the past 6 months or so. So, I'm sure with any of my tips, there is probably a more elegant solution. Anyways I hope some of you find this useful.
     
  5. Offline

    Rjames426

    tfuller82 Thanks for your comment! I might actually try this backup script!

    Also using cd ~/Desktop/BukkitServer will look in the Home directory.
     
  6. Offline

    tfuller82

    No problem. I hope you found it somewhat useful. I feel like I'm just now coming to grips with Linux so I'm extra eager to help out and discuss all things Linux. Good call on the ~, much shorter to write. :)
     
  7. Offline

    Rjames426

    tfuller82 Simplicity is key. Keep up on the helpful posts.

    What is the #!/bin/bash used for?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  8. Offline

    tfuller82

    It's convention so Linux knows what interpreter to run. Theoretically scripts can be in anything, python, perl, etc... Bash is almost always default and honestly I've written a lot of scripts leaving that line out and they function just fine.
     
Thread Status:
Not open for further replies.

Share This Page