init-script-normal-user-rvm-fedora 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/bin/bash
  2. #
  3. # init script build as PoC for
  4. # 1) normal user (non root)
  5. # 2) rvm support
  6. # 3) pid files in user space
  7. # 4) fedora os
  8. # source function library
  9. . /etc/rc.d/init.d/functions
  10. # Get network config
  11. . /etc/sysconfig/network
  12. [ "${NETWORKING}" = "no" ] && exit 0
  13. DAEMON_HOME=/home/kraftvoll/zammad/
  14. #RAILS_ENV=production
  15. RAILS_ENV=test
  16. NAME=zammad
  17. APP_PORT=3000
  18. WS_PORT=6042
  19. ZAMMAD_CONFIG=/etc/sysconfig/zammad
  20. # Read config
  21. [ -f "$ZAMMAD_CONFIG" ] && . "$ZAMMAD_CONFIG"
  22. # Load RVM into a shell session *as a function*
  23. if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
  24. # First try to load from a user install
  25. source "$HOME/.rvm/scripts/rvm"
  26. elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
  27. # Then try to load from a root install
  28. source "/usr/local/rvm/scripts/rvm"
  29. else
  30. printf "ERROR: An RVM installation was not found.\n"
  31. exit 1
  32. fi
  33. rvm use ruby-2.0.0
  34. RUBY=$(which ruby)
  35. RAILS=$(which rails)
  36. BUNDLE=$(which bundle)
  37. APP_PIDFILE=$DAEMON_HOME/tmp/pids/puma.pid
  38. WS_PIDFILE=$DAEMON_HOME/tmp/pids/websocket.pid
  39. SCHEDULER_PIDFILE=$DAEMON_HOME/tmp/pids/scheduler_runner.pid
  40. start() {
  41. cd $DAEMON_HOME
  42. # precompile assets
  43. if [ "$RAILS_ENV" = "production" ]; then
  44. echo -n $"Precompile assets for ${NAME}/${RAILS_ENV}"
  45. $BUNDLE exec rake assets:precompile &> /dev/null && echo_success || echo_failure
  46. echo
  47. fi
  48. # start web server
  49. echo -n $"Starting ${NAME}/${RAILS_ENV} application server on port: ${APP_PORT}"
  50. # $RAILS server -d -p $APP_PORT --pid $APP_PIDFILE &> /dev/null
  51. # thin start --threaded -d -p $APP_PORT --pid $APP_PIDFILE
  52. puma --pidfile $APP_PIDFILE -d -p $APP_PORT -e $RAILS_ENV &> /dev/null
  53. sleep 2
  54. status -p $APP_PIDFILE &> /dev/null && echo_success || echo_failure
  55. echo
  56. # start websocket server
  57. echo -n $"Starting ${NAME}/${RAILS_ENV} web socket server on port: ${WS_PORT}"
  58. script/websocket-server.rb start -d -p $WS_PORT -i $WS_PIDFILE &> /dev/null &
  59. sleep 2
  60. status -p $WS_PIDFILE &> /dev/null && echo_success || echo_failure
  61. echo
  62. # start scheduler worker
  63. echo -n $"Starting ${NAME}/${RAILS_ENV} scheduler worker"
  64. script/scheduler.rb start &> /dev/null && echo_success || echo_failure
  65. echo
  66. }
  67. stop() {
  68. # stop scheduler worker
  69. echo -n $"Shutting down ${NAME}/${RAILS_ENV} scheduler worker"
  70. script/scheduler.rb stop &> /dev/null && echo_success || echo_failure
  71. echo
  72. # stop websocket server
  73. echo -n $"Shutting down ${NAME}/${RAILS_ENV} web socket server on port: ${WS_PORT}"
  74. if test -e $WS_PIDFILE; then
  75. killproc -p $WS_PIDFILE
  76. fi
  77. echo
  78. # stop web server
  79. echo -n $"Shutting down ${NAME}/${RAILS_ENV} application server on port: ${APP_PORT}"
  80. if test -e $APP_PIDFILE; then
  81. killproc -p $APP_PIDFILE
  82. fi
  83. echo
  84. }
  85. case "$1" in
  86. start)
  87. start
  88. ;;
  89. stop)
  90. stop
  91. ;;
  92. restart)
  93. stop
  94. start
  95. ;;
  96. status)
  97. status -p $APP_PIDFILE "${NAME} ${RAILS_ENV} - application server"
  98. status -p $WS_PIDFILE "${NAME} ${RAILS_ENV} - web socket server"
  99. ;;
  100. *)
  101. echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2
  102. exit 3
  103. ;;
  104. esac