• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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.

[Solved]How to start a python script @reboot?

Scheduled Pinned Locked Moved General Discussion
10 Posts 3 Posters 6.4k Views 3 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.
  • P Online
    pauabaer
    last edited by May 1, 2017, 9:23 PM

    It does not work at all. At least not the way i hoped.

    see here: https://forum.magicmirror.builders/topic/2468/mmm-pir-sensor-delay

    so i really like to get the python-autostart working. any help?

    1 Reply Last reply Reply Quote 0
    • D Offline
      d3r
      last edited by d3r May 1, 2017, 9:44 PM May 1, 2017, 9:43 PM

      Look into cron.
      [Cron](https://thepihut.com/blogs/raspberry-pi-tutorials/34930820-running-things-regularly-cron

      1 Reply Last reply Reply Quote 0
      • P Online
        pauabaer
        last edited by May 1, 2017, 9:51 PM

        thanks so far.
        i have already put this as cron: @reboot sudo /usr/bin/python /home/pi/monitor.py &
        but nothing happens

        when i want to start this, i will get this message:
        /etc/init.d/cron restart
        […] Restarting cron (via systemctl): cron.serviceFailed to restart cron.service: Access denied
        failed!
        So what can i do now?

        D 1 Reply Last reply May 2, 2017, 1:05 AM Reply Quote 0
        • D Offline
          d3r @pauabaer
          last edited by May 2, 2017, 1:05 AM

          @pauabaer It’s easier to just make your python code executable. Then you can just start it with cron with
          @reboot /home/pi/monitor.py

          1 Reply Last reply Reply Quote 0
          • P Online
            pauabaer
            last edited by May 2, 2017, 5:47 PM

            Two questions:

            1. how do i make it executable?
            2. when the script is executable, the problem with the failure is still existing, isn’t it?
            D 1 Reply Last reply May 2, 2017, 9:48 PM Reply Quote 0
            • D Offline
              d3r @pauabaer
              last edited by May 2, 2017, 9:48 PM

              @pauabaer To make the code executable:

              1. Add #!/usr/bin/python3 to the top of your code.(1st line)
              2. open terminal and type sudo chmod +x /home/pi/monitor.py (this will make your code executable. You can check that it’s executable by typing “./monitor.py” You code should run.

              Then you can add the line @reboot /home/pi/monitor.py to the crontab.

              1 Reply Last reply Reply Quote 0
              • P Online
                pauabaer
                last edited by May 2, 2017, 10:15 PM

                Ok. Thanks. I made these two steps and i can see via htop that the script is running.

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                1 / 1
                • First post
                  8/10
                  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