Advertisement
andrum99

/etc/init.d/noip2

Dec 30th, 2013
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.84 KB | None | 0 0
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          noip2
  4. # Required-Start:    $network $local_fs $remote_fs
  5. # Required-Stop:     $network $local_fs $remote_fs
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: no-ip.com updater
  9. # Description:       Service to periodically update no-ip.com
  10. #                    dynamic DNS
  11. ### END INIT INFO
  12.  
  13. # noip2 init script for Debian Wheezy
  14. # Author: Andrew Pattison <andrum99@gmail.com>
  15. # Created 30 December 2013
  16.  
  17. # Do NOT "set -e"
  18.  
  19. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  20. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  21. DESC="dynamic DNS updater"
  22. NAME=noip2
  23. DAEMON=/usr/local/bin/$NAME
  24. DAEMON_ARGS=""
  25. CONFFILE=/usr/local/etc/no-ip2.conf
  26. PIDFILE=/var/run/$NAME.pid
  27. SCRIPTNAME=/etc/init.d/$NAME
  28.  
  29. # Exit if the executable is not present
  30. [ -x "$DAEMON" ] || exit 0
  31.  
  32. # Display message if service not configured
  33. #[ -x "$CONFFILE" ] || printf "Service not configured - please run $DAEMON -C"
  34.  
  35. # Read configuration variable file if it is present
  36. #[ -r /etc/default/$NAME ] && . /etc/default/$NAME
  37.  
  38. # Load the VERBOSE setting and other rcS variables
  39. . /lib/init/vars.sh
  40.  
  41. # Define LSB log_* functions.
  42. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  43. # and status_of_proc is working.
  44. . /lib/lsb/init-functions
  45.  
  46. #
  47. # Function that starts the daemon/service
  48. #
  49. do_start()
  50. {
  51.     # Return
  52.     #   0 if daemon has been started
  53.     #   1 if daemon was already running
  54.     #   2 if daemon could not be started
  55.     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  56.         || return 1
  57.     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  58.         $DAEMON_ARGS \
  59.         || return 2
  60.     # Add code here, if necessary, that waits for the process to be ready
  61.     # to handle requests from services started subsequently which depend
  62.     # on this one.  As a last resort, sleep for some time.
  63. }
  64.  
  65. #
  66. # Function that stops the daemon/service
  67. #
  68. do_stop()
  69. {
  70.     # Return
  71.     #   0 if daemon has been stopped
  72.     #   1 if daemon was already stopped
  73.     #   2 if daemon could not be stopped
  74.     #   other if a failure occurred
  75.     start-stop-daemon --stop --quiet --retry=TERM/5/KILL/5 --pidfile $PIDFILE --name $NAME
  76.     RETVAL="$?"
  77.     [ "$RETVAL" = 2 ] && return 2
  78.     # Wait for children to finish too if this is a daemon that forks
  79.     # and if the daemon is only ever run from this initscript.
  80.     # If the above conditions are not satisfied then add some other code
  81.     # that waits for the process to drop all resources that could be
  82.     # needed by services started subsequently.  A last resort is to
  83.     # sleep for some time.
  84.     start-stop-daemon --stop --quiet --oknodo --retry=0/5/KILL/5 --exec $DAEMON
  85.     [ "$?" = 2 ] && return 2
  86.     # Many daemons don't delete their pidfiles when they exit.
  87.     rm -f $PIDFILE
  88.     return "$RETVAL"
  89. }
  90.  
  91. case "$1" in
  92.   start)
  93.     log_daemon_msg "Starting $DESC" "$NAME"
  94.     do_start
  95.     case "$?" in
  96.         0|1) log_end_msg 0 ;;
  97.         2) log_end_msg 1 ;;
  98.     esac
  99.     ;;
  100.   stop)
  101.     log_daemon_msg "Stopping $DESC" "$NAME"
  102.     do_stop
  103.     case "$?" in
  104.         0|1) log_end_msg 0 ;;
  105.         2) log_end_msg 1 ;;
  106.     esac
  107.     ;;
  108.   status)
  109.     status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  110.     ;;
  111.   restart|force-reload)
  112.     log_daemon_msg "Restarting $DESC" "$NAME"
  113.     do_stop
  114.     case "$?" in
  115.       0|1)
  116.         do_start
  117.         case "$?" in
  118.             0) log_end_msg 0 ;;
  119.             1) log_end_msg 1 ;; # Old process is still running
  120.             *) log_end_msg 1 ;; # Failed to start
  121.         esac
  122.         ;;
  123.       *)
  124.         # Failed to stop
  125.         log_end_msg 1
  126.         ;;
  127.     esac
  128.     ;;
  129.   *)
  130.     echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  131.     exit 3
  132.     ;;
  133. esac
  134.  
  135. :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement