Configure supervisord to run video_looper on boot.

This commit is contained in:
Tony DiCola 2015-02-10 22:20:14 -08:00
parent a1da408897
commit 7f1a14e636
5 changed files with 73 additions and 7 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
omxplayer-dist.tgz*
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

View File

@ -55,9 +55,9 @@ class OMXPlayer(object):
"""
# Stop the player if it's running.
if self._process is not None and self._process.returncode is None:
# process.kill() doesn't seem to work reliably if USB drive is
# removed, instead just run a kill -9 on it.
subprocess.call(['kill', '-9', str(self._process.pid)])
# There are a couple processes used by omxplayer, so kill both
# with a pkill command.
subprocess.call(['pkill', '-9', 'omxplayer'])
# If a blocking timeout was specified, wait up to that amount of time
# for the process to stop.
start = time.time()

View File

@ -1,12 +1,12 @@
# Copyright 2015 Adafruit Industries.
# Author: Tony DiCola
# License: GNU GPLv2, see LICENSE.txt
import atexit
import ConfigParser
import importlib
import os
import re
import sys
import signal
import time
import pygame
@ -50,7 +50,6 @@ class VideoLooper(object):
self._console_output = self._config.getboolean('video_looper', 'console_output')
# Load configured video player and file reader modules.
self._player = self._load_player()
atexit.register(self._player.stop) # Make sure to stop player on exit.
self._reader = self._load_file_reader()
# Load other configuration values.
self._osd = self._config.getboolean('video_looper', 'osd')
@ -73,6 +72,7 @@ class VideoLooper(object):
self._extensions = self._player.supported_extensions()
self._small_font = pygame.font.Font(None, 50)
self._big_font = pygame.font.Font(None, 250)
self._running = True
def _print(self, message):
"""Print message to standard output if console output is enabled."""
@ -186,7 +186,7 @@ class VideoLooper(object):
playlist = self._build_playlist()
self._prepare_to_run_playlist(playlist)
# Main loop to play videos in the playlist and listen for file changes.
while True:
while self._running:
# Load and play a new movie if nothing is playing.
if not self._player.is_playing():
movie = playlist.get_next()
@ -205,14 +205,26 @@ class VideoLooper(object):
# Give the CPU some time to do other tasks.
time.sleep(0)
def signal_quit(self, signal, frame):
"""Shut down the program, meant to by called by signal handler."""
self._running = False
if self._player is not None:
self._player.stop()
pygame.quit()
# Main entry point.
def main():
print('Starting Adafruit Video Looper.')
# Default config path to /boot.
config_path = '/boot/video_looper.ini'
# Override config path if provided as parameter.
if len(sys.argv) == 2:
config_path = sys.argv[1]
# Create video looper and run it.
# Create video looper.
videolooper = VideoLooper(config_path)
# Configure signal handlers to quit on TERM or INT signal.
signal.signal(signal.SIGTERM, videolooper.signal_quit)
signal.signal(signal.SIGINT, videolooper.signal_quit)
# Run the main loop.
videolooper.run()

45
install.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh
# Error out if anything fails.
set -e
# Make sure script is run as root.
if [ "$(id -u)" != "0" ]; then
echo "Must be run as root with sudo! Try: sudo ./install.sh"
exit 1
fi
echo "Installing dependencies..."
echo "=========================="
#apt-get update
#apt-get -y install build-essential python-dev python-pip python-pygame supervisor git
echo "Installing omxplayer..."
echo "======================="
if [ -f "omxplayer-dist.tgz" ]; then
rm omxplayer-dist.tgz
fi
wget https://github.com/adafruit/omxplayer/releases/download/2%2F10%2F2015/omxplayer-dist.tgz
tar xvfz omxplayer-dist.tgz -C /
echo "Installing hello_video..."
echo "========================="
git clone https://github.com/adafruit/pi_hello_video.git
cd pi_hello_video
./rebuild.sh
cd hello_video
make install
cd ../..
rm -rf pi_hello_video
echo "Installing video_looper program..."
echo "=================================="
python setup.py install --force
cp video_looper.ini /boot/video_looper.ini
echo "Configuring video_looper to run on start..."
echo "==========================================="
cp video_looper.conf /etc/supervisor/conf.d/
service supervisor restart
echo "Finished!"

8
video_looper.conf Normal file
View File

@ -0,0 +1,8 @@
# Supervisord configuration to run video looper at boot and
# ensure it runs continuously.
[program:video_looper]
command=video_looper
autostart=true
autorestart=unexpected
startsecs=5
stopasgroup=true