feat: Redirect script output in the console.

This commit is contained in:
Nicolas Carlier 2015-04-20 17:23:29 +00:00
parent 50ac05f4f5
commit d1fbdb139b
3 changed files with 46 additions and 13 deletions

View File

@ -23,7 +23,7 @@ all: build
volume:
echo "Building $(APPNAME) volumes..."
sudo docker run \
-v $(PWD)/src:/go/src/github.com/$(USERNAME)/$(APPNAME) \
-v $(PWD)/src:/go/src/$(ROOTPKG)/$(APPNAME) \
-v $(PWD)/scripts:/var/opt/$(APPNAME)/scripts \
--name $(APPNAME)_volumes busybox true

View File

@ -1,20 +1,45 @@
###
# webhook environment configuration
# Webhookd configuration.
###
# Domain name
# This is only used by the reverse proxy container (not by the app).
DOMAIN_NAME=webhook.lan
# Working directory
# Working directory.
# Defaults: /tmp
APP_WORKING_DIR=/var/opt/webhookd/work
# Scripts directory
# Scripts directory.
# Defaults: ./scripts
APP_SCRIPTS_DIR=/var/opt/webhookd/scripts
# Notifier
# "http" or "smtp"
# Redirect scripts output in the console.
# Warning: Only for debugging purpose.
# Defaults: false
APP_SCRIPTS_DEBUG=false
# Notifier.
# Notify script execution result and logs.
# Values:
# - "http": Send notification with an HTTP hook (compatible with Mailgun API).
# - "smtp": Send notification by mail.
# - "": No notification (defaults).
APP_NOTIFIER=http
# HTTP notifier URL
# Notifier FROM directive.
# Defaults: "webhookd <noreply@nunux.org>"
APP_NOTIFIER_FROM=Mailgun Sandbox <postmaster@sandboxdexxxxxxxxxxxxxxxxxx.mailgun.org>
# Notifier TO directive.
# Defaults: "hostmaster@nunux.org"
APP_NOTIFIER_TO=foo@bar.org
# HTTP notifier URL.
APP_HTTP_NOTIFIER_URL=http://requestb.in/1gd3ond1
#APP_HTTP_NOTIFIER_URL=https://api.mailgun.net/v2/sandboxdexxxxxxxxxxxxxxxxx.mailgun.org/messages
# HTTP notifier user:password.
APP_HTTP_NOTIFIER_USER=api:key-xxxxxxxxxxxxxxxxxxxxxxxxxx
# SMTP notifier host.
# Defaults: localhost:25
APP_SMTP_NOTIFIER_HOST=localhost:25

View File

@ -2,6 +2,7 @@ package worker
import (
"fmt"
"io"
"os"
"os/exec"
"path"
@ -10,6 +11,7 @@ import (
var (
workingdir = os.Getenv("APP_WORKING_DIR")
scriptsdir = os.Getenv("APP_SCRIPTS_DIR")
scriptsdebug = os.Getenv("APP_SCRIPTS_DEBUG")
)
func RunScript(work *WorkRequest) (string, error) {
@ -34,8 +36,14 @@ func RunScript(work *WorkRequest) (string, error) {
}
defer outfile.Close()
cmd.Stdout = outfile
cmd.Stderr = outfile
if scriptsdebug == "true" {
fmt.Println("Logging in console: ", scriptsdebug)
cmd.Stdout = io.MultiWriter(os.Stdout, outfile)
cmd.Stderr = io.MultiWriter(os.Stderr, outfile)
} else {
cmd.Stdout = outfile
cmd.Stderr = outfile
}
err = cmd.Start()
if err != nil {