Created
December 19, 2010 16:11
-
-
Save jakob-stoeck/747435 to your computer and use it in GitHub Desktop.
python poker network startup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# | |
# Copyright (C) 2006 - 2010 Loic Dachary <[email protected]> | |
# Copyright (C) 2004, 2005, 2006 Mekensleep <[email protected]> | |
# 24 rue vieille du temple, 75004 Paris | |
# | |
# This software's license gives you freedom; you can copy, convey, | |
# propagate, redistribute and/or modify this program under the terms of | |
# the GNU Affero General Public License (AGPL) as published by the Free | |
# Software Foundation, either version 3 of the License, or (at your | |
# option) any later version of the AGPL. | |
# | |
# This program is distributed in the hope that it will be useful, but | |
# WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero | |
# General Public License for more details. | |
# | |
# You should have received a copy of the GNU Affero General Public License | |
# along with this program in a file in the toplevel directory called | |
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>. | |
# | |
# Authors: | |
# Loic Dachary <[email protected]> | |
# | |
# http://wiki.debian.org/LSBInitScripts | |
# | |
### BEGIN INIT INFO | |
# Provides: poker-network | |
# Required-Start: $network $remote_fs $syslog | |
# Required-Stop: $network $remote_fs $syslog | |
# Should-Start: mysql | |
# Should-Stop: mysql | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: poker-network server and bots | |
# Description: Multi player online poker server with | |
# bots running according to /etc/poker-network | |
### END INIT INFO | |
# Change this to your virtualenv path | |
MY_VIRTUALENV=/usr/poker_env | |
# | |
# Run bots that will connect to the poker server as instructed | |
# in /etc/poker-network/poker.bot.xml | |
# | |
RUN_BOTS=false | |
# Include python-poker-network defaults if available | |
if [ -f $MY_VIRTUALENV/etc/default/python-poker-network ] ; then | |
. /etc/default/python-poker-network | |
fi | |
twistd=$MY_VIRTUALENV/bin/twistd | |
reactor=poll | |
PATH=$MY_VIRTUALENV/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
name=poker-network | |
desc='poker server ' | |
python=$MY_VIRTUALENV/bin/python | |
python_lib_path=$(python -c 'from distutils import sysconfig; print(sysconfig.get_python_lib())') | |
lockfile=$MY_VIRTUALENV/etc/poker-network/lockfile | |
serverpidfile=/var/run/poker-network-server.pid | |
serverlogfile=/var/log/poker-network-server.log | |
serverplugin=pokerserver | |
serverconfig=$MY_VIRTUALENV/etc/poker-network/poker.server.xml | |
botpidfile=/var/run/poker-network-bot.pid | |
botlogfile=/var/log/poker-network-bot.log | |
botplugin=pokerbot | |
more_args=--no_save | |
test -x ${twistd} || exit 0 | |
set -e | |
case "$1" in | |
start) | |
echo -n "Starting ${desc}: " | |
if [ -f $lockfile ]; then | |
echo " not configured, abort." | |
exit 0; | |
fi | |
${python} ${twistd} \ | |
--pidfile=${serverpidfile} \ | |
--logfile=${serverlogfile} ${more_args} \ | |
--reactor=${reactor} \ | |
${serverplugin} #--config=${serverconfig} | |
if $RUN_BOTS ; then | |
${python} ${twistd} \ | |
--pidfile=${botpidfile} \ | |
--logfile=${botlogfile} ${more_args} \ | |
--reactor=${reactor} \ | |
${botplugin} | |
else | |
echo "Bots are disabled, edit /etc/default/python-poker-network to enable them." | |
fi | |
echo ${name} | |
;; | |
stop) | |
echo -n "Stopping poker server ..." | |
start-stop-daemon --stop --quiet --retry forever/-2/3 --pidfile=${serverpidfile} || true | |
echo " done." | |
if $RUN_BOTS ; then | |
echo -n "Stopping poker bots ..." | |
start-stop-daemon --stop --quiet --retry forever/-2/3 --pidfile=${botpidfile} || true | |
echo "done" | |
fi | |
;; | |
rebot) | |
if $RUN_BOTS ; then | |
echo -n "Stopping poker bots ..." | |
start-stop-daemon --stop --quiet --retry forever/-2/3 --pidfile=${botpidfile} || true | |
echo "done" | |
echo -n "Wait 10 minutes ..." | |
sleep 600 | |
echo "done" | |
echo -n "Starting poker bots ..." | |
${python} ${twistd} \ | |
--pidfile=${botpidfile} \ | |
--logfile=${botlogfile} ${more_args} \ | |
--reactor=${reactor} \ | |
${botplugin} | |
echo "done" | |
else | |
echo "Bots are disabled" | |
fi | |
;; | |
restart|force-reload) | |
# | |
# If the "reload" option is implemented, move the "force-reload" | |
# option to the "reload" entry above. If not, "force-reload" is | |
# just the same as "restart". | |
# | |
$0 stop | |
$0 start | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
echo "Usage: $N {start|stop|restart|force-reload|rebot}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment