Changes between Version 19 and Version 20 of UbuntuRunningDeepaMehtaAsDaemon
- Timestamp:
- 11.02.2013 06:38:11 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
UbuntuRunningDeepaMehtaAsDaemon
v19 v20 1 1 [[PageOutline]] 2 2 3 = Running DeepaMehta as a Daemon on Ubuntu 1 0.04 or likewise systems =3 = Running DeepaMehta as a Daemon on Ubuntu 12.04 or likewise systems = 4 4 5 5 You 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. … … 8 8 9 9 == Download DeepaMehta == 10 Download the latest stable version of DeepaMehta from [[http s://github.com/jri/deepamehta/downloads|GitHub]]:11 {{{ 12 wget http s://github.com/downloads/jri/deepamehta/deepamehta-4.XXX.YYY.zip10 Download the latest stable version of DeepaMehta from [[http://demo.deepamehta.de/|our build server]]: 11 {{{ 12 wget http://demo.deepamehta.de/download/deepamehta-4.XXX.YYY.zip 13 13 }}} 14 14 … … 68 68 # PATH should only include /usr/* if it runs after the mountnfs.sh script 69 69 PATH=/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 72 NAME="deepamehta" 73 #NAME=$( echo $0 | awk -F'/' '{ print $NF }' ) 74 DESC="DeepaMehta daemon" 75 USER="deepamehta" 76 DAEMON=/usr/lib/deepamehta/deepamehta-daemon 77 EXTRA_ARGS="--chuid $USER:$USER --background --make-pidfile" 78 DAEMON_ARGS="/etc/deepamehta/$NAME.conf" 79 PIDFILE=/var/run/$USER/$NAME.pid 76 80 SCRIPTNAME=/etc/init.d/$NAME 77 81 … … 83 87 84 88 # create PID directory 85 if [ ! -d /var/run/$NAME ]; then 86 mkdir /var/run/$NAME 87 chown $NAME:$NAME /var/run/$NAME 89 if [ ! -d /var/run/$USER ]; then 90 mkdir /var/run/$USER 91 chown $USER:$USER /var/run/$USER 92 sleep 2 88 93 fi 89 94 90 95 # Read configuration variable file if it is present 91 96 [ -r /etc/default/$NAME ] && . /etc/default/$NAME 97 98 # Create logfile if configured 99 if [ ! -z $LOG_DEEPAMEHTA_INIT ] && [ ! -f $LOG_DEEPAMEHTA_INIT ]; then 100 touch $LOG_DEEPAMEHTA_INIT 101 chown $USER:$USER $LOG_DEEPAMEHTA_INIT 102 fi 92 103 93 104 # Load the VERBOSE setting and other rcS variables … … 106 117 # 1 if daemon is not running 107 118 # 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 }' ) 110 120 if [ "$PIDLNUM" != "" ]; then 111 121 if [ -f $PIDFILE ]; then 112 122 PIDFNUM=$( cat $PIDFILE ) 113 123 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?" 115 125 return 2 116 126 else … … 118 128 fi 119 129 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." 121 131 return 2 122 132 fi … … 131 141 do_start() 132 142 { 143 # Check START_DEEPAMEHTA 144 if [ "$START_DEEPAMEHTA" != "yes" ]; then 145 echo " $DESC is disabled in /etc/default/$NAME." 146 exit 0 147 fi 133 148 # Return 134 149 # 0 if daemon has been started 135 150 # 1 if daemon was already running 136 151 # 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 ) 139 154 # Add code here, if necessary, that waits for the process to be ready 140 155 # to handle requests from services started subsequently which depend … … 157 172 # 2 if daemon could not be stopped 158 173 # other if a failure occurred 159 echo -n " Stopping $DESC ... "174 echo -n " Stopping instance $NAME of $DESC ... " 160 175 status_of_daemon && start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE 161 176 RETVAL="$?" … … 191 206 case "$1" in 192 207 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 ) 199 209 ;; 200 210 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 ) ) 207 212 ;; 208 213 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." 210 215 ;; 211 216 restart|force-reload) … … 214 219 # 'force-reload' alias 215 220 # 216 log_daemon_msg "Restarting $DESC" "$NAME"221 echo " Restarting instance $NAME of $DESC" 217 222 status_of_daemon && do_stop 218 223 case "$?" in 219 224 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 226 226 ;; 227 227 *) … … 240 240 : 241 241 242 #EOF 242 #EOF 243 243 }}} 244 244