mg-paster 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/sh
  2. # /etc/init.d/mg-paster
  3. #
  4. ## LICENSE: CC0 <http://creativecommons.org/publicdomain/zero/1.0/>
  5. # To the extent possible under law, Joar Wandborg <http://wandborg.se> has
  6. # waived all copyright and related or neighboring rights to
  7. # mediagoblin-paster. This work is published from Sweden.
  8. #
  9. ## CREDIT
  10. # Credit goes to jpope <http://jpope.org/> and
  11. # chimo <http://chimo.chromic.org/>. From which' Arch init scripts this is
  12. # based upon.
  13. #
  14. ### BEGIN INIT INFO
  15. # Provides: mg-paster
  16. # Required-Start: $network $named $local_fs
  17. # Required-Stop: $remote_fs $syslog $network $named $local_fs
  18. # Should-Start: postgresql $syslog
  19. # Default-Start: 2 3 4 5
  20. # Default-Stop: 0 1 6
  21. # Short-Description: MediaGoblin paster FCGI server init script
  22. # Description: This script will initiate the GNU MediaGoblin paster
  23. # fcgi server.
  24. ### END INIT INFO
  25. ################################################################################
  26. # CHANGE THIS
  27. # to suit your environment
  28. ################################################################################
  29. MG_ROOT=/srv/biblioteca/biblioteca.pirata.xyz
  30. MG_USER=mediagoblin
  31. ################################################################################
  32. # NOW STOP
  33. # You probably won't have to change anything else.
  34. ################################################################################
  35. set -e
  36. DAEMON_NAME=mg-paster
  37. MG_BIN=$MG_ROOT/bin
  38. MG_PASTER_BIN=$MG_BIN/paster
  39. MG_PASTE_INI=$MG_ROOT/paste_local.ini
  40. MG_FCGI_HOST=127.0.0.1
  41. MG_FCGI_PORT=26543
  42. MG_PASTER_PID_FILE=/var/run/mediagoblin/$DAEMON_NAME.pid
  43. MG_PASTER_LOG_FILE=/var/log/mediagoblin/$DAEMON_NAME.log
  44. set_up_directories() {
  45. install -o $MG_USER -g users -d -m 755 /var/log/mediagoblin
  46. install -o $MG_USER -g users -d -m 755 /var/run/mediagoblin
  47. }
  48. set_up_directories
  49. # Include LSB helper functions
  50. . /lib/lsb/init-functions
  51. getPID () {
  52. # Discard any errors from cat
  53. cat $MG_PASTER_PID_FILE 2>/dev/null
  54. }
  55. case "$1" in
  56. start)
  57. # Start the MediaGoblin paster process
  58. log_daemon_msg "Starting GNU MediaGoblin paster fcgi server" "$DAEMON_NAME"
  59. if [ ! -f $MG_PASTE_INI ]; then
  60. MG_PASTE_INI=$MG_ROOT/paste.ini
  61. fi
  62. if [ -z "$(getPID)" ]; then
  63. su -s /bin/sh -c "CELERY_ALWAYS_EAGER=False $MG_PASTER_BIN serve \
  64. $MG_PASTE_INI \
  65. --server-name=fcgi \
  66. fcgi_host=$MG_FCGI_HOST fcgi_port=$MG_FCGI_PORT \
  67. --pid-file=$MG_PASTER_PID_FILE \
  68. --log-file=$MG_PASTER_LOG_FILE \
  69. --daemon" - $MG_USER 2>&1 > /dev/null
  70. PASTER_RESULT=$?
  71. # Sleep for a while until we're kind of certain that paster has
  72. # had it's time to initialize
  73. TRIES=0
  74. while ! [ "X$PASTER_RESULT" != "X" ]; do
  75. log_action_msg "Tried $TRIES time(s)"
  76. sleep 0.1
  77. TRIES=$((TRIES+1))
  78. done
  79. log_end_msg $PASTER_RESULT
  80. else
  81. # Failed because the PID file indicates it's running
  82. log_action_msg "PID file $MG_PASTER_BIN already exists"
  83. log_end_msg 1
  84. fi
  85. ;;
  86. stop)
  87. log_daemon_msg "Stopping GNU MediaGoblin paster fcgi server" "$DAEMON_NAME"
  88. if [ -z "$(getPID)" ]; then
  89. # Failed because the PID file indicates it's not running
  90. RET=1
  91. else
  92. kill $(getPID)
  93. if [ $? -gt 0 ]; then
  94. RET=1
  95. else
  96. RET=0
  97. fi
  98. fi
  99. log_end_msg $RET
  100. ;;
  101. restart)
  102. $0 stop
  103. sleep 1
  104. $0 start
  105. ;;
  106. status)
  107. if ! [ -z "$(getPID)" ]; then
  108. echo "$DAEMON_NAME start/running, process $(getPID)"
  109. else
  110. echo "$DAEMON_NAME stopped."
  111. fi
  112. ;;
  113. *)
  114. echo "Usage: $0 {restart|start|stop|status}"
  115. exit 1
  116. ;;
  117. esac
  118. exit 0