geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jarek Gawor <jga...@gmail.com>
Subject Re: svn commit: r985820 - /geronimo/server/trunk/framework/configs/karaf-framework/src/main/distribution/unix-shell/bin/gserviceReg.sh
Date Mon, 16 Aug 2010 15:04:24 GMT
Can we figure out a better name for this script? For example,
register-service or service-register, etc.?

Jarek

On Mon, Aug 16, 2010 at 4:01 AM,  <xuhaihong@apache.org> wrote:
> Author: xuhaihong
> Date: Mon Aug 16 08:01:40 2010
> New Revision: 985820
>
> URL: http://svn.apache.org/viewvc?rev=985820&view=rev
> Log:
> GERONIMO-5503 Run geronimo as Linux service update (Patch from viola.lu)
>
> Added:
>    geronimo/server/trunk/framework/configs/karaf-framework/src/main/distribution/unix-shell/bin/gserviceReg.sh
  (with props)
>
> Added: geronimo/server/trunk/framework/configs/karaf-framework/src/main/distribution/unix-shell/bin/gserviceReg.sh
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/karaf-framework/src/main/distribution/unix-shell/bin/gserviceReg.sh?rev=985820&view=auto
> ==============================================================================
> --- geronimo/server/trunk/framework/configs/karaf-framework/src/main/distribution/unix-shell/bin/gserviceReg.sh
(added)
> +++ geronimo/server/trunk/framework/configs/karaf-framework/src/main/distribution/unix-shell/bin/gserviceReg.sh
Mon Aug 16 08:01:40 2010
> @@ -0,0 +1,329 @@
> +#!/bin/sh
> +#
> +#  Licensed to the Apache Software Foundation (ASF) under one or more
> +#  contributor license agreements.  See the NOTICE file distributed with
> +#  this work for additional information regarding copyright ownership.
> +#  The ASF licenses this file to You under the Apache License, Version 2.0
> +#  (the "License"); you may not use this file except in compliance with
> +#  the License.  You may obtain a copy of the License at
> +#
> +#      http://www.apache.org/licenses/LICENSE-2.0
> +#
> +#   Unless required by applicable law or agreed to in writing, software
> +#   distributed under the License is distributed on an "AS IS" BASIS,
> +#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +#   See the License for the specific language governing permissions and
> +#   limitations under the License.
> +# --------------------------------------------------------------------
> +#
> +# This script file will invoke startup , shutdown to
> +# start/stop/restart/ server and check server status, also make server autostart
> +# at os boot time.
> +# Usage:
> +#  $server_install_path/bin/gserviceReg.sh add/del/list [service_name]
> +#  [service_name] start/stop/restart/status
> +#--------------------------------------------------------------------
> +
> +# Make sure prerequisite environment variables are set
> +if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
> +    echo "ERROR:  Neither the JAVA_HOME nor the JRE_HOME environment variable is
defined."
> +    echo "At least one of these is required for this program to execute."
> +    echo ""
> +    exit 1
> +fi
> +if [ -z "$JRE_HOME" ]; then
> +   if [ -d "$JAVA_HOME/jre" ]; then
> +     JRE_HOME="$JAVA_HOME/jre"
> +   else
> +     JRE_HOME="$JAVA_HOME"
> +   fi
> +fi
> +cygwin=false
> +os400=false
> +osAix=false
> +osSolaris=false
> +osRedhat=false
> +osSuse=false
> +osUbuntu=false
> +case "`uname`" in
> +CYGWIN*) cygwin=true;;
> +OS400*) os400=true;;
> +AIX*) osAix=true;;
> +SunOS*) osSolaris=true;;
> +Ubuntu*) osUbuntu=true;;
> +Linux*)
> +case "`more /proc/version`" in
> +*Red*Hat*) osRedhat=true;;
> +*SUSE*) osSuse=true;;
> +*Ubuntu*) osUbuntu=true;;
> +esac
> +;;
> +esac
> +# resolve links - $0 may be a softlink
> +PRG="$0"
> +
> +while [ -h "$PRG" ]; do
> +  ls=`ls -ld "$PRG"`
> +  link=`expr "$ls" : '.*-> \(.*\)$'`
> +  if expr "$link" : '/.*' > /dev/null; then
> +    PRG="$link"
> +  else
> +    PRG=`dirname "$PRG"`/"$link"
> +  fi
> +done
> +
> +# Get standard environment variables
> +PRGDIR=`dirname "$PRG"`
> +
> +# Only set GERONIMO_HOME if not already set
> +[ -z "$GERONIMO_HOME" ] && GERONIMO_HOME=`cd "$PRGDIR/.." ; pwd`
> +if [ "$#" -eq "2" ]; then
> +GSERVICE_NAME=${GERONIMO_HOME}/bin/$2
> +fi
> +
> +chmod +x "$GERONIMO_HOME"/bin/*
> +
> +# Check that target executable exists
> +if $os400; then
> +  # -x will Only work on the os400 if the files are:
> +  # 1. owned by the user
> +  # 2. owned by the PRIMARY group of the user
> +  # this will not work if the user belongs in secondary groups
> +  eval
> +else
> +  if [ ! -x "${GERONIMO_HOME}/bin/startup" ]; then
> +    echo "Cannot find ${GERONIMO_HOME}/bin/startup"
> +    echo "This file is needed to run this program"
> +    exit 1
> +  fi
> +  if [ ! -x "${GERONIMO_HOME}/bin/shutdown" ]; then
> +    echo "Cannot find ${GERONIMO_HOME}/bin/shutdown"
> +    echo "This file is needed to run this program"
> +    exit 1
> +  fi
> +fi
> +
> +case "$1" in
> +add)
> +if [ "$#" -lt "2" ]; then
> + echo "Please input service name to be added"
> + exit 1
> +fi
> +echo '#! /bin/bash'>"$GSERVICE_NAME"
> +echo '# chkconfig: 235 99 01'>>"$GSERVICE_NAME"
> +echo "# description: $2 service dameon">>"$GSERVICE_NAME"
> +echo "# /etc/init.d/$2">>"$GSERVICE_NAME"
> +echo '### BEGIN INIT INFO'>>"$GSERVICE_NAME"
> +echo "# Provides:          $2">>"$GSERVICE_NAME"
> +echo '# Required-Start:    $ALL'>>"$GSERVICE_NAME"
> +echo '# Required-Stop:     '>>"$GSERVICE_NAME"
> +echo '# Default-Start:     2 3 5'>>"$GSERVICE_NAME"
> +echo '# Default-Stop:      0 1 2 6'>>"$GSERVICE_NAME"
> +echo "# Short-Description: $2 daemon">>"$GSERVICE_NAME"
> +echo '### END INIT INFO'>>"$GSERVICE_NAME"
> +if $osUbuntu; then
> + echo ". /lib/lsb/init-functions" >>"$GSERVICE_NAME"
> + echo "user=$USER" >>"$GSERVICE_NAME"
> +else
> + echo "user=$USER" >>"$GSERVICE_NAME"
> +fi
> +echo "JAVA_HOME=$JAVA_HOME">>"$GSERVICE_NAME"
> +echo "export JAVA_HOME">>"$GSERVICE_NAME"
> +echo "GERONIMO_HOME=$GERONIMO_HOME">>"$GSERVICE_NAME"
> +echo 'Port_Off_Set=`grep "^PortOffset=" "$GERONIMO_HOME"/var/config/config-substitutions.properties
|awk -F= '\'{print \$2}\'\`>>"$GSERVICE_NAME"
> +echo 'RMI_PORT=`expr $Port_Off_Set \+ 1099`'>>"$GSERVICE_NAME"
> +echo 'ADMIN_USER=system'>>"$GSERVICE_NAME"
> +echo 'ADMIN_PASS=manager'>>"$GSERVICE_NAME"
> +
> +
> +echo 'start() {'>>"$GSERVICE_NAME"
> +echo 'PID_Count=`ps -ef|grep -i "$GERONIMO_HOME"|awk -FS '\'{print \$2}\'\|wc -l\`>>"$GSERVICE_NAME"
> +echo 'if [ $PID_Count -eq 1 ] '>>"$GSERVICE_NAME"
> +echo 'then'>>"$GSERVICE_NAME"
> +echo '{'>>"$GSERVICE_NAME"
> +echo 'echo "Server is started already"'>>"$GSERVICE_NAME"
> +echo '}'>>"$GSERVICE_NAME"
> +echo 'else  '>>"$GSERVICE_NAME"
> +echo '{'>>"$GSERVICE_NAME"
> +if $osUbuntu; then
> +echo 'log_daemon_msg "Starting Server"'>>"$GSERVICE_NAME"
> +echo 'JAVA_HOME="$JAVA_HOME" start-stop-daemon --make-pidfile --pidfile /var/run/geronimo-server.pid
--background --user $user --exec "$GERONIMO_HOME"/bin/geronimo.sh --start -- run'>>"$GSERVICE_NAME"
> +else
> +echo 'echo "Start Server on port $RMI_PORT"'>>"$GSERVICE_NAME"
> +echo 'su $user -s /bin/bash -c "$GERONIMO_HOME/bin/startup"'>>"$GSERVICE_NAME"
> +fi
> +echo '}'>>"$GSERVICE_NAME"
> +echo 'fi'>>"$GSERVICE_NAME"
> +echo '}'>>"$GSERVICE_NAME"
> +
> +echo 'stop() {'>>"$GSERVICE_NAME"
> +if $osUbuntu; then
> + echo 'log_daemon_msg "Stopping Server"'>>"$GSERVICE_NAME"
> + echo 'killproc -p /var/run/geronimo-server.pid || true'>>"$GSERVICE_NAME"
> +else
> +echo 'echo "Shutting down server on port ${RMI_PORT}"'>>"$GSERVICE_NAME"
> +echo '"$GERONIMO_HOME"/bin/shutdown --user "$ADMIN_USER" --password "$ADMIN_PASS" --port
"$RMI_PORT"'>>"$GSERVICE_NAME"
> +fi
> +echo '}'>>"$GSERVICE_NAME"
> +
> +echo 'restart() {'>>"$GSERVICE_NAME"
> +echo 'echo "Restart server on port ${RMI_PORT}"'>>"$GSERVICE_NAME"
> +echo 'PID_Count=`ps -ef|grep -i "$GERONIMO_HOME"|awk -FS '\'{print \$2}\'\|wc -l\`>>"$GSERVICE_NAME"
> +echo 'if [ $PID_Count -eq 1 ] '>>"$GSERVICE_NAME"
> +echo 'then'>>"$GSERVICE_NAME"
> +echo '{'>>"$GSERVICE_NAME"
> +echo '  echo -n -e "\nRestart server.\n"'>>"$GSERVICE_NAME"
> +echo '  stop'>>"$GSERVICE_NAME"
> +echo '  sleep 30'>>"$GSERVICE_NAME"
> +echo '  start'>>"$GSERVICE_NAME"
> +echo '}'>>"$GSERVICE_NAME"
> +echo 'else  '>>"$GSERVICE_NAME"
> +echo '{'>>"$GSERVICE_NAME"
> +echo '  echo -n -e "\nServer is down.Can not restart.\n"'>>"$GSERVICE_NAME"
> +echo '}'>>"$GSERVICE_NAME"
> +echo 'fi'>>"$GSERVICE_NAME"
> +
> +echo '}'>>"$GSERVICE_NAME"
> +
> +echo 'status() {'>>"$GSERVICE_NAME"
> +echo 'echo -n "Check server status on port ${RMI_PORT}"'>>"$GSERVICE_NAME"
> +echo 'PID_Count=`ps -ef|grep -i "$GERONIMO_HOME"|awk -FS '\'{print \$2}\'\|wc -l\`>>"$GSERVICE_NAME"
> +echo 'if [ $PID_Count -eq 1 ] '>>"$GSERVICE_NAME"
> +echo 'then'>>"$GSERVICE_NAME"
> +echo 'echo -n -e "\nServer is started.\n"'>>"$GSERVICE_NAME"
> +echo 'else'>>"$GSERVICE_NAME"
> +echo '  echo -n -e "\nServer is down.\n"'>>"$GSERVICE_NAME"
> +echo 'fi'>>"$GSERVICE_NAME"
> +echo '}'>>"$GSERVICE_NAME"
> +
> +echo 'case "$1" in'>>"$GSERVICE_NAME"
> +echo 'start)'>>"$GSERVICE_NAME"
> +echo 'start'>>"$GSERVICE_NAME"
> +echo ';;'>>"$GSERVICE_NAME"
> +echo 'stop)'>>"$GSERVICE_NAME"
> +echo 'stop'>>"$GSERVICE_NAME"
> +echo ';;'>>"$GSERVICE_NAME"
> +echo 'restart)'>>"$GSERVICE_NAME"
> +echo 'restart'>>"$GSERVICE_NAME"
> +echo ';;'>>"$GSERVICE_NAME"
> +echo 'status)'>>"$GSERVICE_NAME"
> +echo 'status'>>"$GSERVICE_NAME"
> +echo ';;'>>"$GSERVICE_NAME"
> +echo '*)'>>"$GSERVICE_NAME"
> +echo "echo \"Usage: $2 {start|stop|restart|status}\"">>"$GSERVICE_NAME"
> +echo 'exit 1'>>"$GSERVICE_NAME"
> +echo 'esac'>>"$GSERVICE_NAME"
> +
> +chmod +x "$GSERVICE_NAME"
> +if [ ! -x /usr/sbin/$2 ]; then
> +
> +  if $osUbuntu; then
> +   sudo ln -sf "$GSERVICE_NAME" /usr/sbin/"$2"
> +   sudo chmod +x /usr/sbin/"$2"
> +  else
> +    if [ "$USER" = "root" ]; then
> +      ln -sf "$GSERVICE_NAME" /usr/sbin/"$2"
> +      chmod +x /usr/sbin/"$2"
> +    else
> +      sudo ln -sf "$GSERVICE_NAME" /usr/sbin/"$2"
> +      sudo chmod +x /usr/sbin/"$2"
> +    fi
> +  fi
> + if $osSuse; then
> +  if [ "$USER" = "root" ]; then
> +   ln -sf /usr/sbin/"$2" /etc/init.d/"$2"
> +   insserv "$2"
> +   chkconfig "$2" on
> +  else
> +   sudo ln -sf /usr/sbin/"$2" /etc/init.d/"$2"
> +   sudo /sbin/insserv "$2"
> +   sudo /sbin/chkconfig "$2" on
> +  fi
> + fi
> + if $osRedhat; then
> +  if [ "$USER" = "root" ]; then
> +  ln -sf /usr/sbin/"$2" /etc/init.d/"$2"
> +  chkconfig "$2" on
> +  else
> +   sudo ln -sf /usr/sbin/"$2" /etc/init.d/"$2"
> +   sudo /sbin/chkconfig "$2" on
> +  fi
> + fi
> + if $osSolaris; then
> +   if [ "$USER" = "root" ]; then
> +    ln -sf /usr/sbin/"$2" /etc/rc3.d/S99"$2"
> +   else
> +    sudo ln -sf /usr/sbin/"$2" /etc/rc3.d/S99"$2"
> +   fi
> + fi
> + if $osAix; then
> +   echo "$2:2:once:/usr/sbin/$2 start">>/etc/inittab
> + fi
> + if $osUbuntu; then
> +   sudo ln -sf /usr/sbin/"$2" /etc/init.d/"$2"
> +   sudo update-rc.d $2 defaults
> + fi
> +else
> +echo "$2 already exists"
> +exit 1
> +fi
> +;;
> +del)
> +if [ "$#" -lt "2" ]; then
> + echo "Please input service name to be deleted"
> + exit 1
> +else
> + if [ -x /usr/sbin/"$2" ]; then
> + echo "Delete service $2"
> + if $osSuse -o $osRedhat; then
> +  if [ "$USER" = "root" ]; then
> +   chkconfig --del $2
> +   rm -f /etc/init.d/"$2"
> +  else
> +   sudo /sbin/chkconfig --del $2
> +   sudo rm -f /etc/init.d/"$2"
> +  fi
> + fi
> + if $osSolaris; then
> +   if [ "$USER" = "root" ]; then
> +     rm -fr /etc/rc3.d/S99"$2"
> +   else
> +     sudo rm -fr /etc/rc3.d/S99"$2"
> +   fi
> + fi
> + if $osUbuntu; then
> +   sudo update-rc.d -f $2 remove
> +   sudo rm -f /etc/init.d/"$2"
> +   sudo rm -f /usr/sbin/$2
> + fi
> + if [ "$USER" = "root" ]; then
> +  rm -f /usr/sbin/$2
> + else
> +  sudo rm -f /usr/sbin/$2
> + fi
> + rm -f "$GSERVICE_NAME"
> + else
> +  echo "$2 doesn't exist"
> +  exit 1
> + fi
> +fi
> +;;
> +list)
> +if [ "$#" -lt "2" ]; then
> + echo "Please input service name to be listed"
> + exit 1
> +else
> +  if [ -x /usr/sbin/"$2" ]; then
> +  serverfolder=`head -1 /usr/sbin/"$2"|awk -F= '{print $2}'`
> +  echo "$2 for server $serverfolder"
> +  else
> +    echo "$2 doesn't exist"
> +    exit 1
> +  fi
> +fi
> +;;
> +*)
> +echo "Usage: ./gserviceReg.sh add|del|list [required:service name]"
> +exit 1
> +;;
> +esac
>
> Propchange: geronimo/server/trunk/framework/configs/karaf-framework/src/main/distribution/unix-shell/bin/gserviceReg.sh
> ------------------------------------------------------------------------------
>    svn:eol-style = native
>
> Propchange: geronimo/server/trunk/framework/configs/karaf-framework/src/main/distribution/unix-shell/bin/gserviceReg.sh
> ------------------------------------------------------------------------------
>    svn:executable = *
>
> Propchange: geronimo/server/trunk/framework/configs/karaf-framework/src/main/distribution/unix-shell/bin/gserviceReg.sh
> ------------------------------------------------------------------------------
>    svn:keywords = Date Revision
>
>
>

Mime
View raw message