Permalink
Browse files

Merge pull request #316 from pschichtel/patch-1

Added a nginx configuration and an init script
  • Loading branch information...
2 parents cb95f9c + 1e6f199 commit 53eb543d9f82a94ae9733e116438ad8a712a4748 @thedjpetersen thedjpetersen committed Mar 21, 2014
Showing with 139 additions and 0 deletions.
  1. +19 −0 support/README.md
  2. +85 −0 support/init.d/subway
  3. +35 −0 support/nginx/subway
View
@@ -0,0 +1,19 @@
+Support scripts
+===============
+
+[Init Script](init.d/subway)
+----------------------------
+
+This is a pretty basic init script to get subway running as a service.
+By default it places a log file at /var/log/subway.log and a pid file
+in /var/run/subway.pid .
+
+
+[Nginx config](nginx/subway)
+----------------------------
+
+This is a simple Nginx host configuration that proxies both the normal
+HTTP requests as well as Websocket connections to Subway's server.
+Simply edit the file where necessary and throw it in your
+/etc/nginx/sites-enabled (or what ever it's called) folder
+and reload/restart your nginx (typically "service nginx reload").
View
@@ -0,0 +1,85 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides: subway
+# Required-Start: $local_fs $remote_fs $network $time $named
+# Required-Stop: $local_fs $remote_fs $network $time $named
+# Default-Start: 3 5
+# Default-Stop: 0 1 2 6
+# Short-Description: Subway Web IRC
+# Description: A JS based web IRC
+### END INIT INFO
+
+NAME="subway"
+SCRIPTNAME="/etc/init.d/$NAME"
+PREFIX="/home/znc/$NAME"
+USER="znc"
+PID="/var/run/subway.pid"
+LOG="/var/log/subway.log"
+
+if [ `id -u` -ne 0 ]; then
+ echo "The $NAME init script can only be run as root"
+ exit 1
+fi
+
+SCRIPT="$PREFIX/$NAME"
+
+do_start()
+{
+ su - "$USER" -c "$SCRIPT" > "$LOG" 2>&1 &
+ echo $! > "$PID"
+ echo "Started: `cat "$PID"`"
+}
+
+do_stop()
+{
+ if [ -e "$PID" ]
+ then
+ kill -INT `cat "$PID"`
+ rm "$PID"
+ echo "Stopped"
+ else
+ echo "Not running."
+ fi
+}
+
+do_status()
+{
+ if [ -e "$PID" ]
+ then
+ if kill -0 `cat "$PID"`
+ then
+ echo "Running: `cat $PID`"
+ else
+ echo "Crashed!"
+ fi
+ else
+ echo "Not running."
+ fi
+}
+
+do_restart()
+{
+ do_stop
+ do_start
+}
+
+case "$1" in
+ start)
+ do_start
+ ;;
+ stop)
+ do_stop
+ ;;
+ status)
+ do_status
+ ;;
+ restart|force-reload)
+ do_restart
+ ;;
+ *)
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+ exit 3
+ ;;
+esac
+
+exit 0
View
@@ -0,0 +1,35 @@
+upstream subway {
+ server localhost:3000;
+}
+
+map $http_upgrade $connection_upgrade {
+ default upgrade;
+ '' close;
+}
+
+server {
+ listen 80;
+ # for IPv6
+ # listen [::]:80;
+ server_name irc.example.org;
+
+ access_log /path/to/subway/subway_access.log;
+ error_log /path/to/subway/subway_errors.log warn;
+
+ location /assets {
+ root /path/to/subway;
+ }
+
+ location / {
+ proxy_pass http://subway;
+ proxy_redirect off;
+
+ proxy_http_version 1.1;
+
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection $connection_upgrade;
+ }
+}

0 comments on commit 53eb543

Please sign in to comment.