-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamrecord.init
executable file
·120 lines (104 loc) · 2.24 KB
/
camrecord.init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
#
# camrecord This shell script takes care of starting and stopping
# camrecord on RedHat or other chkconfig-based system.
#
# chkconfig: 345 98 02
#
# description: camrecord is a robust camera recording application making use of
# ffmpeg, mencoder, and curl.
#
# To install:
# copy this file to /etc/rc.d/init.d/camrecord
# shell> chkconfig --add camrecord
# shell> mkdir /etc/camrecord
# make .conf files in /etc/camrecord (see below)
# To uninstall:
# run: chkconfig --del camrecord
# Location of camrecord binary
camrecord_bin="/usr/bin/camrecord"
# Lock file
lock_file="/var/lock/subsys/camrecord"
# PID directory
pid_dir="/var/run/camrecord"
# Configuration directory
conf_dir=/etc/camrecord
# Source function library.
. /etc/rc.d/init.d/functions
# Check that binary exists
if ! [ -f $camrecord_bin ]
then
echo "camrecord binary not found"
exit 0
fi
# See how we were called.
case "$1" in
start)
echo -n $"Starting camrecord: "
if [ ! -d $pid_dir ]; then
mkdir $pid_dir
fi
if [ -f $lock_file ]; then
# we were not shut down correctly
for pidf in `/bin/ls $pid_dir/*.pid 2>/dev/null`; do
if [ -s $pidf ]; then
kill `cat $pidf` >/dev/null 2>&1
fi
rm -f $pidf
done
rm -f $lock_file
sleep 2
fi
rm -f $pid_dir/*.pid
cd $conf_dir
# Start every .conf in $conf_dir
errors=0
successes=0
for c in `/bin/ls *.conf 2>/dev/null`; do
base_name=${c%%.conf}
rm -f $pid_dir/$base_name.pid
$camrecord_bin --daemon --writepid $pid_dir/$base_name.pid --config $c
if [ $? = 0 ]; then
successes=1
else
errors=1
fi
done
if [ $errors = 1 ]; then
failure; echo
else
success; echo
fi
if [ $successes = 1 ]; then
touch $lock_file
fi
;;
stop)
echo -n $"Shutting down camrecord: "
for pidf in `/bin/ls $pid_dir/*.pid 2>/dev/null`; do
if [ -s $pidf ]; then
kill `cat $pidf` >/dev/null 2>&1
fi
rm -f $pidf
done
success; echo
rm -f $lock_file
;;
restart)
$0 stop
sleep 2
$0 start
;;
condrestart)
if [ -f $lock_file ]; then
$0 stop
sleep 2
$0 start
fi
;;
*)
echo "Usage: camrecord {start|stop|restart|condrestart}"
exit 1
;;
esac
exit 0