I am currently working on a script for BZFS to work like apachectl. Is there any way of controlling the server from a separate process, i.e. not the one that launched it, without using loging in to bzadmin? I'm looking for a better force-shutdown method than
You can use the -pidfile option of bzfs to write out the PID (Process ID) of the bzfs instance to a file of your choice. Then you can use that PID what you want to close down a specific server.
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)
blast wrote:You can use the -pidfile option of bzfs to write out the PID (Process ID) of the bzfs instance to a file of your choice. Then you can use that PID what you want to close down a specific server.
Thanks, but do you know how to start a background process in sh?
A process will be sent to the background by placing an ampersand (&) sign after the command. There are many tutorials and references online to find BASH and linux scripts that you can search for. No need to ask here.
sigonasr2 wrote:A process will be sent to the background by placing an ampersand (&) sign after the command.
I already tried this and output is still in the same terminal. I want to be able to run my script, and close the window without it closing bzfs. I've already asked around a bunch of other forums and I still can't find an answer. Nohup redirects output to a file but I don't need the output at all! Also Nohup causes some strange output in the current window.
I want to launch bzfs in a seperate process that would be the same as if you double clicked it. BZFS should be left running like a regular unix daemon as a child of init.
Last edited by Gamma Ray on Mon Jun 18, 2012 11:41 pm, edited 1 time in total.
How about screen? Screen is a tool that lets you put something up, then it runs in a separate virtual "window" on your system, leaving it be while you take care of other things. I believe screen can accept an input file to execute when it is launched if that helps at all.
There are some good things to know about it. You would have to learn how to attach and detach from screens, and even the ability to create child windows inside one screen. It can all be done, you could private message me for more details on doing it this way.
sigonasr2 wrote:A process will be sent to the background by placing an ampersand (&) sign after the command.
I already tried this and it still in the same terminal. I want to have be able to run my script, and close the window without it closing bzfs. I've already asked around a bunch of other forums and I still can't find an answer. Nohup redirects out put to a file but I don't need the output at all! Also Nohup causes some strange output in the current window.
I want to launch bzfs in a seperate process that would be the same as if you double clicked it. BZFS should be left running like a regular unix daemon as a child of init.
Learn how to use nohup...
There is nothing worse than aggressive stupidity. -- Johann Wolfgang von Goethe
"How many legs does a dog have if you call his tail a leg? Four. Calling a tail a leg doesn't make it a leg." -- Abraham Lincoln
#!/bin/bash
touch stop
if [ -e pid ]
then
kill `cat pid`
sleep 5
fi
if [ -e pid ]
then
kill -9 `cat pid`
rm pid
fi
I have my servers run from their own account, and each server is in their own directory. I have a 'shared' directory that contains these scripts as well as my ban/group/etc files, and then each server's directory has symlinked copies of the scripts. So then I can run the 'stop.sh' script in that server's folder and it will shut that one down. Both scripts assume they are being run from the server's folder.
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)
#!/bin/sh
#
# if you like symbolic links:
# BZFS_EXEC_L '/Library/BZFlagServer/bin/'
BZFS_EXEC_L='/Applications/BZFlag-2.4.0.app/Contents/MacOS/'
BZFS_FILE_L='/Library/BZFlagServer/'
#bold=`tput bold`
#nobold=`tput rmso`
start(){
exec "$BZFS_EXEC_L"bzfs #-conf "$BZFS_FILE_L"conf/bzfs.conf $2
}
force_stop(){
echo 'It is recommended to shutdown the server with the stop command. Terminating bzfs this way can result in lost data.'
echo 'Are you sure you want to force the server to terminate? [y/n]:'
read -n1 -s tmp
if [ $tmp = 'y' ];then
echo 'sending SIGTERM ...'
tmp=`killall bzfs`
if [ $tmp = 'No matching processes' ];then
echo 'BZFlag Server is not running or could not be stopped.'
else
echo 'BZFlag Server Terminated'
fi
else
echo 'Aborted'
fi
}
help(){
echo ' start : start the BZFlag Server'
echo ' stop : stop the BZFlag Server'
echo ' restart : stops and starts the BZFlag Server'
echo ' term : terminate running BZFlag Server'
echo ' help : displays this help'
echo ''
}
fall(){
echo 'BZFlag Server Control Interface for:'
exec "$BZFS_EXEC_L"bzfs -v
}
case $1 in
'start')start;;
'stop')shutdwn;;
'restart')shutdwn;start;;
'term')force_stop;;
'help')help;;
*)fall;;
esac
Also note that I do start my servers within a screen instance and the original shell that starts them remains running. I haven't tried launching them straight from a shell to see if they keep running after I close it.
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)
In general any process that runs from the shell directly will terminate if that terminal connection is closed. Running it in screen or putting it to a background process will allow it to continue running without problems. Although screen is your best option for still allowing input through the interface at this point.
sigonasr2 wrote:In general any process that runs from the shell directly will terminate if that terminal connection is closed. Running it in screen or putting it to a background process will allow it to continue running without problems. Although screen is your best option for still allowing input through the interface at this point.
Actually you can run from the terminal and leave it running. There is a order to things. Run the server as you would normally do. 'bzfs -conf coolmap.conf >> coolmap.log &' or run any script with the following '&'. Then do Ctrl+C, and the important part, you must exit the terminal with the command 'exit' instead of closing the terminal window. The same could be done with any script or action.
Not to throw a big wrinkle into this.... but how would you run multiple maps? Each requires it's own instance of bzfs, which is unlike apache sites.
There is nothing worse than aggressive stupidity. -- Johann Wolfgang von Goethe
"How many legs does a dog have if you call his tail a leg? Four. Calling a tail a leg doesn't make it a leg." -- Abraham Lincoln
joevano wrote:Not to throw a big wrinkle into this.... but how would you run multiple maps? Each requires it's own instance of bzfs, which is unlike apache sites.
The same way, just start as many instances of bzfs or any proc, following each command with Ctrl+C. Then use exit to close the terminal. Or write a simple script to start them all, with a simple sleep timer to ensure they have time to start.
joevano wrote:Not to throw a big wrinkle into this.... but how would you run multiple maps? Each requires it's own instance of bzfs, which is unlike apache sites.
The same way, just start as many instances of bzfs or any proc, following each command with Ctrl+C. Then use exit to close the terminal. Or write a simple script to start them all, with a simple sleep timer to ensure they have time to start.
Right, but he wants to write startup scripts to treat bzfs like a service [like apache]. As far as I can think it through... they are all separate processes and writing something like the apache control script would/could get a bit hairy when dealing with multiple processes. Especially when you want to recycle a single map, without messing with ones that have current players. It can be done, just needs to be planned for.
There is nothing worse than aggressive stupidity. -- Johann Wolfgang von Goethe
"How many legs does a dog have if you call his tail a leg? Four. Calling a tail a leg doesn't make it a leg." -- Abraham Lincoln
Don't see what those Ctrl+c's are actually doing. You're already back at the shell when those bzfs instances start since they are being backgrounded. It's just likely that the server output makes you think the shell prompt isn't there. If you hit the Enter key or clear the terminal with Ctrl+L, you'll see a shell prompt again.
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)
joevano, I misunderstood the wrinkle you spoke of, I was thinking of running multiple processes in the same terminal session.
blast, Ctrl+C serves the same purpose as Ctrl+L, without clearing the terminal, so there is a history of what I've done. I'm getting forgetful, it simply helps me to remember.