Wednesday, September 22, 2010

MacOS X Terminal Page Up/Down Fix

By default in the terminal application the “Page Up” and “Page Down” keys do not send an actual page up sequence to a session but are used to scroll the terminal buffer. I find this is not acceptable when I have to use programs that have their own buffer, like when I run an editor in a ssh session or I'm reading a man page.


This is how to get an x-term like behaviour:


  • Go to Terminal->Preferences->[Settings]->[Keyboard]
  • Find pg up, and pg down and change 'Action' to 'send string to shell:'.
    Click on the entry field and enter \033[5~ for Page Up
    and \033[6~ for Page Down. Remember that \033 is the Esc key!
  • Assign the buffer scrolling actions to Shift-Page Up and Shift-Page Down.
  •  

Other useful codes are \033[1~ for Home and \033[4~ for End.

Tuesday, September 7, 2010

RHEL/Centos init script for a starman web application

#!/bin/bash
#
# myapp-http        This starts and stops myapp http
#
# chkconfig: 345 56 50
# description: http server for myapp
#
# pidfile: /var/run/myapp-http.pid

PATH=/sbin:/bin:/usr/bin:/usr/sbin

# Source function library.
. /etc/init.d/functions

# Get config.
test -f /etc/sysconfig/network && . /etc/sysconfig/network

# Check that we are root ... so non-root users stop here
[ `id -u` = 0 ] || exit 1

# Check that networking is up.
[ "${NETWORKING}" = "yes" ] || exit 0

RETVAL=0

STARMAN="/usr/bin/starman"
MYAPP_HOME="/home/myapp/production"
PID_FILE="/var/run/myapp-http.pid"
PORT=8000
HOST=127.0.0.1
STARMAN_OPTS="-D -E deploy --pid $PID_FILE -I$MYAPP_HOME/lib --listen $HOST:$PORT $MYAPP_HOME/app.psgi"

start(){
    echo -n $"Starting myapp-http: "

    daemon --pidfile $PID_FILE $STARMAN "$STARMAN_OPTS"
    RETVAL=$?
    echo
    touch /var/lock/subsys/myapp-http
    return $RETVAL
}

stop(){
    echo -n $"Stopping $prog: "
    killproc -p $PID_FILE $prog  
    RETVAL=$?
    echo
    rm -f /var/lock/subsys/myapp-http
    return $RETVAL

}

restart(){
    stop
    start
}

condrestart(){
    [ -e /var/lock/subsys/myapp-http ] && restart
    return 0
}


# See how we were called.
case "$1" in
    start)
 start
 ;;
    stop)
 stop
 ;;
    status)
 status -p $PID_FILE starman
 ;;
    restart)
 restart
 ;;
    condrestart)
 condrestart
 ;;
    *)
 echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
 RETVAL=1
esac

exit $RETVAL