Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.21 KB | None | 0 0
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          skeleton
  4. # Required-Start:    $remote_fs $syslog
  5. # Required-Stop:     $remote_fs $syslog
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Atos SIPS Office Server
  9. # Description:       This init script allows to launch Atos SIPS Office Server
  10. #
  11. #                    placed in /etc/init.d.
  12. ### END INIT INFO
  13.  
  14. # Author: xxx <xxx@xxx>
  15. #
  16. # Please remove the "Author" lines above and replace them
  17. # with your own name if you copy and modify this script.
  18.  
  19. # Do NOT "set -e"
  20.  
  21. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  22. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  23. DESC="Atos SIPS Office Server"
  24. NAME=atos-server
  25. SCRIPTNAME=/etc/init.d/$NAME
  26. DAEMON=`which java`
  27.  
  28. # Dynamically determine daemon location depending on environment
  29. if [ "$HOSTNAME" = "lab" ]
  30. then
  31.         SERVER_ROOT="/data/users/$USER/cpg/atos_office_server/server"
  32.         CONFIG_FILE="$SERVER_ROOT/config/dev.config.xml"
  33.         PIDFILE=/tmp/$NAME.pid
  34. else
  35.         SERVER_ROOT=/data/misc/xxx/atos_office_server/server/
  36.         CONFIG_FILE="$SERVER_ROOT/config/prod.config.xml"
  37.         PIDFILE=/var/run/$NAME.pid
  38. fi
  39.  
  40. ARCHIVES="$SERVER_ROOT/lib/apiServer.jar:"
  41. POLICY="$SERVER_ROOT/policy/client.policy"
  42. CONFIG_FILE="$SERVER_ROOT/config/dev.config.xml"
  43. CLASS=com.atosorigin.services.cad.apiserver.watchdog.ProcessWatchdog
  44. DAEMON_ARGS="-cp $ARCHIVES -Djava.security.policy=$POLICY -Dconfigfile=$CONFIG_FILE $CLASS"
  45.  
  46. # Exit if the package is not installed
  47. # [ -x "$ARCHIVES" ] || exit 0
  48.  
  49. # Read configuration variable file if it is present
  50. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  51.  
  52. # Load the VERBOSE setting and other rcS variables
  53. . /lib/init/vars.sh
  54.  
  55. # Define LSB log_* functions.
  56. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  57. # and status_of_proc is working.
  58. . /lib/lsb/init-functions
  59.  
  60. #
  61. # Function that starts the daemon/service
  62. #
  63. do_start()
  64. {
  65.         # Return
  66.         #   0 if daemon has been started
  67.         #   1 if daemon was already running
  68.         #   2 if daemon could not be started
  69.         start-stop-daemon --start --chuid thomas --quiet --verbose --make-pidfile --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  70.                 || return 1
  71.         start-stop-daemon --start --chuid thomas --quiet --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- \
  72.                 $DAEMON_ARGS \
  73.                 || return 2
  74.         # Add code here, if necessary, that waits for the process to be ready
  75.         # to handle requests from services started subsequently which depend
  76.         # on this one.  As a last resort, sleep for some time.
  77. }
  78.  
  79. #
  80. # Function that stops the daemon/service
  81. #
  82. do_stop()
  83. {
  84.         # Return
  85.         #   0 if daemon has been stopped
  86.         #   1 if daemon was already stopped
  87.         #   2 if daemon could not be stopped
  88.         #   other if a failure occurred
  89.         start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  90.         RETVAL="$?"
  91.         [ "$RETVAL" = 2 ] && return 2
  92.         # Wait for children to finish too if this is a daemon that forks
  93.         # and if the daemon is only ever run from this initscript.
  94.         # If the above conditions are not satisfied then add some other code
  95.         # that waits for the process to drop all resources that could be
  96.         # needed by services started subsequently.  A last resort is to
  97.         # sleep for some time.
  98.         start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  99.         [ "$?" = 2 ] && return 2
  100.         # Many daemons don't delete their pidfiles when they exit.
  101.         rm -f $PIDFILE
  102.         return "$RETVAL"
  103. }
  104.  
  105. #
  106. # Function that sends a SIGHUP to the daemon/service
  107. #
  108. do_reload() {
  109.         #
  110.         # If the daemon can reload its configuration without
  111.         # restarting (for example, when it is sent a SIGHUP),
  112.         # then implement that here.
  113.         #
  114.         start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  115.         return 0
  116. }
  117.  
  118. #
  119. # Function that ouputs the name of the developer that started the server if in lab environment
  120. #
  121. get_owner() {
  122.         OWNER=
  123.         if [ "$HOSTNAME" = "lab" ]
  124.         then
  125.                 OWNER=`ps aux| grep -m 1 '[a]tos_office_server\/server\/lib\/apiServer.jar' | awk '{print $1}'`
  126.         fi
  127.         return 0
  128. }
  129.  
  130. case "$1" in
  131.   start)
  132.         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  133.         if [ -z "$OWNER" ]
  134.         then
  135.                 echo "Starting..."
  136.                 do_start
  137.                 case "$?" in
  138.                         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  139.                 esac
  140.         else
  141.                 echo "Atos Office Server has already been started by $OWNER!"
  142.                 log_end_msg 1
  143.         fi
  144.         ;;
  145.   stop)
  146.         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  147.         do_stop
  148.         case "$?" in
  149.             0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  150.             2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  151.         esac
  152.         ;;
  153.   status)
  154.         status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  155.         ;;
  156.   #reload|force-reload)
  157.         #
  158.         # If do_reload() is not implemented then leave this commented out
  159.         # and leave 'force-reload' as an alias for 'restart'.
  160.         #
  161.         #log_daemon_msg "Reloading $DESC" "$NAME"
  162.         #do_reload
  163.         #log_end_msg $?
  164.         #;;
  165.   restart|force-reload)
  166.         #
  167.         # If the "reload" option is implemented then remove the
  168.         # 'force-reload' alias
  169.         #
  170.         log_daemon_msg "Restarting $DESC" "$NAME"
  171.         do_stop
  172.         case "$?" in
  173.           0|1)
  174.                 do_start
  175.                 case "$?" in
  176.                         0) log_end_msg 0 ;;
  177.                         1) log_end_msg 1 ;; # Old process is still running
  178.                         *) log_end_msg 1 ;; # Failed to start
  179.                 esac
  180.                 ;;
  181.           *)
  182.                 # Failed to stop
  183.                 log_end_msg 1
  184.                 ;;
  185.         esac
  186.         ;;
  187.   *)
  188.         echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  189.         exit 3
  190.         ;;
  191. esac
  192.  
  193. :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement