Add web server to dev image
This commit is contained in:
@@ -68,6 +68,12 @@ func doMain() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = postInit(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
newQM, err := createQueueManager(name)
|
||||
if err != nil {
|
||||
logTermination(err)
|
||||
|
||||
@@ -61,7 +61,9 @@ func mirrorAvailableMessages(f *os.File, mf mirrorFunc) {
|
||||
mf(t)
|
||||
count++
|
||||
}
|
||||
log.Debugf("Mirrored %v log entries from %v", count, f.Name())
|
||||
if count > 0 {
|
||||
log.Debugf("Mirrored %v log entries from %v", count, f.Name())
|
||||
}
|
||||
err := scanner.Err()
|
||||
if err != nil {
|
||||
log.Errorf("Error reading file %v: %v", f.Name(), err)
|
||||
|
||||
36
cmd/runmqserver/post_init_dev.go
Normal file
36
cmd/runmqserver/post_init_dev.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// +build mqdev
|
||||
|
||||
/*
|
||||
© Copyright IBM Corporation 2018
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package main
|
||||
|
||||
import "os"
|
||||
|
||||
// postInit is run after /var/mqm is set up
|
||||
// This version of postInit is only included as part of the MQ Advanced for Developers build
|
||||
func postInit(name string) error {
|
||||
disable := os.Getenv("MQ_DISABLE_WEB_CONSOLE")
|
||||
if disable != "true" && disable != "1" {
|
||||
// Configure and start the web server, in the background (if installed)
|
||||
// WARNING: No error handling or health checking available for the web server,
|
||||
// which is why it's limited to use with MQ Advanced for Developers only
|
||||
go func() {
|
||||
configureWebServer()
|
||||
startWebServer()
|
||||
}()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
22
cmd/runmqserver/post_init_other.go
Normal file
22
cmd/runmqserver/post_init_other.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// +build !mqdev
|
||||
|
||||
/*
|
||||
© Copyright IBM Corporation 2018
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package main
|
||||
|
||||
func postInit(name string) error {
|
||||
return nil
|
||||
}
|
||||
110
cmd/runmqserver/webserver.go
Normal file
110
cmd/runmqserver/webserver.go
Normal file
@@ -0,0 +1,110 @@
|
||||
// +build mqdev
|
||||
|
||||
/*
|
||||
© Copyright IBM Corporation 2018
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/ibm-messaging/mq-container/internal/command"
|
||||
)
|
||||
|
||||
func startWebServer() error {
|
||||
_, err := os.Stat("/opt/mqm/bin/strmqweb")
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
log.Debug("Skipping web server, because it's not installed")
|
||||
return nil
|
||||
}
|
||||
log.Println("Starting web server")
|
||||
out, rc, err := command.RunAsMQM("strmqweb")
|
||||
if err != nil {
|
||||
log.Printf("Error %v starting web server: %v", rc, string(out))
|
||||
return err
|
||||
}
|
||||
log.Println("Started web server")
|
||||
return nil
|
||||
}
|
||||
|
||||
func configureWebServer() error {
|
||||
_, err := os.Stat("/opt/mqm/bin/strmqweb")
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
const webConfigDir string = "/etc/mqm/web"
|
||||
_, err = os.Stat(webConfigDir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
uid, gid, err := lookupMQM()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
const prefix string = "/etc/mqm/web"
|
||||
err = filepath.Walk(prefix, func(from string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
to := fmt.Sprintf("/var/mqm/web%v", from[len(prefix):])
|
||||
exists := true
|
||||
_, err = os.Stat(to)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
exists = false
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
if !exists {
|
||||
err := os.MkdirAll(to, 0770)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
log.Printf("Directory: %v --> %v", from, to)
|
||||
} else {
|
||||
if exists {
|
||||
err := os.Remove(to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// TODO: Permissions. Can't rely on them being set in Dockerfile
|
||||
err := os.Link(from, to)
|
||||
if err != nil {
|
||||
log.Debug(err)
|
||||
return err
|
||||
}
|
||||
log.Printf("File: %v", from)
|
||||
}
|
||||
err = os.Chown(to, uid, gid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user