summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--gospeladlershof.de/Makefile3
-rw-r--r--intern.gospeladlershof.de/code/deploy.php2
-rw-r--r--resources/mq/client/message_queue.go68
-rw-r--r--resources/mq/server/gospelserver.service19
-rw-r--r--resources/mq/server/message_queue.go149
6 files changed, 243 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 729b502..d513eea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,7 @@ secrets.php
chor_list_members.txt
public/
_/
+
+gospeladlershof.de/node_modules
+gospeladlershof.de/static/concat.css
+gospeladlershof.de/static/gulp.css/
diff --git a/gospeladlershof.de/Makefile b/gospeladlershof.de/Makefile
index 23b7e6c..d9606f4 100644
--- a/gospeladlershof.de/Makefile
+++ b/gospeladlershof.de/Makefile
@@ -19,7 +19,8 @@ server:
deploy: build
@if [ -d "/var/www/gospeladlershof.de/gospeladlershof.de/" ]; then \
- rsync --delete -avz public/ /var/www/gospeladlershof.de/gospeladlershof.de/; \
+ rsync --delete -avz public/ /var/www/gospeladlershof.de/gospeladlershof.de/ && \
+ /usr/local/bin/gospelclient; \
else \
rsync --delete -avze ssh public/ online:/var/www/gospeladlershof.de/gospeladlershof.de/; \
fi
diff --git a/intern.gospeladlershof.de/code/deploy.php b/intern.gospeladlershof.de/code/deploy.php
index 7782984..15ca9c0 100644
--- a/intern.gospeladlershof.de/code/deploy.php
+++ b/intern.gospeladlershof.de/code/deploy.php
@@ -1,6 +1,6 @@
<?php
-system('cd /home/horus/sites/gospeladlershof.de && make -s 2>&1 | mail -s "Hugo: gospeladlershof.de" status@iamfabulous.de', $retval);
+system('cd /home/horus/app/gospeladlershof.de && make -s 2>&1 | mail -s "Hugo: gospeladlershof.de" status@iamfabulous.de', $retval);
header($_SERVER["SERVER_PROTOCOL"] . " 302 Redirect");
if ( 0 !== $retval ) {
diff --git a/resources/mq/client/message_queue.go b/resources/mq/client/message_queue.go
new file mode 100644
index 0000000..ee662b1
--- /dev/null
+++ b/resources/mq/client/message_queue.go
@@ -0,0 +1,68 @@
+package main
+
+import (
+ "encoding/json"
+ "time"
+
+ log "github.com/Sirupsen/logrus"
+ "github.com/kr/beanstalk"
+)
+
+// beanstalkd, the message queue
+type Queue struct {
+ Conn *beanstalk.Conn
+ Tube *beanstalk.Tube
+}
+
+func (app *Queue) newBeanstalkd() error {
+ //conn, err := beanstalk.Dial("tcp", "192.168.122.1:11300")
+ conn, err := beanstalk.Dial("tcp", "127.0.0.1:11300")
+ if err != nil {
+ return err
+ }
+ app.Conn = conn
+ app.Tube = &beanstalk.Tube{conn, "gospelchor"}
+
+ return nil
+}
+
+func (app *Queue) sendMessage() error {
+
+ msg, err := json.Marshal(true)
+ if err != nil {
+ return err
+ }
+
+ _, err = app.Tube.Put(msg, 1, 1, time.Minute)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func main() {
+ app := Queue{}
+ err := app.newBeanstalkd()
+ if err != nil {
+ log.WithFields(
+ log.Fields{
+ "error": err,
+ },
+ ).Fatal("cannot connect to beanstalkd")
+ }
+
+ // closes the connection to the beanstalkd server on exit
+ defer func() {
+ app.Conn.Close()
+ }()
+
+ if err := app.sendMessage(); err != nil {
+ app.Conn.Close()
+ log.WithFields(
+ log.Fields{
+ "error": err,
+ },
+ ).Fatal("sending message to beanstalkd failed")
+ }
+}
diff --git a/resources/mq/server/gospelserver.service b/resources/mq/server/gospelserver.service
new file mode 100644
index 0000000..52e6f79
--- /dev/null
+++ b/resources/mq/server/gospelserver.service
@@ -0,0 +1,19 @@
+[Unit]
+Description=mailer
+ConditionPathExists=/usr/local/bin/gospelserver
+After=beanstalkd.service
+#After=libvirtd.service
+#Require=sys-devices-virtual-net-virbr0.device
+#After=sys-devices-virtual-net-virbr0.device
+#Before=libvirt-guests.service
+
+[Service]
+WorkingDirectory=/tmp
+EnvironmentFile=
+User=horus
+ExecStart=/usr/local/bin/gospelserver
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
+
diff --git a/resources/mq/server/message_queue.go b/resources/mq/server/message_queue.go
new file mode 100644
index 0000000..a4fcf14
--- /dev/null
+++ b/resources/mq/server/message_queue.go
@@ -0,0 +1,149 @@
+package main
+
+import (
+ "os"
+ "os/exec"
+ "os/signal"
+ "strings"
+ "sync"
+ "syscall"
+ "time"
+
+ log "github.com/Sirupsen/logrus"
+ "github.com/kr/beanstalk"
+)
+
+// beanstalkd, the message queue
+type Queue struct {
+ Conn *beanstalk.Conn
+ Tube *beanstalk.Tube
+}
+
+func (app *Queue) newBeanstalkd() error {
+ conn, err := beanstalk.Dial("tcp", "192.168.122.1:11300")
+ //conn, err := beanstalk.Dial("tcp", "127.0.0.1:11300")
+ if err != nil {
+ return err
+ }
+ app.Conn = conn
+ app.Tube = &beanstalk.Tube{conn, "gospelchor"}
+
+ return nil
+}
+
+func main() {
+ app := Queue{}
+ err := app.newBeanstalkd()
+ if err != nil {
+ log.WithFields(
+ log.Fields{
+ "error": err,
+ },
+ ).Fatal("cannot connect to beanstalkd")
+ }
+
+ // closes the connection to the beanstalkd server on exit
+ defer func() {
+ app.Conn.Close()
+ }()
+
+ cntGoRoutine := 0
+
+ // we will ensure that we wait for the same number
+ // of routines to complete by using a waitGroup
+ waitGroup := &sync.WaitGroup{}
+ waitGroup.Add(cntGoRoutine + 1)
+
+ shutdownChan := make(chan bool)
+
+ log.Println("app started. beginning consuming jobs...")
+ app.consumeJob(shutdownChan, waitGroup, 1)
+
+ // waits for shutting down
+ term := make(chan os.Signal, 1)
+ signal.Notify(term, os.Interrupt)
+ signal.Notify(term, syscall.SIGTERM)
+
+ <-term
+
+ // sends the signal to close to the workers
+ // +1 because we have a separate goroutine
+ // to check for buried jobs
+ for i := 0; i < cntGoRoutine+1; i++ {
+ go func() {
+ shutdownChan <- true
+ }()
+ }
+ // we wait, until they complete
+ log.Info("waiting for goroutine to finish")
+ waitGroup.Wait()
+
+}
+
+func (app *Queue) consumeJob(shutdownChannel chan bool, waitGroup *sync.WaitGroup, number int) {
+
+ tubeset := beanstalk.NewTubeSet(app.Conn, "gospelchor")
+ // we tell when we return
+ defer waitGroup.Done()
+
+ // Looping to consume all Jobs
+ for {
+
+ select {
+ case _ = <-shutdownChannel:
+ log.WithFields(
+ log.Fields{
+ "goroutine_id": number + 1,
+ },
+ ).Info("getting message to return: ")
+ return
+ default:
+ id, body, err := tubeset.Reserve(60 * time.Second)
+ if err != nil {
+ //log.Println(err)
+ continue
+ }
+ log.WithFields(
+ log.Fields{
+ "job_id": id,
+ },
+ ).Info("recieving job")
+
+ /*
+ err = json.Unmarshal(body)
+ if err != nil {
+ app.Conn.Bury(id, 1)
+ log.WithFields(
+ log.Fields{
+ "job_id": id,
+ "error": err,
+ },
+ ).Warn("decoding json failed")
+ continue
+ }
+ */
+ if !strings.EqualFold(string(body), "true") {
+ app.Conn.Bury(id, 1)
+ continue
+ }
+
+ // rsync den ordner rüber
+ cmdArgs := []string{"--delete", "-avz", "-e ssh", "applications:/var/www/gospeladlershof.de/gospeladlershof.de/", "/var/www/gospeladlershof.de/gospeladlershof.de/"}
+ if _, err = exec.Command("rsync", cmdArgs...).Output(); err != nil {
+ log.WithFields(
+ log.Fields{
+ "error": err,
+ },
+ ).Warn("fatal error using rsync")
+ app.Conn.Bury(id, 1)
+ } else {
+ log.Println("seite synchronisiert")
+
+ // Deleting the job from beanstalkd
+ app.Conn.Delete(id)
+ }
+
+ }
+ }
+
+}