added websocket server

This commit is contained in:
rkaldung 2014-08-13 18:28:18 +02:00
parent 1c038f2cc4
commit 69bb7691bc

View file

@ -14,11 +14,11 @@
APP_ROOT="/home/zammad/zammad" APP_ROOT="/home/zammad/zammad"
PID_PATH="$APP_ROOT/tmp/pids" PID_PATH="$APP_ROOT/tmp/pids"
WEB_SERVER_PID="$PID_PATH/puma.pid" WEB_SERVER_PID="$PID_PATH/puma.pid"
SOCKET_PATH="$APP_ROOT/tmp/sockets" WEBSOCKET_SERVER_PID="$PID_PATH/websocket.pid"
SOCKET_FILE="$SOCKET_PATH/zammad.socket"
APP_USER="zammad" APP_USER="zammad"
DAEMON_OPTS="-p 3000 -d -e production --pidfile $WEB_SERVER_PID" PUMA_OPTS="-p 3000 -d -e production --pidfile $WEB_SERVER_PID"
WEBSOCKET_OPTS="-d"
NAME="zammad" NAME="zammad"
DESC="Zammad application" DESC="Zammad application"
@ -31,6 +31,12 @@ check_daemons() {
PUMA_PID=$(pgrep -F $WEB_SERVER_PID) PUMA_PID=$(pgrep -F $WEB_SERVER_PID)
PUMA_OK=$? PUMA_OK=$?
fi fi
WEBSOCKET_PID=-1
WEBSOCKET_OK=1
if [ -f $WEBSOCKET_SERVER_PID ]; then
WEBSOCKET_PID=$(pgrep -F $WEBSOCKET_SERVER_PID)
WEBSOCKET_OK=$?
fi
} }
execute() { execute() {
@ -42,19 +48,30 @@ start() {
check_daemons check_daemons
if [ $PUMA_OK -eq 0 ]; then if [ $PUMA_OK -eq 0 ]; then
echo Puma is already running echo Puma is already running
exit 1 else
execute "RAILS_ENV=production puma $PUMA_OPTS"
fi
if [ $WEBSOCKET_OK -eq 0 ]; then
echo Websocket server is already running
else
execute "RAILS_ENV=production script/websocket-server.rb start $WEBSOCKET_OPTS"
fi fi
execute "RAILS_ENV=production puma $DAEMON_OPTS"
echo "$DESC started" echo "$DESC started"
} }
stop() { stop() {
cd $APP_ROOT cd $APP_ROOT
check_daemons check_daemons
if [ "$PUMA_OK" -eq 0 ]; then if [ "$PUMA_OK" -eq 0 -o $WEBSOCKET_OK -eq 0 ]; then
## Program is running, stop it. ## Program is running, stop it.
if [ $PUMA_OK -eq 0 ]; then
kill -QUIT $PUMA_PID kill -QUIT $PUMA_PID
test -f "$WEB_SERVER_PID" && rm -f "$WEB_SERVER_PID" test -f "$WEB_SERVER_PID" && rm -f "$WEB_SERVER_PID"
fi
if [ $WEBSOCKET_OK -eq 0 ]; then
execute "RAILS_ENV=production script/websocket-server.rb stop $WEBSOCKET_OPTS"
test -f "$WEBSOCKET_SERVER_PID" && rm -f "$WEBSOCKET_SERVER_PID"
fi
echo "$DESC stopped" echo "$DESC stopped"
else else
## Program is not running, exit with error. ## Program is not running, exit with error.
@ -66,9 +83,11 @@ stop() {
restart() { restart() {
cd $APP_ROOT cd $APP_ROOT
check_daemons check_daemons
if [ "$PUMA_OK" -eq 0 ]; then if [ "$PUMA_OK" -eq 0 -o WEBSOCKET_OK -eq 0 ]; then
echo "Restarting $DESC..." echo "Restarting $DESC..."
kill -USR2 $PUMA_PID kill -USR2 $PUMA_PID
execute "RAILS_ENV=production script/websocket-server.rb stop $WEBSOCKET_OPTS"
execute "RAILS_ENV=production script/websocket-server.rb start $WEBSOCKET_OPTS"
echo "$DESC restarted." echo "$DESC restarted."
else else
echo "Error, $NAME not running!" echo "Error, $NAME not running!"
@ -80,10 +99,14 @@ status() {
cd $APP_ROOT cd $APP_ROOT
check_daemons check_daemons
if [ $PUMA_OK -eq 0 ]; then if [ $PUMA_OK -eq 0 ]; then
echo "$DESC / Puma with PID $PUMA_PID is running." echo "$DESC / Puma (pid $PUMA_PID) is running."
else else
echo "$DESC is not running." echo "$DESC / Puma (pid $PUMA_PID) is not running."
exit 1 fi
if [ $WEBSOCKET_OK -eq 0 ]; then
echo "Websocket server (pid $WEBSOCKET_PID) is running."
else
echo "Websocket server (pid $WEBSOCKET_PID) is not running."
fi fi
} }