summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.remote.utils/resources/yocto_tool.sh
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.remote.utils/resources/yocto_tool.sh')
-rwxr-xr-xplugins/org.yocto.remote.utils/resources/yocto_tool.sh125
1 files changed, 125 insertions, 0 deletions
diff --git a/plugins/org.yocto.remote.utils/resources/yocto_tool.sh b/plugins/org.yocto.remote.utils/resources/yocto_tool.sh
new file mode 100755
index 0000000..099e481
--- /dev/null
+++ b/plugins/org.yocto.remote.utils/resources/yocto_tool.sh
@@ -0,0 +1,125 @@
1#!/bin/sh
2
3help ()
4{
5 echo "Usage $0 command [options] application [application argument]"
6 echo "command:"
7 echo " start - start an application"
8 echo " stop - stop an application"
9 echo " restart - restart an application"
10 echo ""
11 echo "options: -d | -l <log file>"
12 echo " -d - start an application as a singleton daemon"
13 echo " -l <log file name> - redirect the standard output/error in the the file"
14 echo " note: Option -d and -l are exclusive to each other"
15 exit 1
16}
17
18killproc() { # kill the named process(es)
19 pid=`/bin/pidof $1`
20 [ "x$pid" != "x" ] && kill $pid
21}
22
23start ()
24{
25 pid=`/bin/pidof $APP`
26 [ "x$pid" != "x" ] && return 0
27
28 if [ "x$DAEMON" != "x" ]; then
29 if [ "x$APPARG" != "x" ]; then
30 start-stop-daemon -S -b --oknodo -x $APP -- $APPARG
31 else
32 start-stop-daemon -S -b --oknodo -x $APP
33 fi
34
35 #wait for sometime for the backend app to bring up & daemonzie
36 ret=$?
37 if [ $ret -eq 0 ]; then
38 sleep 1
39 fi
40 return $ret
41 elif [ "x$LOGFILE" != "x" ]; then
42 $APP $APPARG $>${LOGFILE}
43 else
44 $APP $APPARG
45 fi
46}
47
48stop ()
49{
50 if [ "x$DAEMON" != "x" ]; then
51 start-stop-daemon -K -x $APP
52 else
53 count=0
54 while [ -n "`/bin/pidof $APP`" -a $count -lt 10 ] ; do
55 killproc $APP >& /dev/null
56 sleep 1
57 RETVAL=$?
58 if [ $RETVAL != 0 -o -n "`/bin/pidof $APP`" ] ; then
59 sleep 3
60 fi
61 count=`expr $count + 1`
62 done
63 fi
64}
65
66restart ()
67{
68 stop
69 sleep 1
70 start
71}
72
73#set PATH to include sbin dirs
74export PATH="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
75
76#get command
77case $1 in
78start) CMD=$1; shift 1
79 ;;
80stop) CMD=$1; shift 1
81 ;;
82*) help
83 ;;
84esac
85
86#get options
87while [ $# -gt 0 ]; do
88 case $1 in
89 -d) DAEMON=true; shift 1
90 ;;
91 -l) LOGFILE=$2; shift 2
92 ;;
93 *) break
94 ;;
95 esac
96done
97
98#get application
99APP=$1
100shift 1
101
102#get app argument
103APPARG="$@"
104
105#validate options
106if [ "x$DAEMON" != "x" -a "x$LOGFILE" != "x" ]; then
107 help
108fi
109if [ "x$DAEMON" != "x" ]; then
110 APP=`which $APP`
111fi
112if [ "x$APP" == "x" ]; then
113 help
114fi
115
116#run script
117case $CMD in
118start) start
119 ;;
120stop) stop
121 ;;
122restart)
123 restart
124 ;;
125esac