Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.93 KB | None | 0 0
  1. #! /bin/sh
  2. #
  3. # atop init script
  4.  
  5. ### BEGIN INIT INFO
  6. # Provides:          atop
  7. # Required-Start:    $syslog $remote_fs
  8. # Required-Stop:     $syslog $remote_fs
  9. # Should-Start:      $local_fs
  10. # Should-Stop:       $local_fs
  11. # Default-Start:     2 3 4 5
  12. # Default-Stop:      0 1 6
  13. # Short-Description: Monitor for system resources and process activity
  14. # Description:       Atop is an ASCII full-screen performance monitor,
  15. #                    similar to the top command, but atop only shows
  16. #                    the active system-resources and processes, and
  17. #                    only shows the deviations since the previous
  18. #                    interval.
  19. ### END INIT INFO
  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="atop system monitor"
  24. NAME=atop
  25. DAEMON=/usr/bin/atop
  26. WRAPPER=/usr/share/atop/atop.wrapper
  27. INTERVAL=600            # interval 10 minutes
  28. LOGPATH="/var/log/atop"
  29. OUTFILE=$LOGPATH/daily.log
  30. PIDFILE=/var/run/$NAME.pid
  31. SCRIPTNAME=/etc/init.d/$NAME
  32.  
  33. # Exit if the package is not installed
  34. [ -x $DAEMON ] || exit 0
  35.  
  36. # Read configuration variable file if it is present
  37. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  38.  
  39. # Load the VERBOSE setting and other rcS variables
  40. . /lib/init/vars.sh
  41.  
  42. # Define LSB log_* functions.
  43. . /lib/lsb/init-functions
  44.  
  45. CURDAY=$(date +%Y%m%d)
  46. DAEMON_ARGS="-a -w $LOGPATH/atop_$CURDAY $INTERVAL"
  47.  
  48. #
  49. # Function that starts the daemon/service
  50. #
  51. do_start()
  52. {
  53.         # Return
  54.         #   0 if daemon has been started
  55.         #   1 if daemon was already running
  56.         #   2 if daemon could not be started
  57.         start-stop-daemon --start --background --quiet \
  58.         --pidfile $PIDFILE \
  59.         --test --startas $WRAPPER > /dev/null \
  60.                 || return 1
  61.         start-stop-daemon --start --background --quiet \
  62.             --pidfile $PIDFILE --make-pidfile \
  63.         --startas $WRAPPER -- $DAEMON $OUTFILE \
  64.                 $DAEMON_ARGS \
  65.                 || return 2
  66. }
  67.  
  68. #
  69. # Function that stops the daemon/service
  70. #
  71. do_stop()
  72. {
  73.         # Return
  74.         #   0 if daemon has been stopped
  75.         #   1 if daemon was already stopped
  76.         #   2 if daemon could not be stopped
  77.         #   other if a failure occurred
  78.         start-stop-daemon --stop --quiet --retry=USR2/30/KILL/5 --pidfile $PIDFILE --name $NAME
  79.     RETVAL="$?"
  80.         [ "$RETVAL" = 2 ] && return 2
  81.         rm -f $PIDFILE
  82.         return "$RETVAL"
  83. }
  84.  
  85. case "$1" in
  86.   start)
  87.     [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
  88.     do_start
  89.     case "$?" in
  90.                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  91.                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  92.     esac
  93.   ;;
  94.   stop)
  95.         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  96.         do_stop
  97.         case "$?" in
  98.                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  99.                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  100.         esac
  101.         ;;
  102.   status)
  103.        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  104.        ;;
  105.   restart|force-reload|_cron)
  106.     [ "$1" = "_cron" ] && VERBOSE="no"
  107.         [ "$VERBOSE" != no ] && log_daemon_msg "Restarting $DESC" "$NAME"
  108.         do_stop
  109.         case "$?" in
  110.           0|1)
  111.                 do_start
  112.                 case "$?" in
  113.                         0) [ "$VERBOSE" != no ] && log_end_msg 0
  114.                [ "$1" = "_cron" ] && sleep 3 && find $LOGPATH -name 'atop_*' -mtime +28 -exec rm {} \;
  115.                    ;;
  116.                         1) [ "$VERBOSE" != no ] && log_end_msg 1 ;; # Old process is still running
  117.                         *) [ "$VERBOSE" != no ] && log_end_msg 1 ;; # Failed to start
  118.                 esac
  119.                 ;;
  120.           *)
  121.                 # Failed to stop
  122.                 [ "$VERBOSE" != no ] && log_end_msg 1
  123.                 ;;
  124.         esac
  125.         ;;
  126.   *)
  127.     echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  128.     exit 1
  129.     ;;
  130. esac
  131.  
  132. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement