Can't get startup script to run - want to shut off camera on start or prevent from running until a print starts

What is the problem?
I'm trying to prevent the camera from starting up automatically when the server boots up.

What did you already try to solve it?
Looked in settings.
Added script that waits 30 seconds after the Startup event fires then shuts down the camera.

.

The below Startup event command doesn't seem to fire. It writes nothing to the webcamstart.log

My subscription to startup (please forgive the extra code for debugging):

  - command: echo "Webcam stop at Startup called at $(date) > /home/pi/scripts/webcamstart.log &&  /home/pi/scripts/webcam_cancel_on_start >> /home/pi/scripts/$
    async: true
    event: Startup
    type: system

webcam_cancel_on_start script (works fine from bash):

#!/bin/bash
# Waits a few seconds then shuts down the camera
sleep 30
webcam stop

webcam script from here (works on bash and via config.yaml system/actions):

Additional information about your setup
OctoPrint 1.3.9 running on OctoPi 0.15.1
Nothing in octoprint.log indicates an issue, can upload a sample if needed.

Thanks!!

Is the format correct for your event? Sorry, haven't messed much with these, but maybe something like this?

events:
  subscriptions:
    - event: Startup
      command: "/home/pi/scripts/webcam_cancel_on_start"
      type: system

Just not sure if the dash on the subscription has to be on the event line or not, just noticed that difference from the documentation.

Well, the issue wasn't that the order of elements is wrong in the yaml, but it did get me to look closer and I was missing a quotation mark. Also it appears that you can't string commands together with double ampersands in the config event.

So I migrated all of that code over to the webcam_cancel_on_start script and I get my logging now.

However, the webcam is still running after startup. I even added a 2 minute delay between startup event and calling the script that turns off the camera.

After some more observation it seems that something is restarting the webcam.

If I use the web interface to call my webcam stop script then the webcam stops, but if I wait a couple of minutes and refresh the page then the webcam is running again. But if I run that from the bash terminal the webcam remains stopped until i run webcam start from the terminal again. Running webcam start from the web interface will not restart it.

I've uploaded the scripts, config.yaml, and logs in case someone wants to look over them.

OctoprintWebcamIssue_20180831-1040.zip (10.9 KB)

You should read the nearly-identical thread that was created in the Get Help section just this week.

1 Like

Oh man, thanks for linking me to that. It did not come up in searches (hence why I put a lot of keywords in the title of this thread). Looks like that might be a path to getting this to work right.