Skip to content

Commit

Permalink
add npm stop for stop MagicMirror process
Browse files Browse the repository at this point in the history
  • Loading branch information
bugsounet committed Sep 1, 2023
1 parent 4606fdd commit 0f27ccd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ _This release is scheduled to be released on 2023-10-01._

- Added UV Index support to OpenWeatherMap
- Added 'hideDuplicates' flag to the calendar module
- Added 'npm stop' for stop MagicMirror

### Removed

Expand Down
13 changes: 13 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function App() {
let nodeHelpers = [];
let httpServer;

writePid();
/**
* Loads the config file. Combines it with the defaults and returns the config
* @async
Expand Down Expand Up @@ -329,6 +330,18 @@ function App() {
return httpServer.close();
};

/**
* Write MagicMirror pid
*/
function writePid() {
let pid = process.pid;
Log.log(`MagicMirror is available on pid: ${pid}`);
fs.writeFile("MagicMirror.pid", pid.toString(), (error) => {
if (error) Log.error(`MagicMirror.pid writing error!: ${error.message}`);
else Log.debug(`MagicMirror.pid file writed!`);
});
}

/**
* Listen for SIGINT signal and call stop() function.
*
Expand Down
19 changes: 19 additions & 0 deletions js/stop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** Stop MagicMirror from MagicMirror.pid file */

const readFile = require("fs").readFile;

let pid;
readFile("MagicMirror.pid", "utf8", (err, data) => {
if (err) {
console.error("Error reading MagicMirror.pid file");
console.error(err.message);
} else {
pid = data;
try {
process.kill(pid, "SIGINT");
console.log(`MagicMirror² killed from process ${pid}`);
} catch (e) {
console.error(`MagicMirror² not found on process ${pid}`);
}
}
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "js/electron.js",
"scripts": {
"start": "DISPLAY=\"${DISPLAY:=:0}\" ./node_modules/.bin/electron js/electron.js",
"stop": "node js/stop.js",
"start:dev": "DISPLAY=\"${DISPLAY:=:0}\" ./node_modules/.bin/electron js/electron.js dev",
"server": "node ./serveronly",
"install-mm": "npm install --no-audit --no-fund --no-update-notifier --only=prod --omit=dev",
Expand Down

0 comments on commit 0f27ccd

Please sign in to comment.