Last active
August 29, 2015 13:58
-
-
Save rmamba/10130375 to your computer and use it in GitHub Desktop.
Timelapse daemon for RaspberryPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: webcam | |
# Required-Start: $remote_fs $syslog | |
# Required-Stop: $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Control raspistill | |
# Description: Control raspistill camera time lapse | |
# and save images to RAM disk. | |
# Source: http://www.dronkert.net/rpi/webcam.html | |
### END INIT INFO | |
BIN="raspistill" | |
EXE="/usr/bin/$BIN" | |
[ -x "$EXE" ] || exit 0 | |
SCR="timelapsed" # script / service name | |
# -ts paramater replaces the frame number with timestamp value when creating file | |
ARG="-n -t 0 -tl 5000 -ts -o /run/shm/tl%010d.jpg" | |
LCK="/var/run/$SCR.pid" # lock file location | |
update_lockfile() { | |
PID=$(pgrep "$BIN") | |
if [ -z "$PID" ]; then | |
[ -f "$LCK" ] && [ -w "$LCK" ] && rm -f "$LCK" | |
else | |
[ -e "$LCK" ] || touch "$LCK" | |
[ -f "$LCK" ] && [ -w "$LCK" ] && echo "$PID" > "$LCK" | |
fi | |
} | |
do_start() { | |
$EXE $ARG & | |
update_lockfile | |
} | |
do_stop() { | |
killall -q "$BIN" | |
update_lockfile | |
} | |
case "$1" in | |
status) | |
echo -n "Service $SCR is " | |
update_lockfile | |
if [ -z "$PID" ]; then | |
echo "not running." >&2 | |
exit 3 | |
else | |
echo "running." | |
fi | |
;; | |
start) | |
echo -n "Starting service $SCR..." | |
update_lockfile | |
if [ -n "$PID" ]; then | |
echo "already started." >&2 | |
exit 4 | |
else | |
do_start | |
echo "done." | |
fi | |
;; | |
stop) | |
echo -n "Stopping service $SCR..." | |
update_lockfile | |
if [ -z "$PID" ]; then | |
echo "already stopped." >&2 | |
exit 5 | |
else | |
do_stop | |
echo "done." | |
fi | |
;; | |
restart|force-reload) | |
echo -n "Restarting service $SCR..." | |
do_stop | |
if [ -n "$PID" ]; then | |
echo "failed to stop." >&2 | |
exit 6 | |
else | |
do_start | |
if [ -z "$PID" ]; then | |
echo "failed to start." >&2 | |
exit 7 | |
else | |
echo "done." | |
fi | |
fi | |
;; | |
*) | |
echo "Usage: $0 {status|start|stop|restart|force-reload}" >&2 | |
exit 8 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment