Skip to content

Commit

Permalink
Merge pull request thedjpetersen#316 from pschichtel/patch-1
Browse files Browse the repository at this point in the history
Added a nginx configuration and an init script
  • Loading branch information
thedjpetersen committed Mar 21, 2014
2 parents cb95f9c + 1e6f199 commit 53eb543
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
19 changes: 19 additions & 0 deletions support/README.md
Original file line number Diff line number Diff line change
@@ -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").
85 changes: 85 additions & 0 deletions support/init.d/subway
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions support/nginx/subway
Original file line number Diff line number Diff line change
@@ -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.