Instalación del servidor CDO como servicio en Linux

De Document Product Lines wiki
Revisión del 18:04 17 jul 2013 de Agomez (discusión | contribs.) (Página creada con 'Para instalar el servidor de CDO como servicio al inicio usando SysV en Linux se proporciona el siguiente script. <code> #! /bin/bash # /etc/init.d/cdo # ### BEGIN INIT INFO #…')
(difs.) ← Revisión anterior | Revisión actual (difs.) | Revisión siguiente → (difs.)

Para instalar el servidor de CDO como servicio al inicio usando SysV en Linux se proporciona el siguiente script.

  1. ! /bin/bash
  2. /etc/init.d/cdo
      1. BEGIN INIT INFO
  1. Provides: cdo-server 1.1
  2. Required-Start: $all
  3. Required-Stop: $all
  4. Should-Start: $syslog
  5. Should-Stop: $syslog
  6. Default-Start: 2 3 4 5
  7. Default-Stop: 0 1 6
  8. Short-Description: DPLfw CDO server
      1. END INIT INFO


  1. This script starts and stops the CDO server in background, and attaches
  2. the OSGi console to port 23. The OSGi console can be controlled via telnet.
  1. Must be run after other services have been started to
  2. ensure that the server is able to create a connection
  1. Some things that run always

LOCK=/run/lock/cdo.pid SVCDIR=/opt/cdo-server/linux.gtk.x86-1.1/eclipse/ FIFO=/run/lock/cdo.fifo

  1. Error codes

ERUNNING=10 ENORUNNING=20

echoerr() {

 echo "$@" 1>&2;

}

chkrunning() {

 if [ -e $LOCK ]; then
   # LOCK exists, check PID
   # Get saved PID
   PID=$(cat $LOCK)
   # Get nameof the binary running with pid $PID
   PROCPID=$(ps -p $PID -o comm --no-headers)
   # If process with pid $PID is cdo-server, the service is running
   if [ "$PROCPID" == "cdo-server" ]; then
     return $ERUNNING
   else
     return $ENORUNNING
   fi
 else
   # LOCK does not exist, not running
   return $ENORUNNING
 fi

}

dostart() {

 # AL CREATED FILES WIL BE ONLY ACCESIBLE BY ROOT
 umask 077
 ################################################
 cd $SVCDIR
 # Check if server is running
 chkrunning
 if [ $? -eq $ERUNNING  ]; then
   return $ERUNNING
 fi
 # At this point no other live instance of cdo-server
 # should hold the LOCK and the FIFO
 # However, this is not always true if an unexpected error
 # has ocurred.
 # If any other instance of the cdo service is still running,
 # the LOCK file will be reset and the FIFO disconnected
 # Unlink any existing FIFO silently
 # and create a new one
 unlink $FIFO > /dev/null 2>&1
 mkfifo $FIFO
 # Move to server dir (required to resolve config files)
 cd $SVCDIR
 # Start service in background
 $SVCDIR/cdo-server -console 23 > $FIFO 2>&1 &
 NEWPID=$!
 # Save the new PID to LOCK
 echo $NEWPID > $LOCK
 # Monitor server output from FIFO until server is loaded
 awk -v PID=$NEWPID '{
   print $0;
   if ($0 == "[INFO] CDO server started") {
     exit 0;
   } else if ($1 == "[ERROR]") {
     print "An error ocurred, killing process!";
     system("kill -9 " PID);
     exit 1;
   }
 }' $FIFO
 # The AWK command detected an error!
 if [ $? -ne 0 ]; then
   # If there are no instances of cdo-server running
   # (for example, the service failed to start when invoked by
   # rc.d boot scripts), delete the LOCK and the FIFO
   CDOSRVRUNNING=$(ps -C cdo-server)
   if [ $CDOSRVRUNNING ]; then
     rm -f $LOCK
     rm -f $FIFO
   fi
 fi

}

dostop() {

 # Check if server is running
 chkrunning
 if [ $? -eq $ERUNNING ]; then
     echo -e "\nclose" | telnet localhost &> /dev/null &
     cat $FIFO
     rm $LOCK
     unlink $FIFO
 else
   return $ENORUNNING
 fi

}

  1. Carry out specific functions when asked to by the system

case "$1" in

 start)
   dostart
   if [ $? -eq $ERUNNING ]; then
     echoerr "CDO service already running!"
   fi
   ;;
 stop)
   dostop
   if [ $? -eq $ENORUNNING ]; then
     echoerr "CDO service not running!"
   fi
   ;;
 restart)
   dostop
   dostart
   ;;
 *)
   echo "Usage: /etc/init.d/cdo {start|stop|restart}"
   exit 1
   ;;

esac

exit 0