 
     commands[fileName] = command
 
+
+# On connection, list all files in the log path directory and start redirecting
+# a tail -f for each of them to given socket.
+# When socket is disconnected, all tail -f process are stopped.
 io.sockets.on "connection", (socket) ->
 
     fs.readdir config.logPath, (err, files) ->


    socket.on "disconnect", () ->
        console.log "Client has disconnected, closing the processes..."
        killCommands(commands);

process.on 'SIGINT', () ->
  console.log "Server is stopping, closing the processes..."
  killCommands(commands);
  app.close()
  process.exit()

process.on 'SIGTERM', () ->
  console.log "Server is stopping, closing the processes..."
  killCommands(commands);
  app.close()

fs = require "fs"
spawn = require('child_process').spawn
connect = require "connect"

config = require './config'

app = connect.createServer(connect.static('public')).listen(9099)
io = require("socket.io").listen app
io.set 'log level', 2 # disable heartbeat debug output


commands = []

# Send data to connected client.
sendData = (socket, data, fileName, fileSlug, channel) ->
    data = "#{data}"
    socket.emit 'new-data',
