diff --git a/Makefile b/Makefile index 5f4c5cd..8adf42f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/etc/env_sample.conf b/etc/env_sample.conf index 7061ef2..7cb2b85 100644 --- a/etc/env_sample.conf +++ b/etc/env_sample.conf @@ -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 " +APP_NOTIFIER_FROM=Mailgun Sandbox + +# 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 + + diff --git a/src/worker/script_runner.go b/src/worker/script_runner.go index f6c04d1..bf2ea57 100644 --- a/src/worker/script_runner.go +++ b/src/worker/script_runner.go @@ -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 {