MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Create another PM2 Script?

    Scheduled Pinned Locked Moved Troubleshooting
    7 Posts 2 Posters 3.1k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      Damian @Damian
      last edited by

      @Mods

      Appreciate I have posted this twice in 2 seperate posts - but other one is FAO the Developer in his original post of 1 year ago, and to the poster who replied with his fix.

      This post goes to anyone here who can help me with making and executing a script, going by the example given for this module.

      1 Reply Last reply Reply Quote 1
      • bheplerB Offline
        bhepler Module Developer
        last edited by bhepler

        Okay, a couple things. sono.sh is your script that starts your process. ~ is the shortcut to the pi user’s home directory, also known as /home/pi. In order to run scripts from the command line, you have to precede the script name with ./

        So let’s take a moment to verify the state of your pi. Change to the home directory and pull up the file list with a couple switches to see if sonos.sh exits:

        pi@raspi:~ $ cd ~
        pi@raspi:~ $ ls -lh sonos.sh
        -rwxr-xr-x 1 pi pi 26 April 15 11:50 sonos.sh
        

        There will be some variation in your results. If you see the phrase “No such file or directory”, then the file does not exist at that location. Also, you may not have any “x” entries when you do see the file listed. If so, the file is not marked executable, so it won’t run. You can fix this by typing chmod +x sonos.sh

        I’m a little unclear as to what commands exactly are in your sonos.sh file. Could you please enter cat sonos.sh and reply with the results?

        Adding the script to pm2 is done by typing pm2 start sonos.sh. You can then verify that pm2 has picked it up by typing pm2 status all. That will give you a list of the processes that pm2 is controlling. You should see both your mm.sh process and your sonos.sh process.

        Give that a go and report back to us.

        D 1 Reply Last reply Reply Quote 1
        • D Offline
          Damian @bhepler
          last edited by Damian

          @bhepler

          Thanks so much for your help on this as it was doing my head in…

          Ok… I entered everything exactly as you stated above… and found everything you stated… and then it worked - Thank you so much for that, I sincerely appreciate your help on this.

          Can I ask you one more favour please?

          Going by the instructions I followed above, which made no sence to me in the format it was written… can I ask you what your simple instructions would be to complete that part? In a more understandable format than what is written above, and how it is written.

          This would help others understanding how to make that PM2 Script, and not confuse them, and would also educate me on how I should have done it.

          Thanks again.

          create another pm2 script named sonos.sh in ~ directory
          cd ~
          sonos.sh file contents:
          cd ~/node-sonos-http-api
          DISPLAY=:0 npm start
          
          pm2 start sonos.sh
          pm2 start mm
          pm2 save
          
          
          bheplerB 1 Reply Last reply Reply Quote 0
          • bheplerB Offline
            bhepler Module Developer @Damian
            last edited by bhepler

            @Damian Sure, I can do that. Let me re-write this a bit.

            Step 1 - Create a script called sonos.sh in the home directory (~).

            cd ~
            nano sonos.sh
            

            Enter the following in the nano editor for the contents of your sonos.sh script:

            cd ~/node-sonos-http-api
            DISPLAY=:0 npm start
            

            Save the file and exit the nano editor.

            Step 2 - Make your script executable by entering chmod +x sonos.sh

            Step 3 - Tell pm2 to manage your sonos script so that it is always running in the background:

            pm2 start sonos.sh
            pm2 save
            

            Verify that pm2 is managing both your sonos.sh script and the mm.sh script by typing pm2 status all. You should see two lines, one for each script.

            Step 4 - Clear the logs and bounce your mirror and verify that everything works as planned.

            pm2 flush
            pm2 restart all
            
            D 1 Reply Last reply Reply Quote 3
            • D Offline
              Damian @bhepler
              last edited by

              @bhepler

              Thanks very much for that, appreciated.

              Inclusion of nano will help as that was not mentioned.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Enjoying MagicMirror? Please consider a donation!
              MagicMirror created by Michael Teeuw.
              Forum managed by Sam, technical setup by Karsten.
              This forum is using NodeBB as its core | Contributors
              Contact | Privacy Policy