Sign in to follow this  
HalestormXV

Restarter Help Linux Server

Recommended Posts

Alright I have been hosting servers for a while now. Whether it be via personal computer or hosting companies etc. I always have enjoyed doing it. However I decided to change it up a bit and host my server off a Linux VPS and it works wonderfully. My only question/problem is I am entirely new to Linux and sh scripts. I am trying to get a decent re-starter for my server. One that ideally can detect if the server has crashed as well as schedule a restart at set intervals to essentially preserve server freshness. I did some heavy google searching and i found a wonderful .sh script but I can't get it to work properly.

 

As I said, i found this googleing and I made some changes: http://pastebin.com/J3DCS9pK

 

My question becomes: Does anyone have any nice restarters to share? 

 

OR

 

On the script i linked how can I get it to run properly. Every time I try to execute it, it terminates saying the directory does not exist. Now I have changed the piece of code where it say dirname to the directory that my .jar is and still no luck. 

 

 

Share this post


Link to post
Share on other sites

Hi there

I'm new to linux too, but I like to have a look at all sorts of shell scripts, and like to understand them.

If I get this right, then the MC_PATH variable contains the path of the shell script file. So I think you have to place it in the Minecraft Server Folder.

I'm not at home right now though, so this is only guessing since I can't try it.

Did you place the shell file in the minecraft folder? If you did, and it didn't help, then maybe a qucik excerpt of your changes might help.

 

cheers

 

Edit: I just tested it. Works for me, but I don't have the .jar file it tries to start, so i get an error there of course.

Edited by Haulvarn

Share this post


Link to post
Share on other sites

Alright. The script still didnt work. It is terminating by saying:

 

/server.properties: No such file or directory

line 38: syntax error near unexpected token `done'  (yes it has a ` and a ')

line 38: `done'

 

 

The .sh file is in the main server folder where the .jar is located as well as the server.properties file. Now if I manually put in the MC_PORT constant then the only error I get is the two syntax ones. 

 

Yes I tried by leaving 

MC_PATH=$(dirname "$(readlink -fn "$0")")

 

and I also tried doing

MC_PATH=$(7Sanctums "$(readlink -fn "$0")")

MC_PATH=$(/7Sanctums "$(readlink -fn "$0")")

MC_PATH=$(../7Sanctums "$(readlink -fn "$0")")

 

7Sanctums in the minecraft server folder where the .jar and the .properties, the mods files and folders are etc. etc.

Edited by HalestormXV

Share this post


Link to post
Share on other sites

ok, so basically what this '$(dirname "$(readlink -fn "$0")")' does is, that it returns the path of the shell file, without the filename.

if you started './testfolder/test.sh' then MC_PATH would contain './testfolder/'.

You can't just replace 'dirname' without removing the stuff after it, because dirname is a function that works with the returnvalue of readlink. Replacing it with 7sanctums doesn't work, because it isn't a function.

Edit: you also need to remove the $ before, and the brackets around it, because that initiates the execution of a function

 

You should however be able to replace '$(dirname "$(readlink -fn "$0")")' with your path though. Not sure if it had to be in single quotes, double quotes or no quotes at all though, but that should be easy to find out by trying, or asking google (I might try it a bit later).

 

As for the 'No such file or directory' error: Again, I can't try it with the actuall server files, as I'm not at home, but I tried placing an empty file called server.properties in my script folder, and it worked. there was no error.

 

Here's one thing you can try though: after the 'MC_PATH=$(dirname "$(readlink -fn "$0")")' you insert a new line 'echo $MC_PATH'. now when you execute the script it shows you the path it's using, and expecting the server files to be in.

 

Hope this helps you.

Edited by Haulvarn

Share this post


Link to post
Share on other sites

This helped wonders. I found out it seems the issue was not with the directory but with locating the server.properties file. The script seemed to be assuming the the server.properties file was its own directory so I modified it and added in the the echo debug and it seemed to detect the directory as well as the correct port number. The only error left is this strange one. It says it a syntax error and I am not familiar with .sh enough to find it however other scripts have the same restart end piece.

 

The exact error is:

 

MCPCStarter.sh: line 43: syntax error near unexpected token `done'

MCPCStarter.sh: line 43: `done'

 

Here is the updated code: http://pastebin.com/LL6L7REu

Edited by HalestormXV

Share this post


Link to post
Share on other sites

hmmm... very strange...

I took your code, executed it, and this is what I got:

'

$ ./test2.sh
0
/cygdrive/c/app
1

3
Error: Unable to access jarfile mcpc-plus-1.6.4-R2.1-forge965-B243.jar
Server shutting down in 3 seconds!
Server shutting down in 2 seconds!
Server shutting down in 1 second!
Shutdown..
'

so it seems to be working properly...

A collegue of mine just had an idea though: Apparently some versions of linux and/or unix don't support the 'true' keyword.

Maybe try replacing it with '[ 0 -eq 0 ]', that should have the same effect.

 

EDIT: Another idea would be, that you have windows linebreaks in your file. Try replacing 'rn' with 'n' for the entire file.

EDIT2: Another idea from a colegue is that you might not have bash, but only shell which might not support some of the commands. try executing this: 'ls -la /bin/sh /bin/bash'. if it doesn't return a line for bin/bash, then you might want to install it. Maybe also execute this '/bin/sh --version' to check what shell version you're running.

 

If none of the above help, then you linux system and version might help us find the solution.

Edited by Haulvarn

Share this post


Link to post
Share on other sites
I executed those commands and these were the results.
 
[[email protected] 7Sanctums]# ls -la /bin/sh /bin/bash
-rwxr-xr-x 1 root root 768664 Jul 10  2013 /bin/bash
lrwxrwxrwx 1 root root      4 Feb 13 20:07 /bin/sh -> bash
[[email protected] 7Sanctums]# /bin/sh --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright © 2005 Free Software Foundation, Inc.
[[email protected] 7Sanctums]#
 
I also did the replace method that you suggested in the first edit. Now when I execute it....it SEEMS to work. I executed it as bash MCPCStarter.sh and it started up....Hopefuly that was the right way to do it. My next question becomes how can i execute this in a screen of its own so that I can close my session and this will still run and check if the server is running and if it crashes re-execute in a new screen?. I imagine you cant do screen "bash MCPCStarter.sh" right?
 
Like I said, when I say I am new to this I mean literally I am learning this as I go and I have only been operating on Linux for a little over a week.
Edited by HalestormXV

Share this post


Link to post
Share on other sites

I'm afraid I never used Screen, and so I can't tell you what you need to do to get it working...

however, you shouldn't have to explicitly start the shell by writing 'bash MCPCStarter.sh', just 'MCPCStarter.sh' should work aswell.

 

If I understand Screen correctly however, you first need to create a new session, then connect to that session, and just execute the shell. After that you disconnect form the session (I think :P).

 

Anyway, glad to hear that you got the script running :)

Share this post


Link to post
Share on other sites

Yes the screen is one of the things I have been using all the time. To execute the screen I use the screen command. I am able to start the script in the screen and it seems to work fine. Then I can detach the screen and close out my session with CTRL+A and then CTRL+D. I am curious to know if there is a way to execute the script and have it auto-start a screen session. Any information on that or even links for guidance is appreciated. As I said I am new to all of this and I truely would like to learn it.

But as for the script itself it seems to work and I must thank you for that. I would have never guessed that the windows line breaks were causing the issues. So I apprecaite that.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this