Writing a Startscript


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Writing a Startscript
# 1  
Old 12-30-2014
Java Writing a Startscript

I hope I have found the perfect place for my problem ...

I have a dedicated server with some minecraftservers (java) which are connected via a Bungeecord on it.
These all have a start.sh which looks in its folder like this:

Code:
screen -A -m -d -S SERVERNAME java -jar -Xmx2048M -Xms2048M spigot.jar

The stop.sh looks like this:

Code:
screen -S SERVERNAME -X quit


I would like to combine the scripts, that you must perform only one file to start/stop the servernetwork...
It would be perfect if there was skript, which allows to start/stop the servers seperately AND together.... But I have no idea if such a programm is even possible Smilie In another Forum they said i wouldn't be that hard to wirte something like that. They said I'd have to write a Start/Stop/Status script for the servers seperately and combine them in another script. Would be really nice if someone would help Smilie The gameservers are running a screen when they are online. It would be brilliant if I could check the Status of the servers. (The script has to check if there is a screen online with the name "XY")

I look forward to your answers Smilie

Yours sincerely
Spongebob

PS: Sorry for my bad english Smilie



I tried really hard with this one, but the status isn't working that fine and i can't connect the scripts:

Code:
#!/bin/bash
INSTANZ="Bungeecord"
BPDIR=/home/bungeecord
Pidfile=/home/Steuerung/bungee.pid

if [ -f $Pidfile ]
then
	Pid=`cat $Pidfile`
fi

case "$1" in
'start')
		if [ -f $Pidfile ] ; then
				if test `ps -e | grep -c $Pid` = 1; then
						echo "Not starting $INSTANZ - instance already running with PID: $Pid"
				else
						echo "Starting $INSTANZ"
						cd $BPDIR
						nohup ./start.sh &> /dev/null &
						echo $! > $Pidfile
				fi
		else
				echo "Starting $INSTANZ"
				cd $BPDIR
				nohup ./bsp.sh &> /dev/null &
				echo $! > $Pidfile
		fi
		;;

'stop')
		if [ -f $Pidfile ] ; then
				echo "stopping $INSTANZ"
					cd $BPDIR
						nohup ./stop.sh &> /dev/null &
						echo $! > $Pidfile
		else
				echo "Cannot stop $INSTANZ - no Pidfile found!"
		fi
		;;

'restart')
		$0 stop
		sleep 30
		$0 start
		;;

'status')
		if [ -f $Pidfile ] ; then
				if test `ps -e | grep -c $Pid` = 0; then
						echo "$INSTANZ not running"
				else
						echo "$INSTANZ running with PID: [$Pid]"
				fi
		else
				echo "$Pidfile does not exist! Cannot process $INSTANZ status!"
				exit 1
		fi
		;;

*)
		echo "usage: $0 { start | stop | restart | status }"
		;;

esac
exit 0


Last edited by jim mcnamara; 12-30-2014 at 08:10 AM..
# 2  
Old 12-30-2014
RE: status
If you are going to test Pidfile for zero lines,
Code:
if test `ps -e | grep -c $Pid` = 0; then

... try
Code:
> $Pidfile  # instead of echo $! > $Pidfile

when you 'stop' or initialize $Pidfile

Last edited by ongoto; 12-30-2014 at 09:24 AM..
This User Gave Thanks to ongoto For This Post:
# 3  
Old 12-30-2014
Quote:
Originally Posted by ongoto
RE: status
If you are going to test Pidfile for zero lines,
Code:
if test `ps -e | grep -c $Pid` = 0; then

... try
Code:
> $Pidfile  # instead of echo $! > $Pidfile

when you 'stop' or initialize $Pidfile
Great, the Status-Test is working now. But do you know if it is possible to test if there is a screen on with a specified name instead? And how to combine these scripts into one?
# 4  
Old 12-30-2014
Quote:
Originally Posted by Spongebob
Great, the Status-Test is working now. But do you know if it is possible to test if there is a screen on with a specified name instead? And how to combine these scripts into one?
Screen is a pretty complex monster. There is a command to list sessions...
Code:
screen -ls
screen --list

