Skip to content

Commit

Permalink
Added refresh button to logs and increased log textarea.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kugelschieber committed Dec 11, 2018
1 parent 35e0515 commit 0067647
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
16 changes: 13 additions & 3 deletions instance/mgn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -61,9 +62,6 @@ func StartInstance(instanceName string, configuration int64) error {
}

// force server_cfg and entry_list ini paths
// start
// FIXME: s.Args has been discarted. No real use so far?
// cmd := exec.Command(filepath.Join(s.Folder, s.Executable), strings.Split(cmdArgs, " ")...)
cmd := exec.Command(filepath.Join(s.Folder, s.Executable), "-c", iniServerCfg, "-e", iniEntryList)
now := time.Now().Format("20060102_150405")

Expand Down Expand Up @@ -96,6 +94,18 @@ func StartInstance(instanceName string, configuration int64) error {
return nil
}

func runScript(scriptPath string, processId int, logfile *os.File) {
// pass the process ID of the server instance (or 0 if not set) and log output to the log file
cmd := exec.Command(scriptPath, strconv.Itoa(processId))
cmd.Stdout = logfile
cmd.Stderr = logfile
cmd.Dir = filepath.Dir(scriptPath)

if err := cmd.Start(); err != nil {
log.WithFields(log.Fields{"err": err, "script_path": scriptPath, "process_id": processId}).Error("Error starting script")
}
}

func observeProcess(cmd *exec.Cmd) {
if err := cmd.Wait(); err != nil {
exitErr, ok := err.(*exec.ExitError)
Expand Down
22 changes: 19 additions & 3 deletions public/src/pages/instance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@
<div class="box" v-if="showLog">
<div class="wrapper">
<h2>Log Output</h2>
<button v-on:click="refreshLog">Refresh</button>
<small>(showing the last 256kb)</small>
<textarea v-model="log"></textarea>
<textarea v-model="log" style="min-height: 300px;"></textarea>
<button v-on:click="showLog = false">Close</button>
</div>
</div>
Expand Down Expand Up @@ -176,7 +177,8 @@ export default {
started: false,
stopped: false,
startInstance: false,
stopInstance: false
stopInstance: false,
logFile: ''
}
},
mounted() {
Expand Down Expand Up @@ -259,6 +261,7 @@ export default {
this.stopped = false;
this.startInstance = false;
this.stopInstance = false;
this.logFile = '';
},
performStart() {
axios.post('/api/instance', {name: this.name, config: this.config})
Expand Down Expand Up @@ -300,8 +303,9 @@ export default {
},
openLog(file) {
this._reset();
this.logFile = file;
axios.get('/api/instance/log', {params: {file: file}})
axios.get('/api/instance/log', {params: {file}})
.then(resp => {
if(resp.data.code){
console.log(resp.data.code+': '+resp.data.msg);
Expand Down Expand Up @@ -340,6 +344,18 @@ export default {
},
closeMsg() {
this.err = 0;
},
refreshLog() {
axios.get('/api/instance/log', {params: {file: this.logFile}})
.then(resp => {
if(resp.data.code){
console.log(resp.data.code+': '+resp.data.msg);
return;
}
var log = resp.data.substr(1, resp.data.length-2).split('\\n');
this.log = log.join('\n');
});
}
}
}
Expand Down

0 comments on commit 0067647

Please sign in to comment.