MagicMirror_scripts icon indicating copy to clipboard operation
MagicMirror_scripts copied to clipboard

How to stop autostart ? ie to switch to server mode

Open cruzanhtpc opened this issue 2 years ago • 21 comments

I used your script. Works Great! but im trying to see how to do i stop it from autostarting the client? Basically i want to run this in server mode only now and cant figureout how to do it with your script.

My end result is running MM in server mode (its already running and config with your script) and then loading midori on my pi zero 2 w. Or modifying your script to use Midori
Any help would be appreciated.

cruzanhtpc avatar Jan 02 '22 02:01 cruzanhtpc

for more context. I have couple of pi zero 2w, I want to run MM off my pi02w in server mode then launch midori in fullscreen to the mm page. or modify mm to use midori.

Reason. I have a module that loads background wallpaper and it will crash MM after about 20 min. and i think its because of chromium

I have a similar setup with Dakboard on a pi02w and running it with chromium will crash my dakboard , but after i switched to Midori, runs for days without issues changing wallpaper nonstop.

cruzanhtpc avatar Jan 02 '22 02:01 cruzanhtpc

install adds a script, run-srart.sh

this is how we launch chrome over server

change the package.json start line to launch run-start.sh

then change the serverOnly parm in config.js to 'local'

then run-start will start server and launch chrome

but u can change to launch Midori instead

sdetweil avatar Jan 02 '22 02:01 sdetweil

sdetweil, Thank you for the quick response , i think i did it right. can you check my below.. i think i messed up Midori though, on my other pi i use in autostart @midori -e Fullscreen http://.....

config.js serverOnly: "local",

package.json "scripts": { "start": "/home/pi/MagicMirror/run-start.sh",

run-start (is this right?)

start chromium

  echo "Starting chromium browser now, have patience, it takes a minute"
  # continue to spool stdout to console
  tee <&3 &
    if [ $mac != 'Darwin' ]; then
    b="chromium"
  if [ $(which $b). == '.' ]; then
    b='midori'
   # b='chromium-browser'
  fi
    if [ $(which $b). != '.' ]; then
    "$b" -e Fullscreen --app=http://localhost:$port 2>/dev/null/ 

cruzanhtpc avatar Jan 02 '22 02:01 cruzanhtpc

looks good.

didn't need full path on run-start in package.json. it's launched in the mm folder so "./run-start.sh"

would have been enough.

u can test it by running ./run-start.sh in the mm folder

bash -x ./run-start.sh

will show debug as it executes

the main logic tests if chromium is NOT found, then use chromium-browser raspi has one, Ubuntu has another.

sdetweil avatar Jan 02 '22 02:01 sdetweil

I update the json "start": "DISPLAY="${DISPLAY:=:0}" ./run-start.sh",

im getting this error running bash -x ./run-start.sh

SyntaxError: Error parsing /home/pi/MagicMirror/package.json: Unexpected token / in JSON at position 213 at parse () at readPackage (node:internal/modules/cjs/loader:304:20) at readPackageScope (node:internal/modules/cjs/loader:329:19) at shouldUseESMLoader (node:internal/modules/run_main:39:15) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:74:24) at node:internal/main/run_main_module:17:47 { path: '/home/pi/MagicMirror/package.json'

And right i am using raspi, so it should be looking for chromium-browser right? or are you saying i need to modify the chromium also to say midori also?

cruzanhtpc avatar Jan 02 '22 03:01 cruzanhtpc

"start":"./run-start.sh",

I don't remember which is which, but u can use the which ??? command to find the path to either executable

??? is chromium or chromium-browser

sdetweil avatar Jan 02 '22 03:01 sdetweil

json, everything must be quoted, double quotes.

quotes inside quotes have to be escaped with \ in front of the internal ones

sdetweil avatar Jan 02 '22 03:01 sdetweil

ah ok, i think i got it now! had an error with the midori portion but now bash -x ./run-start.sh executes without an error. time to reboot and see if it loads all up as expected using midori

cruzanhtpc avatar Jan 02 '22 03:01 cruzanhtpc

don't need to reboot. just pm2 restart 0

sdetweil avatar Jan 02 '22 04:01 sdetweil

@cruzanhtpc did u get it to work?

sdetweil avatar Jan 02 '22 16:01 sdetweil

For the most part, sorry have been letting it run to see if it crashes etc... But yes Midori launches as expected.

I say most part because with chrome I could reduce the font size or module size by editing config.js , zoom: 0.6 and it would reduce everything. When using Midori doesn't seem to respect that zoom. So trying to figure out how to now scale everything down to the right zoom with Midori but no luck.

But I really appreciate it! Everything worked!

cruzanhtpc avatar Jan 02 '22 23:01 cruzanhtpc

woohoo. glad to hear. I know nothing about Midori, sorry

sdetweil avatar Jan 02 '22 23:01 sdetweil

So question. In theory. If I didn't call your run-start.sh in start of the package.json. like omitted this. Couldn't I just Auto start Midori and point it to localhost. By editing /etc/xdg/lxsession/LXDE-pi/autostart

And adding

@midori -e Fullscreen http://localhost:8080

I'm asking since I trying to see if I can get Midori to zoomout via this method.

If so then what do I put in start for package.json ?

cruzanhtpc avatar Jan 02 '22 23:01 cruzanhtpc

just

npm run server

not npm start

I don't know what the @ does in linux.in windows it sliences echo of the command being executed

sdetweil avatar Jan 02 '22 23:01 sdetweil

Where do I edit that ? Or how do I Auto start that at boot of pi?

cruzanhtpc avatar Jan 02 '22 23:01 cruzanhtpc

Oh ok, that is how I autostart Midori for my other pi 02w to load a page in Fullscreen at boot

cruzanhtpc avatar Jan 02 '22 23:01 cruzanhtpc

edit that?

here is zooming on Midori

@midori -e Fullscreen -e ZoomIn -e ZoomIn -a http://10.0.0.254:8080 -p

(Google search)

I use pm2 to launch at boot works the same everywhere, I don't edit system files

make a bash script that does npm run server

then pm2 start script file

the pm2 save

then reboot

sdetweil avatar Jan 02 '22 23:01 sdetweil

Yeah that is the way I have been trying to get zoom to work via run-start.sh

Got it I'm not familiar with pm2 that's why I asked , but makes sense now that you said.

cruzanhtpc avatar Jan 03 '22 00:01 cruzanhtpc

strange it doesnt zoom via runstart. it's just a script. nothing special..

wonder if it's because of npm or pm2 or both..

if I just run runstart from the mm folder does it work ok?

./run-start.sh

sdetweil avatar Jan 03 '22 00:01 sdetweil

When just running the script Midori Doesn't like the -e ZoomOut. Or -e ZoomIn but it does run with -e Fullscreen

cruzanhtpc avatar Jan 03 '22 01:01 cruzanhtpc

i have added support for launching midori on linux

add

export external_browser=midori to the installers/mm.sh before the npm start line

run-start.sh will use that to launch midori over server-only mode

sdetweil avatar May 05 '22 21:05 sdetweil