-
Notifications
You must be signed in to change notification settings - Fork 102
How to Setup config.py Remote Configuration
Remotely Manage picamera config.py settings and camera operations from your favorite rclone storage service.
- Introduction
- Prerequisites
- How to Edit watch-app.sh Variables
- How to Implement Remote Configuration
- How to Setup a watch-app.sh crontab Schedule
- How to Manage pi-timolo Files from Remote Storage Sync Folder
- How To reboot.force RPI from Remote Storage Service
- How to Remotely Run a remote-run.sh Bash Script
NOTE: watch-app.sh could be easily adapted for other projects since it is self contained and only needs rclone installed and a service name configured. If you want to try it out, Download a copy to a RPI or Debian OS per commands below.
wget -O watch-app.sh https://raw.github.com/pageauc/pi-timolo/master/source/watch-app.sh
chmod +x watch-app.sh
Then customize variables for your requirements per details in this Wiki. Let me know if you use this on any of your projects. Claude ....
watch-app.sh is a bash script that uses rclone to sync a designated folder name per variable sync_dir default is sync_dir = "mycam-config-sync". This folder resides on the local RPI and remote storage service and can automatically sync configuration file changes placed on the remote storage service sync folder. When an update occurs the files are scanned and files that match entries in the sync_files list variable are transferred to the same folder that watch-app.sh was launched from (usually pi-timolo folder) after a .prev backup is saved. pi-timolo.py is then restarted and new settings will be used. If the application per *watch_app_fname= variable (usually pi-timolo.py) does not restart, then changes are rolled back and app will be restarted. You can manage specified files contained in a watch-app.sh list variable called sync_files . These files must reside in the same folder as watch-app.sh normally pi-timolo folder. watch-app.sh script performs the following tasks.
- Auto restart of an application (usually pi-timolo.py) if it Stops
- Auto Reboot if application (usually pi-timolo.py) if it Fails to restart
- Remotely update specified files in sync_files list variable that exist in pi-timolo folder
- Remotely Run a script named remote-run.sh if allowed
- Remotely force a reboot of RPI if a file called reboot.force is sync'd from the remote storage service.
Before doing the steps in this wiki section, make sure that you have successfully Configured a remote storage service using rclone
watch-app.sh can remotely manage config.py and other variable settings file for pi-timolo.py via rclone and your selected remote storage service. This allows changing config.py and other designated files from a folder on a remote storage service eg google drive. This is useful if you have a camera that is in a remote location. Note the camera Must have an internet connection for this to work.
IMPORTANT You can also manage watch-app.sh settings using ./menubox.sh
Edit watch-app.sh using nano editor (or similar)
cd ~/pi-timolo
nano watch-app.sh
Edit variables below per comments '
watch_config_on=false # true= Remotely Manage Files from Remote Storage false=off
watch_app_on=false # true= Monitor watch_app_fname and attempt restart false=off
watch_reboot_on=false # true= Reboot RPI If watch_app_fname Down false=0ff
watch_app_fname="pi-timolo.py" # Filename of Program to Monitor for Run Status
rclone_name="gdmedia" # Name you gave remote storage service
sync_dir="mycam-config-sync" # Name of folder to manage when watch_config_on=true
# List of file names to monitor for updates
sync_files=("config.py" "pi-timolo.py" "video.conf" \
"watch-app-err.log" "reboot.force" "remote-run.sh")
' ctrl-x y to save nano editor changes
Note You can specify a unique identifier value for sync_dir variable Eg birdcam-config-sync. This allows managing multiple configurations eg I call one of mine tx-deck-conf-sync. This folder will automatically be created locally using copies of files specified in sync_files list. One copy will have a .done and another with .orig file name extension. These will initially be identical. the folder specified by sync_dir will then be synced to the specified remote storage drive root folder and will have the same name and contents. You can leave the sync_files list as default unless you want to be able to remotely edit other pi-timolo files.
To Run watch-app.sh execute the following commands
cd ~/pi-timolo
./watch-app.sh
If this is the first time run and watch_config_on=true then the sync dir will be created and required file on the sync_files variable will be copied into the new folder with .orig and .done extensions. The folder will then be sync to the designed remote storage service using rclone.
If the sync folder per sync_dir exists rclone will sync the remote storage folder to the local folder and scan for files that exist in the sync_files and copy them into the pi-timolo folder after taking a .prev version.
After all files are processed pi-timolo.py will be restarted. If pi-timolo.py execution fails then .prev version will be reinstated and files will be named with a .bad extension and synced back to remote storage folder. If pi-timolo.py started OK then file(s) will have .done extension and include the .prev then be sync'd to remote storage folder to indicate successful implementation. Review media files for any appropriate changes (if media files are being sync'd to remote storage)
NOTE: Changes below can be done using menubox.sh REMOTE menu pick
- Edit watch-app.sh variable watch_config_on=true
- Edit rclone_name= variable for a previously setup rclone remote storage service name
- Optionally Edit sync_dir= and/or sync_files= variables
- Run ./watch-app.sh and the local and remote sync folders will be created with .done and .orig file extensions for each file in the sync_files variable list
- You can also enable watch_reboot_on=true and/or watch_app_on=true*** to turn on these features. default is false or turned off. Note the watch_reboot_on will give a 15 second warning message if run from console. This should only be used with running unattended to avoid surprise reboots if pi-timolo fails for some reason.
Configure a crontab entry to run watch-app.sh per your schedule needs eg every 10 minutes per Example crontab entry below using command
sudo crontab -e
Add Entry below to Run watch-app.sh every 10 minutes as pi user.
*/10 * * * * su pi -c "/home/pi/pi-timolo/watch-app.sh" > /dev/null 2>&1
ctrl-x y to save and exit.
IMPORTANT: It is recommended that you disable plugins so all pi-timolo.py variables are controlled by config.py by setting config.py variable pluginEnable = False.
watch-app.sh allows editing config.py and other allowed pi-timolo files per sync_files variable on a remote storage service folder per sync_dir variable. A sync subfolder per variable sync_dir is automatically created on the local pi-timolo folder and remote storage service root if they do not exist. Files are given extensions .done, .orig and .prev . To implement a change remove the extension from one of the files (normally .done).
The changed file(s) will be sync'd to the remote RPI sync per a scheduled crontab entry on the RPI. The changes will then be copied to the pi-timolo folder and pi-timolo.py restarted. If the change fails and pi-timolo does not restart successfully, the changes will be rolled back and the files will have .bad extension. If successful the files will return with a .done extension to indicate change was successful. A .prev version will be the previous version before the last change attempt. .orig will be a backup copy of the original working file when the the sync folder was created (unless later modified locally on the RPI or a new local sync folder is created).
Changed config.py or other allowed files can be modified and uploaded to the remote watch_app.sh subfolder per sync_dir variable. You can also modify them directly on the remote storage service (eg google drive notepad). You can do this by temporarily renaming file with a .txt extension eg config.py.done.txt edit the file then rename it to config.py and the change will be synced per next crontab schedule. If successful, file will be returned with .done and previous (un modified version) with .prev extension. If change failed (pi-timolo.py did not restart successfully) then file(s) will have .bad extension.
If you delete the local or remote folder specified by sync_dir variable it will automatically be recreated the next time watch-app.sh is run manually or via crontab entry. This can be useful if you intentionally or unintentionally delete the local or remove folder. It can also be handy for refreshing files.
If variable watch_config_on=true and a file called reboot.force is placed in the remote storage service folder specified by variable sync_dir then watch-app.sh will reboot the Raspbery Pi. Log history will be stored in the reboot.force and it will be renamed reboot.force.log. There should already be a reboot.force.log file when the sync_dir= was created. You can rename this file by removing the .log from the filename. The file will contain the reboot log history.
If variable watch_config_on=true and a file called remote-run.sh is in the remote storage service folder specified by variable sync_dir and a dummy file named remote-run.sh exists in the pi-timolo folder (default install) then watch-app.sh will attempt to run the script as a background task. If an existing remote-run.sh script is already running, it will be killed and the new version will be started as a background task. Output will be sent to remote-run.sh.log and the previous version of the script will be named remote-run.sh.prev. The uploaded remote-run.sh on the remote storage service will be renamed remote-run.sh.done
This will allow you to remotely perform tasks specified in the remote-run.sh script eg special rclone job or some file maintenance. IMPORTANT: Make sure you test the custom remote-run.sh script before you upload it to the folder specified by the watch-app.sh sync_dir variable.
- Wiki Home
- Introduction
- Prerequisites
- Install or Upgrade
- Run pi-timolo from a drive mnt
- Customize config.py
- Panoramic Images
- user_motion_code.py
- Align Camera Motion Area
- Schedule StartAt
- Basic Troubleshooting
- Tuning Variable Settings
- menubox.sh
- Web Server View Files
- Make Timelapse Video
- Join or Convert h264 to MP4
- Run on Boot
- Setup & Run shutdown.py
- Rclone Media Sync
- watch-app.sh Usage
- Plugins Usage
- Mount USB Storage
- Mount Network Share
- Auto SubFolder Creation
- Manage Disk Space
- Utilities Summary
- GitHub Repo
gdrive is no longer default.