hallo @ all ,
i am new here and german, so sorry for my english :-)
i build my first module. i started with this simple module.
it works. then i add an exec command
exec("bash ../MagicMirror/config/test.sh", (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`)
return;
}
thats works ?! i am not sure.
the test.sh
cp ../MagicMirror/config/config.js ../MagicMirror/config/config_1.js
pm2 restart all
in my custom_menu.json i have an entry that send the notification TEST, my MMM_MeinModul.js recieved this and send
this.sendSocketNotification('START_TEST', {});
when my node_helper.js recieved this then call the function with the exec command.
the result is an error at pm2 log:
exec error: Error: Command failed: bash ../MagicMirror/config/test.sh
but thats not true. the pm2 restart all are executed and restart the mm.
playerRadio
0|MagicMirror | [06.07.2021 19:22.56.851] [LOG] Stopping module helper: MMM-Tools
0|MagicMirror | [06.07.2021 19:22.56.883] [ERROR]
0|MagicMirror | exec error: Error: Command failed: bash ../MagicMirror/config/test.sh
0|MagicMirror | > magicmirror@2.16.0 start /home/pi/MagicMirror
0|MagicMirror | > DISPLAY="${DISPLAY:=:0}" ./node_modules/.bin/electron js/electron.js
0|MagicMirror | [06.07.2021 19:23.02.329] [LOG]
0|MagicMirror | Starting MagicMirror: v2.16.0
so, i think the cp command not work, but i dont understand the problem.
here my module
Module.register("MMM-MeinModul",{
defaults: {
text: "Sergio"
},
getDom: function() {
var wrapper = document.createElement("div");
wrapper.innerHTML = this.config.text;
return wrapper;
},
start: function() {
this.sendSocketNotification('CONFIG', this.config);
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'STARTED') {
console.log("MMM-MeinModule notification [" + notification + "] payload [" + payload + "]")
this.config.text = 'Started';
this.updateDom();
}
},
notificationReceived: function(notification, payload) {
if (notification === 'TEST') {
console.log("MMM-MeinModule notification [" + notification + "] payload [" + payload + "]")
this.config.text = 'changed';
this.updateDom();
this.sendSocketNotification('START_TEST', {});
}
}
});
and here my node_helper
var NodeHelper = require("node_helper");
const exec = require("child_process").exec;
module.exports = NodeHelper.create({
start: function () {
this.config = {}
},
copyfile: function () {
console.log(__dirname)
exec("bash ../MagicMirror/config/test.sh", (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`)
return;
}
});
},
socketNotificationReceived: function (notification, payload) {
if (notification === 'CONFIG') {
this.config = payload;
console.log("MMM-MeinModule node_helper (config) notification [" + notification + "] payload [" + payload + "]")
this.sendSocketNotification('STARTED',payload);
}
if (notification === 'START_TEST') {
console.log("MMM-MeinModule node_helper (TEST) notification [" + notification + "] payload [" + payload + "]")
this.copyfile();
}
}
});
can sameone get a hint please ?