diff --git a/labs/bbb-callback/README.md b/labs/bbb-callback/README.md index 5cc6c9c2a07c7b5cc31d8db82317f9cbb15b2e97..fca5f9bf2a224a2799c9c37ff7819b72bca9db06 100644 --- a/labs/bbb-callback/README.md +++ b/labs/bbb-callback/README.md @@ -237,12 +237,12 @@ Development 1. Install node. You can use [NVM](https://github.com/creationix/nvm) if you need multiple versions of node or install it from source. To install from source, first check the exact version you need on `package.json` and replace the all `vX.X.X` by the correct version when running the commands below. ```bash -$ wget http://nodejs.org/dist/vX.X.X/node-vX.X.X.tar.gz -$ tar -xvf node-vX.X.X.tar.gz -$ cd node-vX.X.X/ -$ ./configure -$ make -$ sudo make install +wget http://nodejs.org/dist/vX.X.X/node-vX.X.X.tar.gz +tar -xvf node-vX.X.X.tar.gz +cd node-vX.X.X/ +./configure +make +sudo make install ``` 2. Copy and edit the configuration file: `cp config_local.coffee.example config_local.coffee` @@ -259,12 +259,12 @@ Production 1. Install node. First check the exact version you need on `package.json` and replace the all `vX.X.X` by the correct version in the commands below. ```bash -$ wget http://nodejs.org/dist/vX.X.X/node-vX.X.X.tar.gz -$ tar -xvf node-vX.X.X.tar.gz -$ cd node-vX.X.X/ -$ ./configure -$ make -$ sudo make install +wget http://nodejs.org/dist/vX.X.X/node-vX.X.X.tar.gz +tar -xvf node-vX.X.X.tar.gz +cd node-vX.X.X/ +./configure +make +sudo make install ``` 2. Copy the entire webhooks directory to `/usr/local/bigbluebutton/bbb-webhooks` @@ -273,3 +273,31 @@ $ sudo make install 4. Drop the nginx configuration file in its place: `cp config/webhooks.nginx /etc/bigbluebutton/nginx/`. If you changed the port of the web server on your configuration file, you will have to edit it in `webhooks.nginx` as well. + +5. Copy upstart's configuration file and make sure its permissions are ok: + + ```bash +sudo cp config/upstart-bbb-webhooks.conf /etc/init/bbb-webhooks.conf +sudo chown root:root /etc/init/bbb-webhooks.conf + ``` + +6. Copy monit's configuration file and make sure its permissions are ok: + + ```bash +sudo cp config/monit-bbb-webhooks /etc/monit/conf.d/bbb-webhooks +sudo chown root:root /etc/monit/conf.d/bbb-webhooks + ``` + +7. Start the application using monit: + + ```bash +sudo monit monitor bbb-webhooks +sudo monit start bbb-webhooks + ``` + + You can also use upstart to start/stop the application: + + ```bash +sudo service bbb-webhooks start +sudo service bbb-webhooks stop + ``` diff --git a/labs/bbb-callback/bbb-callback.sh b/labs/bbb-callback/bbb-callback.sh deleted file mode 100644 index d7ccce6e39d96640bff83757799f18b4308b7033..0000000000000000000000000000000000000000 --- a/labs/bbb-callback/bbb-callback.sh +++ /dev/null @@ -1,156 +0,0 @@ -#!/bin/bash -# -# An example init script for running a Node.js process as a service -# using Forever as the process monitor. For more configuration options -# associated with Forever, see: https://github.com/nodejitsu/forever -# -# You will need to set the environment variables noted below to conform to -# your use case, and change the init info comment block. -# -# This was written for Debian distributions such as Ubuntu, but should still -# work on RedHat, Fedora, or other RPM-based distributions, since none -# of the built-in service functions are used. If you do adapt it to a RPM-based -# system, you'll need to replace the init info comment block with a chkconfig -# comment block. -# -### BEGIN INIT INFO -# Provides: bbb-callback -# Required-Start: $syslog $remote_fs -# Required-Stop: $syslog $remote_fs -# Should-Start: $local_fs -# Should-Stop: $local_fs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: BigBlueButton Callback Application -# Description: BigBlueButton application that callback URLs registered to receive events. -### END INIT INFO -# -# Based on: -# https://gist.github.com/3748766 -# https://github.com/hectorcorrea/hectorcorrea.com/blob/master/etc/forever-initd-hectorcorrea.sh -# https://www.exratione.com/2011/07/running-a-nodejs-server-as-a-service-using-forever/ - -# Source function library. Note that this isn't used here, but remains to be -# uncommented by those who want to edit this script to add more functionality. -# Note that this is Ubuntu-specific. The scripts and script location are different on -# RPM-based distributions. -# . /lib/lsb/init-functions - -# The example environment variables below assume that Node.js is -# installed into /home/node/local/node by building from source as outlined -# here: -# https://www.exratione.com/2011/07/running-a-nodejs-server-as-a-service-using-forever/ -# -# It should be easy enough to adapt to the paths to be appropriate to a -# package installation, but note that the packages available for Ubuntu in -# the default repositories are far behind the times. Most users will be -# building from source to get a more recent Node.js version. -# -# An application name to display in echo text. -# NAME="My Application" -# The full path to the directory containing the node and forever binaries. -# NODE_BIN_DIR=/home/node/local/node/bin -# Set the NODE_PATH to the Node.js main node_modules directory. -# NODE_PATH=/home/node/local/node/lib/node_modules -# The directory containing the application start Javascript file. -# APPLICATION_DIRECTORY=/home/node/my-application -# The application start Javascript filename. -# APPLICATION_START=start-my-application.js -# Process ID file path. -# PIDFILE=/var/run/my-application.pid -# Log file path. -# LOGFILE=/var/log/my-application.log -# -NAME="BBB Calback" -NODE_BIN_DIR=/usr/local/bin -NODE_PATH=/usr/local/lib/node_modules -APPLICATION_DIRECTORY=/usr/local/bigbluebutton/bbb-callback -APPLICATION_START=app.js -PIDFILE=/var/run/bbb-callback.pid -LOGFILE=/var/log/bbb-callback.log - -# Add node to the path for situations in which the environment is passed. -PATH=$NODE_BIN_DIR:$PATH -# Export all environment variables that must be visible for the Node.js -# application process forked by Forever. It will not see any of the other -# variables defined in this script. -export NODE_PATH=$NODE_PATH - -start() { - echo "Starting $NAME" - # We're calling forever directly without using start-stop-daemon for the - # sake of simplicity when it comes to environment, and because this way - # the script will work whether it is executed directly or via the service - # utility. - # - # The minUptime and spinSleepTime settings stop Forever from thrashing if - # the application fails immediately on launch. This is generally necessary to - # avoid loading development servers to the point of failure every time - # someone makes an error in application initialization code, or bringing down - # production servers the same way if a database or other critical service - # suddenly becomes inaccessible. - # - # The pidfile contains the child process pid, not the forever process pid. - # We're only using it as a marker for whether or not the process is - # running. - forever --pidFile $PIDFILE --sourceDir $APPLICATION_DIRECTORY \ - -a -l $LOGFILE --minUptime 5000 --spinSleepTime 2000 \ - start $APPLICATION_START & - RETVAL=$? -} - -stop() { - if [ -f $PIDFILE ]; then - echo "Shutting down $NAME" - # Tell Forever to stop the process. Note that doing it this way means - # that each application that runs as a service must have a different - # start file name, regardless of which directory it is in. - forever stop $APPLICATION_START - # Get rid of the pidfile, since Forever won't do that. - rm -f $PIDFILE - RETVAL=$? - else - echo "$NAME is not running." - RETVAL=0 - fi -} - -restart() { - echo "Restarting $NAME" - stop - start -} - -status() { - echo "Status for $NAME:" - # This is taking the lazy way out on status, as it will return a list of - # all running Forever processes. You get to figure out what you want to - # know from that information. - # - # On Ubuntu, this isn't even necessary. To find out whether the service is - # running, use "service my-application status" which bypasses this script - # entirely provided you used the service utility to start the process. - forever list - RETVAL=$? -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - status) - status - ;; - restart) - restart - ;; - *) - echo "Usage: {start|stop|status|restart}" - exit 1 - ;; -esac -exit $RETVAL - diff --git a/labs/bbb-callback/config/monit-bbb-webhooks b/labs/bbb-callback/config/monit-bbb-webhooks new file mode 100755 index 0000000000000000000000000000000000000000..78ac9edabb28ea9fcebc0fb0d2129550d5cac1dd --- /dev/null +++ b/labs/bbb-callback/config/monit-bbb-webhooks @@ -0,0 +1,12 @@ +#!monit +set logfile /var/log/monit.log + +check process bbb-webhooks with pidfile "/var/run/bbb-webhooks.pid" + start program = "/sbin/start bbb-webhooks" + stop program = "/sbin/stop bbb-webhooks" + + if failed port 3005 protocol HTTP + request /bigbluebutton/api/hooks/ping + with timeout 30 seconds + then restart + if 5 restarts within 5 cycles then timeout diff --git a/labs/bbb-callback/config/upstart-bbb-webhooks.conf b/labs/bbb-callback/config/upstart-bbb-webhooks.conf new file mode 100644 index 0000000000000000000000000000000000000000..af2e5069340f1650edcc42dede5ece593d76d1e1 --- /dev/null +++ b/labs/bbb-callback/config/upstart-bbb-webhooks.conf @@ -0,0 +1,34 @@ +# bbb-webhooks + +description "bbb-webhooks" +author "BigBlueButton" + +start on (local-filesystems and net-device-up IFACE=eth3) +stop on shutdown + +# respawn # we're using monit for it + +env USER=firstuser +env APP=app.js +env CMD_OPTS="" +env SRC_DIR="/usr/local/bigbluebutton/bbb-webhooks" +env LOGFILE="/var/log/bbb-webhooks.log" +env NODE=/usr/local/bin/node +env PIDFILE="/var/run/bbb-webhooks.pid" +env NODE_ENV="production" + +script + cd $SRC_DIR + echo $$ > $PIDFILE + exec sudo -u $USER NODE_ENV=$NODE_ENV $NODE $APP $CMD_OPTS 1>> $LOGFILE 2>> $LOGFILE +end script + +pre-start script + # Date format same as (new Date()).toISOString() for consistency + echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> $LOGFILE +end script + +pre-stop script + rm $PIDFILE + echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> $LOGFILE +end script