Initialize the project.
[apps/livebox/data-provider-master.git] / data / data-provider-master
1 #!/bin/sh
2 #
3 # Copyright 2012  Samsung Electronics Co., Ltd
4 #
5 # Licensed under the Flora License, Version 1.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.tizenopensource.org/license
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 launch_provider()
19 {
20         RETRY_COUNT=0
21         while [ ! -f "/tmp/.stop.provider" ]; do
22                 # PROVIDER_HEAP_MONITOR_START=false
23                 # PROVIDER_DISABLE_CALL_OPTION=false
24                 # PROVIDER_METHOD="shm", "pixmap", "file" (default = "file")
25                 BUFMGR_LOCK_TYPE="once" BUFMGR_MAP_CACHE="true" /usr/bin/data-provider-master
26                 let RETRY_COUNT=$RETRY_COUNT+1
27                 if [ $RETRY_COUNT -gt 5 ]; then
28                         echo "EXCEED THE MAXIMUM RETRY COUNT: $RETRY_COUNT (max 5)"
29                         break;
30                 fi
31         done
32         rm /tmp/.stop.provider
33 }
34
35 start ()
36 {
37         rm /opt/usr/share/live_magazine/*
38         rm /opt/usr/share/live_magazine/reader/*
39         rm /opt/usr/share/live_magazine/log/*
40         rm /tmp/.stop.provider
41         launch_provider &
42 }
43
44 stop ()
45 {
46         TMP=`which ps`
47         if [ $? -ne 0 ]; then
48                 echo "'ps' is not exists"
49                 exit 0
50         fi
51
52         TMP=`which grep`
53         if [ $? -ne 0 ]; then
54                 echo "'grep' is not exists"
55                 exit 0
56         fi
57
58         TMP=`which awk`
59         if [ $? -ne 0 ]; then
60                 echo "'awk' is not exists"
61                 exit 0
62         fi
63
64         if [ ! -f "/usr/bin/data-provider-master" ]; then
65                 echo "Data provider master is not installed correctly";
66                 exit 0;
67         fi
68
69         touch /tmp/.stop.provider
70         BIN_INODE=`stat -Lc "%i" /usr/bin/data-provider-master`
71
72         PID=`ps ax | grep 'data-provider-master' | awk '{print $1}'`
73         for I in $PID;
74         do
75                 if [ ! -f "/proc/$I/exe" ]; then
76                         continue;
77                 fi
78
79                 INODE=`stat -Lc "%i" /proc/$I/exe 2>/dev/null`
80                 if [ x"$BIN_INODE" == x"$INODE" ]; then
81                         echo "Send TERM to $I"
82                         kill $I # Try to terminate a master which is launched already
83                         break
84                 fi
85         done
86 }
87
88 case "$1" in
89         start|"") start;;
90         stop) stop;;
91         restart) stop; start;;
92 esac
93
94 # End of a file