Fix prevent issue.
[platform/framework/web/data-provider-master.git] / data / data-provider-master
1 #!/bin/sh
2 #
3 # Copyright 2013  Samsung Electronics Co., Ltd
4 #
5 # Licensed under the Flora License, Version 1.1 (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://floralicense.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                 vconftool set -t bool memory/data-provider-master/started 0 -f
27                 let RETRY_COUNT=$RETRY_COUNT+1
28                 if [ $RETRY_COUNT -gt 5 ]; then
29                         echo "EXCEED THE MAXIMUM RETRY COUNT: $RETRY_COUNT (max 5)"
30                         break;
31                 fi
32         done
33         rm /tmp/.stop.provider
34 }
35
36 start ()
37 {
38         OLDPID=`ps ax | grep /usr/bin/data-provider-master | grep -v grep | awk '{print $1}'`
39         if [ x"$OLDPID" != x"" ]; then
40                 echo $OLDPID is already running.
41                 exit 0
42         fi
43
44         rm /tmp/.stop.provider
45         launch_provider &
46 }
47
48 stop ()
49 {
50         TMP=`which ps`
51         if [ $? -ne 0 ]; then
52                 echo "'ps' is not exists"
53                 exit 0
54         fi
55
56         TMP=`which grep`
57         if [ $? -ne 0 ]; then
58                 echo "'grep' is not exists"
59                 exit 0
60         fi
61
62         TMP=`which awk`
63         if [ $? -ne 0 ]; then
64                 echo "'awk' is not exists"
65                 exit 0
66         fi
67
68         if [ ! -f "/usr/bin/data-provider-master" ]; then
69                 echo "Data provider master is not installed correctly";
70                 exit 0;
71         fi
72
73         touch /tmp/.stop.provider
74         BIN_INODE=`stat -Lc "%i" /usr/bin/data-provider-master`
75
76         PID=`ps ax | grep 'data-provider-master' | awk '{print $1}'`
77         for I in $PID;
78         do
79                 if [ ! -f "/proc/$I/exe" ]; then
80                         continue;
81                 fi
82
83                 INODE=`stat -Lc "%i" /proc/$I/exe 2>/dev/null`
84                 if [ x"$BIN_INODE" == x"$INODE" ]; then
85                         echo "Send TERM to $I"
86                         kill $I # Try to terminate a master which is launched already
87                         break
88                 fi
89         done
90 }
91
92 case "$1" in
93         start|"") start;;
94         stop) stop;;
95         restart) stop; start;;
96 esac
97
98 # End of a file