clsync.init 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: clsync
  4. # Required-Start: $remote_fs
  5. # Required-Stop: $remote_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: clsync daemon init script
  9. # Description: This script launches the clsync daemon.
  10. ### END INIT INFO
  11. # bugtrack: https://github.com/xaionaro/clsync/issues
  12. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  13. DESC="syncer daemon"
  14. NAME=clsync
  15. DAEMON=/usr/bin/$NAME
  16. PIDFILE=/var/run/$NAME.pid
  17. ARGS="--pid-file ${PIDFILE} --background"
  18. SCRIPTNAME=/etc/init.d/$NAME
  19. # Exit if the package is not installed
  20. [ -x "$DAEMON" ] || exit 0
  21. # Read configuration variable file if it is present
  22. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  23. [ "$CLSYNC_ENABLE" != "true" ] && exit 0
  24. . /lib/lsb/init-functions
  25. do_start() {
  26. start-stop-daemon --start --quiet --pidfile "$PIDFILE" \
  27. --exec "$DAEMON" --test > /dev/null \
  28. || return 1
  29. start-stop-daemon --start --quiet --pidfile "$PIDFILE" \
  30. --exec "$DAEMON" -- $ARGS $CLSYNC_ARGS \
  31. || return 2
  32. }
  33. do_stop() {
  34. start-stop-daemon --stop --quiet --pidfile "$PIDFILE" --name "$NAME"
  35. RC="$?"
  36. [ "$RC" = 2 ] && return 2
  37. start-stop-daemon --stop --quiet --oknodo --exec "$DAEMON"
  38. [ "$?" = 2 ] && return 2
  39. rm -f "$PIDFILE"
  40. return "$RC"
  41. }
  42. do_reload() {
  43. start-stop-daemon --stop --signal 1 --quiet --pidfile "$PIDFILE" --name "$NAME"
  44. return 0
  45. }
  46. case "$1" in
  47. start)
  48. log_daemon_msg "Starting $DESC" "$NAME"
  49. do_start
  50. case "$?" in
  51. 0|1)
  52. log_end_msg 0
  53. ;;
  54. 2)
  55. log_end_msg 1
  56. ;;
  57. esac
  58. ;;
  59. stop)
  60. log_daemon_msg "Stopping $DESC" "$NAME"
  61. do_stop
  62. case "$?" in
  63. 0|1)
  64. log_end_msg 0
  65. ;;
  66. 2)
  67. log_end_msg 1
  68. ;;
  69. esac
  70. ;;
  71. status)
  72. status_of_proc $DAEMON $NAME && exit 0 || exit $?
  73. ;;
  74. restart|force-reload)
  75. log_daemon_msg "Restarting $DESC" "$NAME"
  76. do_stop
  77. case "$?" in
  78. 0|1)
  79. do_start
  80. case "$?" in
  81. 0) log_end_msg 0 ;;
  82. 1) log_end_msg 1 ;; # Old process is still running
  83. *) log_end_msg 1 ;; # Failed to start
  84. esac
  85. ;;
  86. *)
  87. # Failed to stop
  88. log_end_msg 1
  89. ;;
  90. esac
  91. ;;
  92. *)
  93. echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  94. exit 3
  95. ;;
  96. esac
  97. exit 0