diff options
author | Tudor Florea <tudor.florea@enea.com> | 2014-10-10 03:49:30 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2014-10-10 03:49:30 +0200 |
commit | ede215cf93ba81c963ae62d665d0f32c9407551c (patch) | |
tree | 4a6dc80f259bccb8ff8b76d31e6cc8794bd97a2b /plugins/org.yocto.remote.utils/resources/yocto_tool.sh | |
download | eclipse-poky-kepler-daisy-140929.tar.gz |
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'plugins/org.yocto.remote.utils/resources/yocto_tool.sh')
-rwxr-xr-x | plugins/org.yocto.remote.utils/resources/yocto_tool.sh | 125 |
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 | |||
3 | help () | ||
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 | |||
18 | killproc() { # kill the named process(es) | ||
19 | pid=`/bin/pidof $1` | ||
20 | [ "x$pid" != "x" ] && kill $pid | ||
21 | } | ||
22 | |||
23 | start () | ||
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 | |||
48 | stop () | ||
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 | |||
66 | restart () | ||
67 | { | ||
68 | stop | ||
69 | sleep 1 | ||
70 | start | ||
71 | } | ||
72 | |||
73 | #set PATH to include sbin dirs | ||
74 | export PATH="$PATH:/usr/local/sbin:/usr/sbin:/sbin" | ||
75 | |||
76 | #get command | ||
77 | case $1 in | ||
78 | start) CMD=$1; shift 1 | ||
79 | ;; | ||
80 | stop) CMD=$1; shift 1 | ||
81 | ;; | ||
82 | *) help | ||
83 | ;; | ||
84 | esac | ||
85 | |||
86 | #get options | ||
87 | while [ $# -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 | ||
96 | done | ||
97 | |||
98 | #get application | ||
99 | APP=$1 | ||
100 | shift 1 | ||
101 | |||
102 | #get app argument | ||
103 | APPARG="$@" | ||
104 | |||
105 | #validate options | ||
106 | if [ "x$DAEMON" != "x" -a "x$LOGFILE" != "x" ]; then | ||
107 | help | ||
108 | fi | ||
109 | if [ "x$DAEMON" != "x" ]; then | ||
110 | APP=`which $APP` | ||
111 | fi | ||
112 | if [ "x$APP" == "x" ]; then | ||
113 | help | ||
114 | fi | ||
115 | |||
116 | #run script | ||
117 | case $CMD in | ||
118 | start) start | ||
119 | ;; | ||
120 | stop) stop | ||
121 | ;; | ||
122 | restart) | ||
123 | restart | ||
124 | ;; | ||
125 | esac | ||