Read the statement by Michael Teeuw here.
Magic Mirror startup script.
-
Hello,
Because I believe that Computers are much better at performing and repeating recurring commands and I regularly forget to do it the right way, I thought it would be nice to create a Magic Mirror startup script for myself. Another reason for making those scripts is for me to better understand how the Operating Systems works.I worked with Unix for the last time more than 20 years ago on a Four Phase/Motorola Unix System V Office computers. Very slowly pieces of memory come up from frequently used commands and making useful scripts that sometimes also look a lot like existing Windows environment commands. Sorry for that ;-)
The script that I have now does almost do what I want. Testing the presence of the Magic Mirror home directory. Then change directory to that directory, and then perform a test on the configuration script for possible syntax errors. No errors found, then start Magic Mirror and enjoy the result. And so far it works nice and easy and the way I like it. But …
At least that’s what I thought till now. Until I made a error in the configuration script. Despite the syntax error Magic Mirror was starting. And that’s precisely NOT my intention of this startup script. In that case, I want first to solve the error(s) I made.
The syntax checker test that I found was listed in the MM documentation: ./MagicMirror/npm run config:check. This gives a lot of information about why and where to look for errors when syntax errors are found. Only after the extraction and error code listing the error (echo $?) gives always a 0. And I d’not know why, and what the underlying idea is.
Changing made into someone else’s script with the danger that after an update or re-installation you lose everything with what you have adjusted in it is great, and that’s why I prefer not to do it. I also do not understand everything in detail with what is being executed in the config_check.js script yet.
So therefore, in my startup script I run first the “./MagicMirror/npm run config:check” test to receive in a case of a error a nice list with syntax errors and second than I run the command’s “node -c config/config.js” to receive a errorcode -ne 0. Then I test this and decide not to start Magic Mirror but first solving the syntax error. Not the best solution but at the moment I do not know a better way how to do it.
But I would like to know why the error code cannot be retrieved and what I can do to get it done. Is there anybody who likes to help me and give me a nice solution how to solve this problem ?
-
Personally, I don’t see why you’d have anything more than
cd ~/MagicMirror
DISPLAY=:0 npm startin your magic mirror startup script. I personally have a 2nd script with the config check in it, so I can see errors and fix them before I manually run the PM2 restart.
-
@bkeyport . You’re absolutely right in that, and that’s how I did it all the time. But to create a script where it does not matter where you are at that moment, it seemed like a fun project to start building scripts again.
Do you happen to have an answer about my questions?