Guest User

/etc/init.d/pvw-start

a guest
Jan 12th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.29 KB | None | 0 0
  1. #! /bin/sh
  2. . /lib/lsb/init-functions
  3. ### BEGIN INIT INFO
  4. # Provides:          pvw-start
  5. # Required-Start:    $remote_fs $syslog
  6. # Required-Stop:     $remote_fs $syslog
  7. # Default-Start:     5
  8. # Default-Stop:      0 1 6
  9. # Short-Description: Start ParaViewWeb launchers
  10. # Description:       This script will automatically start
  11. #                    a ParaViewWeb launcher.
  12. ### END INIT INFO
  13.  
  14. # Author: Sebastien Jourdain <[email protected]>
  15. #
  16. # Do NOT "set -e"
  17.  
  18. NAME=pvw-start
  19.  
  20. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  21. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  22. DESC="Handle ParaViewWeb launcher processes"
  23. DAEMON=/data/start.sh
  24. PIDFILE=/var/run/$NAME-.pid
  25. SCRIPTNAME=/etc/init.d/$NAME
  26.  
  27. # Exit if the package is not installed
  28. [ -x "$DAEMON" ] || exit 0
  29.  
  30. #
  31. # Function that starts the daemon/service
  32. #
  33. do_start()
  34. {
  35.     # Return
  36.     #   0 if daemon has been started
  37.     #   1 if daemon was already running
  38.     #   2 if daemon could not be started
  39.     start-stop-daemon --start --quiet --pidfile $PIDFILE -c ubuntu:www-data --exec $DAEMON --test > /dev/null \
  40.         || return 1
  41.     start-stop-daemon --start --quiet --pidfile $PIDFILE -c ubuntu:www-data --exec $DAEMON -- \
  42.         || return 2
  43.     # Add code here, if necessary, that waits for the process to be ready
  44.     # to handle requests from services started subsequently which depend
  45.     # on this one.  As a last resort, sleep for some time.
  46. }
  47.  
  48. #
  49. # Function that stops the daemon/service
  50. #
  51. do_stop()
  52. {
  53.     # Return
  54.     #   0 if daemon has been stopped
  55.     #   1 if daemon was already stopped
  56.     #   2 if daemon could not be stopped
  57.     #   other if a failure occurred
  58.     start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE -c ubuntu:www-data --name $NAME
  59.     RETVAL="$?"
  60.     [ "$RETVAL" = 2 ] && return 2
  61.     # Wait for children to finish too if this is a daemon that forks
  62.     # and if the daemon is only ever run from this initscript.
  63.     # If the above conditions are not satisfied then add some other code
  64.     # that waits for the process to drop all resources that could be
  65.     # needed by services started subsequently.  A last resort is to
  66.     # sleep for some time.
  67.     start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 -c ubuntu:www-data --exec $DAEMON
  68.     [ "$?" = 2 ] && return 2
  69.     # Many daemons don't delete their pidfiles when they exit.
  70.     rm -f $PIDFILE
  71.     return "$RETVAL"
  72. }
  73.  
  74. #
  75. # Function that sends a SIGHUP to the daemon/service
  76. #
  77. do_reload() {
  78.     #
  79.     # If the daemon can reload its configuration without
  80.     # restarting (for example, when it is sent a SIGHUP),
  81.     # then implement that here.
  82.     #
  83.     start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE -c ubuntu:www-data --name $NAME
  84.     return 0
  85. }
  86.  
  87. case "$1" in
  88.   start)
  89.     [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  90.     do_start
  91.     case "$?" in
  92.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  93.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  94.     esac
  95.     ;;
  96.   stop)
  97.     [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  98.     do_stop
  99.     case "$?" in
  100.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  101.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  102.     esac
  103.     ;;
  104.   status)
  105.     status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  106.     ;;
  107.   #reload|force-reload)
  108.     #
  109.     # If do_reload() is not implemented then leave this commented out
  110.     # and leave 'force-reload' as an alias for 'restart'.
  111.     #
  112.     #log_daemon_msg "Reloading $DESC" "$NAME"
  113.     #do_reload
  114.     #log_end_msg $?
  115.     #;;
  116.   restart|force-reload)
  117.     #
  118.     # If the "reload" option is implemented then remove the
  119.     # 'force-reload' alias
  120.     #
  121.     log_daemon_msg "Restarting $DESC" "$NAME"
  122.     do_stop
  123.     case "$?" in
  124.       0|1)
  125.         do_start
  126.         case "$?" in
  127.             0) log_end_msg 0 ;;
  128.             1) log_end_msg 1 ;; # Old process is still running
  129.             *) log_end_msg 1 ;; # Failed to start
  130.         esac
  131.         ;;
  132.       *)
  133.         # Failed to stop
  134.         log_end_msg 1
  135.         ;;
  136.     esac
  137.     ;;
  138.   *)
  139.     #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  140.     echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  141.     exit 3
  142.     ;;
  143. esac
  144.  
  145. :
Advertisement
Add Comment
Please, Sign In to add comment