Call the gosuper from node via unix socket + http.

This commit is contained in:
Pablo Carranza Vélez 2015-07-24 14:26:33 -03:00
parent 300067febe
commit dd53bbd1db
4 changed files with 23 additions and 2 deletions

View File

@ -2,6 +2,10 @@
set -e
if [ -z $GOSUPER_SOCKET ]; then
GOSUPER_SOCKET=/var/run/gosuper.sock
fi
[ -d /dev/net ] ||
mkdir -p /dev/net
[ -c /dev/net/tun ] ||

View File

@ -2,7 +2,9 @@ package main
import (
"fmt"
"net"
"net/http"
"os"
"resin-supervisor/Godeps/_workspace/src/github.com/gorilla/mux"
)
@ -25,6 +27,7 @@ func main() {
*/
ResinDataPath = "/resin-data/"
laddr := os.Getenv("GOSUPER_SOCKET")
r := mux.NewRouter()
r.HandleFunc("/ping", pingHandler)
@ -32,6 +35,14 @@ func main() {
apiv1.HandleFunc("/purge", PurgeHandler).Methods("POST")
http.ListenAndServe(":8080", r)
listener, err := net.Listen("unix", laddr)
if err != nil {
fmt.Println("Could not listen on " + laddr)
return
}
err = http.Serve(listener, r)
if err != nil {
fmt.Println("Could not start HTTP server")
return
}
}

View File

@ -6,6 +6,8 @@ tty = require './lib/tty'
knex = require './db'
express = require 'express'
bodyParser = require 'body-parser'
request = require 'request'
config = require './config'
module.exports = (secret) ->
api = express()
@ -57,4 +59,7 @@ module.exports = (secret) ->
.catch (err) ->
res.status(503).send(err?.message or err or 'Unknown error')
api.post '/v1/purge', (req, res) ->
request.post(config.gosuperAddress + '/v1/purge', req.body).pipe(res)
return api

View File

@ -10,6 +10,7 @@ checkInt = (s) ->
module.exports = config =
apiEndpoint: process.env.API_ENDPOINT ? 'https://api.resin.io'
listenPort: process.env.LISTEN_PORT ? 80
gosuperAddress: "http://unix:#{process.env.GOSUPER_SOCKET}:"
registryEndpoint: process.env.REGISTRY_ENDPOINT ? 'registry.resin.io'
pubnub:
subscribe_key: process.env.PUBNUB_SUBSCRIBE_KEY ? 'sub-c-bananas'