Changes between Version 19 and Version 20 of UbuntuRunningDeepaMehtaAsDaemon


Ignore:
Timestamp:
11.02.2013 06:38:11 (12 years ago)
Author:
silke
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UbuntuRunningDeepaMehtaAsDaemon

    v19 v20  
    11[[PageOutline]] 
    22 
    3 = Running DeepaMehta as a Daemon on Ubuntu 10.04 or likewise systems = 
     3= Running DeepaMehta as a Daemon on Ubuntu 12.04 or likewise systems = 
    44 
    55You can of course run DeepaMehta on your computer by simply starting the shell script ''deepamehta-linux.sh'' in a terminal session. But maybe you want to "daemonize" the server and run it in the background. This setup is especially recommended if you want to run DeepaMehta on a server.  
     
    88 
    99== Download DeepaMehta == 
    10 Download the latest stable version of DeepaMehta from [[https://github.com/jri/deepamehta/downloads|GitHub]]: 
    11 {{{ 
    12 wget https://github.com/downloads/jri/deepamehta/deepamehta-4.XXX.YYY.zip 
     10Download the latest stable version of DeepaMehta from [[http://demo.deepamehta.de/|our build server]]: 
     11{{{ 
     12wget http://demo.deepamehta.de/download/deepamehta-4.XXX.YYY.zip 
    1313}}}  
    1414 
     
    6868# PATH should only include /usr/* if it runs after the mountnfs.sh script 
    6969PATH=/sbin:/usr/sbin:/bin:/usr/bin 
    70 DESC="DeepaMehta server" 
    71 NAME=deepamehta 
    72 DAEMON=/opt/deepamehta/deepamehta-linux.sh 
    73 EXTRA_ARGS="-c $NAME --user $NAME --name $NAME --background --make-pidfile" 
    74 DAEMON_ARGS="" 
    75 PIDFILE=/var/run/$NAME/$NAME.pid 
     70 
     71# NAME is the name of the instance of deepamehta 
     72NAME="deepamehta" 
     73#NAME=$( echo $0 | awk -F'/' '{ print $NF }' ) 
     74DESC="DeepaMehta daemon" 
     75USER="deepamehta" 
     76DAEMON=/usr/lib/deepamehta/deepamehta-daemon 
     77EXTRA_ARGS="--chuid $USER:$USER --background --make-pidfile" 
     78DAEMON_ARGS="/etc/deepamehta/$NAME.conf" 
     79PIDFILE=/var/run/$USER/$NAME.pid 
    7680SCRIPTNAME=/etc/init.d/$NAME 
    7781 
     
    8387 
    8488# create PID directory 
    85 if [ ! -d /var/run/$NAME ]; then 
    86      mkdir /var/run/$NAME 
    87      chown $NAME:$NAME /var/run/$NAME 
     89if [ ! -d /var/run/$USER ]; then 
     90    mkdir /var/run/$USER 
     91    chown $USER:$USER /var/run/$USER 
     92    sleep 2 
    8893fi 
    8994 
    9095# Read configuration variable file if it is present 
    9196[ -r /etc/default/$NAME ] && . /etc/default/$NAME 
     97 
     98# Create logfile if configured 
     99if [ ! -z $LOG_DEEPAMEHTA_INIT ] && [ ! -f $LOG_DEEPAMEHTA_INIT ]; then 
     100    touch $LOG_DEEPAMEHTA_INIT 
     101    chown $USER:$USER $LOG_DEEPAMEHTA_INIT 
     102fi 
    92103 
    93104# Load the VERBOSE setting and other rcS variables 
     
    106117    #   1 if daemon is not running 
    107118    #   2 on pidfile mismatch 
    108  
    109     PIDLNUM=$( ps -U $NAME -u $NAME o pid= | sed s'/^\ //' ) 
     119    PIDLNUM=$( ps -U $USER -u $USER o pid= o args= | sed s'/^\ //' | grep $DAEMON_ARGS | awk -F' ' '{ print $1 }' ) 
    110120    if [ "$PIDLNUM" != "" ]; then 
    111121        if [ -f $PIDFILE ]; then 
    112122            PIDFNUM=$( cat $PIDFILE ) 
    113123            if [ "$PIDLNUM" != "$PIDFNUM" ]; then 
    114                 echo "\n   Error in pidfile $PIDFILE! - Is there another $NAME process running?\n" 
     124                echo "   Error in pidfile $PIDFILE! - Is there another $NAME process running for user $USER?" 
    115125                return 2 
    116126            else 
     
    118128            fi 
    119129        else 
    120             echo "\n   WARNING! Found running $DESC with PID $PIDLNUM,\n   but no valid pidfile $PIDFILE was found.\n" 
     130            echo "   WARNING! Found running instance $NAME of $DESC with PID $PIDLNUM and user $USER, but no valid pidfile $PIDFILE was found." 
    121131            return 2 
    122132        fi 
     
    131141do_start() 
    132142{ 
     143        # Check START_DEEPAMEHTA 
     144        if [ "$START_DEEPAMEHTA" != "yes" ]; then 
     145            echo "   $DESC is disabled in /etc/default/$NAME." 
     146            exit 0 
     147        fi 
    133148        # Return 
    134149        #   0 if daemon has been started 
    135150        #   1 if daemon was already running 
    136151        #   2 if daemon could not be started 
    137         echo -n "   Starting $DESC ... " 
    138         status_of_daemon || ( [ "$?" = 1 ] && start-stop-daemon --start $EXTRA_ARGS --quiet --pidfile $PIDFILE --startas $DAEMON $DAEMON_ARGS ) 
     152        echo -n "   Starting instance $NAME of $DESC ... " 
     153        status_of_daemon || ( [ "$?" = 1 ] && start-stop-daemon --start $EXTRA_ARGS --quiet --pidfile $PIDFILE --exec $DAEMON $DAEMON_ARGS ) 
    139154        # Add code here, if necessary, that waits for the process to be ready 
    140155        # to handle requests from services started subsequently which depend 
     
    157172        #   2 if daemon could not be stopped 
    158173        #   other if a failure occurred 
    159         echo -n "   Stopping $DESC ... " 
     174        echo -n "   Stopping instance $NAME of $DESC ... " 
    160175        status_of_daemon && start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE  
    161176        RETVAL="$?" 
     
    191206case "$1" in 
    192207  start) 
    193         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" 
    194         status_of_daemon || ( [ "$?" = 1 ] && do_start ) 
    195         case "$?" in 
    196                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 
    197                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 
    198         esac 
     208        status_of_daemon || ( [ "$?" = 1 ] && ( [ ! -z $LOG_DEEPAMEHTA_INIT ] && echo "$( date +%d.%m.%Y" "%H:%M:%S ) *** Starting $DESC ***">>$LOG_DEEPAMEHTA_INIT ); do_start ) 
    199209        ;; 
    200210  stop) 
    201         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" 
    202         status_of_daemon && do_stop 
    203         case "$?" in 
    204                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 
    205                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 
    206         esac 
     211        status_of_daemon && ( do_stop; ( [ ! -z $LOG_DEEPAMEHTA_INIT ] && echo "$( date +%d.%m.%Y" "%H:%M:%S ) *** Stopping $DESC ***">>$LOG_DEEPAMEHTA_INIT ) ) 
    207212        ;; 
    208213  status) 
    209        status_of_daemon && echo "   $DESC is running with PID $PIDLNUM." || echo "  $DESC is not running." 
     214       status_of_daemon && echo "   Instance $NAME of $DESC is running with PID $PIDLNUM." || echo "   Instance $NAME of $DESC is not running." 
    210215       ;; 
    211216  restart|force-reload) 
     
    214219        # 'force-reload' alias 
    215220        # 
    216         log_daemon_msg "Restarting $DESC" "$NAME" 
     221        echo " Restarting instance $NAME of $DESC" 
    217222        status_of_daemon && do_stop 
    218223        case "$?" in 
    219224          0|1) 
    220                 do_start 
    221                 case "$?" in 
    222                         0) log_end_msg 0 ;; 
    223                         1) log_end_msg 1 ;; # Old process is still running 
    224                         *) log_end_msg 1 ;; # Failed to start 
    225                 esac 
     225                ( [ ! -z $LOG_DEEPAMEHTA_INIT ] && echo "$( date +%d.%m.%Y" "%H:%M:%S ) *** Restarting $DESC ***">>$LOG_DEEPAMEHTA_INIT ); do_start 
    226226                ;; 
    227227          *) 
     
    240240: 
    241241 
    242 #EOF 
     242#EOF     
    243243}}} 
    244244