Read the statement by Michael Teeuw here.
PM2 for server mode
-
What must I do to use pm2 to launch in server mode at boot?
My eventual goal is to have multiple instances running server mode on multiple ports. As I understand it I need to copy the MagicMirror directory for each instance and change ports.
But how can I launch them at boot with PM2?
Thank you!
-
change the command in the script pm2 starts
as for multiple instances you can do it all from one folder
use the MM_CONFIG_FILE environment variable
and maybe MM_PORT variableyou can start them all in one script, but hard to stop
they can all use the same config file and use MM_PORT to
override what is in the config file
or use a different config file tooyou can install all modules in the one folder
and use different modules in different instancesnpm run server
instead of
npm run startthen
pm2 start server1.sh
pm2 start server2.shetc
pm2 savepm2 status should show them running
reboot
-
@sdetweil Thank you!
-
@sifuhall one thing
pm2’s job is to keep the app running. so when the script ends it restartsin windows to spin off a separate task you use detach
detach xxxx.bat
in
linux you use the & as last characterxxx.sh &
so if you choose to launch from one script
# use port in config.js
npm run server &
# override port in config.js
export MM_PORT=8090
npm run server &
# override port in config.js
export MM_PORT=8100
npm run server &there is nothing to keep the script running
and pm2 will relaunch itjust remove the last &
and bash will wait for that command to end(never)
pm2 will be happy