If you are serious about hosting a Pootle server for any length of time you probably want to implement service scripts that allow you to start and stop Pootle using your systems convention for service scripts.
As a simple solution you can probably start by using something like
nohup PootleServer > /var/log/pootle.log 2>&1 &
and integrate this by example with similar service scripts for your distribution.
The following are example service scripts for Red Hat and Debian (they can quite easily be used on Fedora and Ubuntu).
This is for RedHat 7.3, but the idea can be applied by copying other service scripts on your machine and adapting for Pootle.
#!/bin/bash # # /etc/rc.d/init.d/pootle # # Starts the pootle daemon # # Source function library. . /etc/init.d/functions pootledir=/var/www/pootle pidfile=pootle.pid prog="pootlewebserver" test -x $pootledir/$prog || (echo $pootledir/$prog not found - aborting ; exit 0) RETVAL=0 # # See how we were called. # start() { # Check if pootle is already running if [ ! -f /var/lock/subsys/pootle ]; then echo -n $"Starting $prog: " daemon $pootledir/$prog RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pootle echo fi return $RETVAL } stop() { echo -n $"Stopping $prog: " # killproc $pootledir/$prog # TODO: fix this to use killproc if [ -f $pootledir/$pidfile ] then pid=`<$pootledir/$pidfile` kill -9 $pid success "pootle shutdown" else failure "pootle shutdown" fi rm -f $pootledir/$pidfile RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/pootle echo return $RETVAL } restart() { stop start } reload() { restart } status_at() { local base=pootle local pid # First try "pidof" pid=`ps -eo "%p.%a" | grep pootle.py | grep -v grep | grep ${base} | cut -d. -f1` if [ -n "$pid" ] && grep pootle /proc/$pid/cmdline > /dev/null ; then processcount=`pgrep -P $pid | wc -l | xargs echo` echo $"${base} (pid $pid) is running... ($processcount children)" grep ^Vm /proc return 0 fi # Next try "/var/run/*.pid" files if [ -f $pootledir/$pidfile ] ; then read pid < $pootledir/$pidfile pid2=`ps -p ${pid} -o "%p.%a" | grep pootle | cut -d. -f1` pid2=`echo ${pid2}` if [ "$pid" = "$pid2" ] ; then processcount=`pgrep -P $pid | wc -l | xargs echo` echo $"${base} (pid $pid) is running... ($processcount children)" grep ^Vm /proc/$pid/status return 0 fi if [ -n "$pid" ]; then echo $"${base} dead but pid file exists (pid ${pid})" return 1 fi fi # See if /var/lock/subsys/${base} exists if [ -f /var/lock/subsys/${base} ]; then echo $"${base} dead but subsys locked" return 2 fi echo $"${base} is stopped" return 3 } case "$1" in start) start ;; stop) stop ;; reload|restart) restart ;; condrestart) if [ -f /var/lock/subsys/pootle ]; then restart fi ;; status) status_at ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|status}" exit 1 esac exit $? exit $RETVAL
pootlewebserver mentioned above is a script to trap errors and redirect output, something like this:
#!/bin/bash traperror() { # don't do anything, just prevent signals from killing the shell script echo trapped error... } export srcpath=/var/www/pootle/src/ export pootlesrc=$srcpath/Pootle/ export controldir=/var/www/pootle/ trap traperror SIGQUIT SIGKILL SIGTERM ( nice -n 1 python $pootlesrc/PootleServer --port 8989 --prefsfile $controldir/pootle.prefs \ --instance wordforge --htmldir=$pootlesrc/html/ --pidfile=$controldir/pootle.pid \ --servertype=threaded # --autorestart --maxrequests=500 ) >> $controldir/results.log 2>&1 &
If you are using a Debian type distro such as Ubuntu, you can use the following start up scripts.
#!bin/bash # /etc/init.d/pootle: start and stop the Pootle Server # Pootle runs as user -pootle- via sudo PREFIX=/vol2 test -x /usr/bin/PootleServer || exit 0 . /lib/lsb/init-functions case "$1" in start) log_begin_msg "Starting Pootle Server..." $PREFIX/bin/start_pootle_iptables /usr/bin/sudo -u pootle $PREFIX/bin/start_pootle & log_end_msg 0 ;; stop) log_begin_msg "Stopping Pootle Server..." $PREFIX/bin/stop_pootle >/dev/null 2>&1 $PREFIX/bin/stop_pootle_iptables >/dev/null 2>&1 log_end_msg 0 ;; restart) log_begin_msg "Stopping Pootle Server..." $PREFIX/bin/stop_pootle >/dev/null 2>&1 log_end_msg 0 log_begin_msg "Starting Pootle Server..." sudo -u pootle $PREFIX/bin/start_pootle & log_end_msg 0 ;; status) $PREFIX/bin/status_pootle ;; *) log_success_msg "Usage: /etc/init.d/pootle {start|stop|restart|status}" exit 1 esac exit 0
Where $PREFIX is the folder where we place customized start, stop, status scripts
The init.d script calls five different scripts that can be customized: start_pootle, stop_pootle, status_pootle, start_pootle_iptables and stop_pootle_iptables. In the example we start Pootle as user pootle in port 8081, separate the error from the normal logs and redirect connections from port 80 to port 8081
start_pootle:
#!/bin/bash # $PREFIX/bin/start_pootle # Start script in port 8081, separates errors from normal logs /usr/bin/PootleServer --prefsfile=/vol2/etc/0.9.prefs -p 8081 $@ > /vol1/var/log/pootle_`date "+%F_%T"` 2> /vol1/var/log/pootle_`date "+%F_%T"`.err
stop_pootle:
#!/bin/bash # Stop script $PREFIX/bin/stop_pootle # TODO. Use pidof instead? echo "Killing Pootle" pidpootle=`ps -ef |grep PootleServer |grep python | awk '{print $2}'` pidpootle2=`ps -ef |grep start_pootle |grep bin | awk '{print $2}'` kill $pidpootle2 >/dev/null 2>&1 kill $pidpootle >/dev/null 2>&1
status_pootle:
#!/bin/bash # Pootle Status $PREFIX/bin/status_pootle pidpootle=`ps -ef |grep PootleServer |grep python | awk '{print $2}'` if [ "$pidpootle" != "" ] then echo "Pootle Server running in pid ("$pidpootle")" else echo "Pootle Server is not running" fi
start_pootle_iptables:
#!/bin/bash # $PREFIX $PREFIX/bin/start_pootle_iptables # Creates port redirection # /sbin/iptables -t nat -A PREROUTING -i eth+ -p tcp --dport 80 -j REDIRECT --to-port 8081
stop_pootle_iptables:
#!/bin/bash # $PREFIX $PREFIX/bin/stop_pootle_iptables # Deletes port redirection # /sbin/iptables -t nat -D PREROUTING -i eth+ -p tcp --dport 80 -j REDIRECT --to-port 8081