view src/sat.sh @ 930:cbf4122baae7

core, memory: use XDG recommended paths as the defaults for the config and local directories
author souliane <souliane@mailoo.org>
date Sun, 23 Mar 2014 22:43:43 +0100
parents 952322b1d490
children 3b30e9f83d88
line wrap: on
line source

#!/bin/sh

#if there is one argument which is "stop", then we kill SàT
DEBUG=""
if [ $# -eq 1 ];then
	if [ $1 = "stop" ];then
		echo "Terminating Salut à Toi"
		pkill -f "twistd.*/sat.tac"
		exit 0
	fi
	if [ $1 = "debug" ];then
		echo "Launching SàT in debug mode"
		DEBUG="--debug"
	fi
fi

NAME='sat'
PYTHON='python'

#We use python to parse config files
eval `"$PYTHON" << PYTHONEND
from sat.core.constants import Const
from ConfigParser import SafeConfigParser
from os.path import expanduser, join
import sys

config = SafeConfigParser(defaults=Const.DEFAULT_CONFIG)
try:
    config.read(Const.CONFIG_FILES)
except:
	print ("echo \"/!\\ Can't read main config ! Please check the syntax\";")
	print ("exit 1")
	sys.exit()

env=[]
env.append("PID_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'pid_dir')),''))
env.append("LOG_DIR='%s'" % join(expanduser(config.get('DEFAULT', 'log_dir')),''))

print ";".join(env)
PYTHONEND
`

PID_FILE="$PID_DIR$NAME.pid"
LOG_FILE="$LOG_DIR$NAME.log"
DAEMON="n"
MAIN_OPTIONS="-${DAEMON}oy"
TAP_PATH="./"
TAP_FILE="$NAME.tac"

#Don't change the next line
AUTO_OPTIONS=""
ADDITIONAL_OPTIONS="--pidfile $PID_FILE --logfile $LOG_FILE $AUTO_OPTIONS $DEBUG"

log_dir=`dirname "$LOG_FILE"`
if [ ! -d $log_dir ] ; then
	mkdir $log_dir
fi

twistd $MAIN_OPTIONS $TAP_PATH$TAP_FILE $ADDITIONAL_OPTIONS