autoclient.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #! /bin/sh
  2. ## Copyright (c) 2015 Minoca Corp. All Rights Reserved.
  3. ##
  4. ## Script Name:
  5. ##
  6. ## autoclient.sh start|stop|reload|force-reload|restart
  7. ##
  8. ## Abstract:
  9. ##
  10. ## This init script starts the Minoca build client.
  11. ##
  12. ## Author:
  13. ##
  14. ## Evan Green 24-Mar-2015
  15. ##
  16. ## Environment:
  17. ##
  18. ## Build
  19. ##
  20. set -e
  21. ##
  22. ## /etc/init.d/autoclient.sh: start and stop the Minoca build client script.
  23. ##
  24. [ -f /etc/init.d/init-functions ] && . /etc/init.d/init-functions
  25. umask 022
  26. ARGS="/auto/client.py"
  27. if [ -n $2 ]; then
  28. ARGS="$ARGS $2"
  29. fi
  30. ##
  31. ## Start in a different directory if an alternate root was specified. Perhaps
  32. ## the OS partition is not big enough to support builds.
  33. ##
  34. AUTO_ROOT=/auto
  35. if [ -r /auto/auto_root ]; then
  36. AUTO_ROOT=`cat /auto/auto_root`
  37. fi
  38. case "$1" in
  39. start)
  40. ##
  41. ## Copy files from /auto if an alternate root was specified.
  42. ##
  43. if [ "$AUTO_ROOT" != "/auto" ]; then
  44. if ! [ -d "$AUTO_ROOT/" ]; then
  45. mkdir "$AUTO_ROOT/"
  46. fi
  47. if ! [ -r "$AUTO_ROOT/auto_root" ]; then
  48. log_daemon_msg "Copying Minoca Build client files" || true
  49. cp -Rpv /auto/* "$AUTO_ROOT/"
  50. log_end_msg 0 || true
  51. fi
  52. fi
  53. ##
  54. ## Fire up the build client.
  55. ##
  56. log_daemon_msg "Running Minoca Build client" || true
  57. if start-stop-daemon -S -p /var/run/mbuild.pid -d "$AUTO_ROOT" -bqom \
  58. -x /usr/bin/python -- $ARGS ; then
  59. log_end_msg 0 || true
  60. else
  61. log_end_msg 1 || true
  62. fi
  63. ;;
  64. stop)
  65. log_daemon_msg "Stopping Minoca Build client" || true
  66. if start-stop-daemon -K -p /var/run/mbuild.pid -qo -n python \
  67. -x /usr/bin/python; then
  68. log_end_msg 0 || true
  69. else
  70. log_end_msg 1 || true
  71. fi
  72. ;;
  73. reload|force-reload|restart)
  74. log_daemon_msg "Restarting Minoca Build client"
  75. start-stop-daemon -K -p /var/run/mbuild.pid -qo -n python
  76. sleep 2
  77. if start-stop-daemon -S -p /var/run/mbuild.pid -d /auto -bqom \
  78. -x /usr/bin/python -- $ARGS ; then
  79. log_end_msg 0 || true
  80. else
  81. log_end_msg 1 || true
  82. fi
  83. ;;
  84. *)
  85. log_action_msg "Usage: $0 {start|stop|reload|force-reload|restart}"
  86. exit 1
  87. ;;
  88. esac
  89. exit 0