You might be able to incorporate that output into your scripts.
See man screen
This User Gave Thanks to ongoto For This Post:
# 5  
Old 12-30-2014
Quote:
Originally Posted by ongoto
Screen is a pretty complex monster. There is a command to list sessions...
Code:
screen -ls
screen --list

You might be able to incorporate that output into your scripts.
See man screen
I know this command. But I don't know how to check if there is a screen with a specified name in this list... Do you know?

And do you know how to combine my startscripts? It's more important to me to start all servers with one command Smilie
# 6  
Old 12-30-2014
Sorry. Smilie
I don't know enough about screen or servers to help you there. I'm sure someone will come along who does.
This User Gave Thanks to ongoto For This Post:
# 7  
Old 12-30-2014
Quote:
Originally Posted by ongoto
Sorry. Smilie
I don't know enough about screen or servers to help you there. I'm sure someone will come along who does.
Still a huge Thank you Smilie You helped me out very good, now I have a running script, but not the way I want it to be Smilie Hopefully someone else will know how to do Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Not writing output

In the attached bash in the convert function the out_position.txt in not being writing to the annovar directory and I can not figure out why. Thank you :). (2 Replies)
Discussion started by: cmccabe
2 Replies

2. How to Post in the The UNIX and Linux Forums

Help with script writing?

I am new for script writing. I have a file named as name.dat and contain numbers with different rows and columns. I want to sum numbers at one row with that of at another row; like row1 + row101 + row 201, with corresponding columns. Any one can help me to write a script for this operation. ... (1 Reply)
Discussion started by: kumnegert
1 Replies

3. AIX

hacmp application startscript issue

Hi, I am setting up a hacmp oracle cluster with 2 resource groups - one on each node. Binaries are local - so is configuration but its the same on both nodes - so are the startscripts. If I start the cluster, each DB comes up nicely on its homenode. Now I have the problem that when I... (1 Reply)
Discussion started by: zxmaus
1 Replies

4. Shell Programming and Scripting

Help in writing a script

Hey everyone Can anyone please write me a script to display numbers in descending order dynamically i.e if the user enter a number say 100 then the output should be like 100 99 ....so on till 0 I tried using the logic as for ((i =1; i<=100; i--) but the it goes into a infinite loop since even the... (7 Replies)
Discussion started by: icchi
7 Replies

5. UNIX for Dummies Questions & Answers

writing a new file

I have one sample file that contains one question and multiple choice with answer. I need to print the question and answer in another file. Answer is printed next to one of the correct choice. e.g. 1. Capital of USA (A) USA (B) Washington (C) New York (B) (D) New Delhi so i want the... (4 Replies)
Discussion started by: blackeyed
4 Replies

6. UNIX for Dummies Questions & Answers

Which process is doing all the writing

Hi We are running an IBM P570 with AIX and Unidata. The disk monitor in nmon is showing that one of our logical volumes is hitting 100% most of the time, and that 98% of it is write. I am trying to identify the top processes in terms of disk IO, obviously particularly write so that we... (4 Replies)
Discussion started by: idwalton72
4 Replies

7. Solaris

PID / Startscript

Hi, I have a startscript on solaris 10 which does not work properly. #!/sbin/sh PIDFILE=/opt/app_y/PID.log case $1 in 'start') /usr/local/bin/app_y -C /opt/app_y/local.cfg echo $! > $PIDFILE ;; esac exit $? The problem is that the PIDFILE is empty.... (3 Replies)
Discussion started by: victorinox
3 Replies

8. Programming

writing functions

I have to write a program in C++ using several functions. The program consists of ticket sales how many if you are an adult, junior, or toddler and if there are any discounts. I have the program working up to the pricing function. when i put the discount in the equation it <strike>do</strike>... (1 Reply)
Discussion started by: ravenswind35
1 Replies

9. Programming

Writing Own Minishell!

Hi, I wanna write my own mini shell as a part of my project. Whole coding is to be donw in C for linux platform. I have got background of linux as well as C but now can anybody please suggest me the sources from where i can find information about how to start ? I have to implement some basic... (4 Replies)
Discussion started by: siddharth_god
4 Replies
Login or Register to Ask a Question