This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
pmocr-srv
executable file
·147 lines (129 loc) · 2.61 KB
/
pmocr-srv
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env bash
#
# Automatic OCR Service
#
# chkconfig: 35 55 25
# description: monitors a local directory and gives any new file to your favorite OCR engine
# processname: /usr/local/bin/pmocr.sh
# pidfile: /var/run/pmocr
### BEGIN INIT INFO
# Provides: pmocr-srv
# Required-Start: $local_fs $time
# Required-Stop: $local_fs $time
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: pmocr daemon
# Description: OCR wrapper service
### END INIT INFO
prog=pmocr
progexec=pmocr.sh
progpath=/usr/local/bin
confdir=/etc/$prog
pidfile=/var/run/$prog
SCRIPT_BUILD=2018122101
if [ ! -f $progpath/$progexec ] && [ ! -f $progexec ]
then
echo "Cannot find $prog executable in $progpath nor in local path."
exit 1
fi
if [ ! -w $(dirname $pidfile) ]
then
pidfile=./$prog
fi
start() {
if ! ls "$confdir/"*.conf > /dev/null 2>&1; then
echo "Cannot find any configuration files in $confdir."
exit 1
fi
errno=0
for cfgfile in "$confdir"/*.conf
do
if [ -f $progpath/$progexec ]
then
$progpath/$progexec --config=$cfgfile --service > /dev/null 2>&1 &
elif [ -f ./$progexec ]
then
./$progexec --config=$cfgfile --service > /dev/null 2>&1 &
else
echo "Cannot find $prog executable in $progpath"
exit 1
fi
pid=$!
retval=$?
if [ $? == 0 ]
then
echo $pid > "$pidfile-$(basename $cfgfile)"
echo "$prog successfully started for configuration file $cfgfile"
else
echo "Cannot start $prog for configuration file $cfgfile"
errno = 1
fi
done
exit $errno
}
stop() {
if [ ! -f $pidfile-* ]
then
echo "No running $prog instances found."
exit 1
fi
for pfile in $pidfile-*
do
if ps -p$(cat $pfile) > /dev/null 2>&1
then
kill -TERM $(cat $pfile)
if [ $? == 0 ]
then
rm -f $pfile
echo "$prog instance $(basename $pfile) stopped."
else
echo "Cannot stop $prog instance $(basename $pfile)"
fi
else
rm -f $pfile
echo "$prog instance $pfile (pid $(cat $pfile)) is dead but pidfile exists."
fi
done
}
status() {
if [ ! -f $pidfile-* ]
then
echo "Cannot find any running $prog instance."
exit 1
fi
errno=0
for pfile in $pidfile-*
do
if ps -p$(cat $pfile) > /dev/null 2>&1
then
echo "$prog instance $(basename $pfile) is running (pid $(cat $pfile))"
else
echo "$prog instance $pfile (pid $(cat $pfile)) is dead but pidfile exists."
errno=1
fi
done
exit $errno
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
condrestart|try-restart)
status || exit 0
restart
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
;;
esac
exit 0