Gentoo Archives: gentoo-user

From: Bruce NCNP <aaniao002@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Is this a bug of runscript? (status will not turn to started)
Date: Mon, 10 May 2010 22:29:36
Message-Id: AANLkTinIomDY7zsVkwi2FxGuPItzpFTiLibFvy_oSz-0@mail.gmail.com
1 hi, all, i had write a #!/sbin/runscript script, but status will not turn to
2 "started", is there some error in this script or this is a bug?
3 THX all of you.
4
5
6
7 source code first (i want to start a bash script with runscript):
8 +---------------------------------------------------------------------------------------------------------------------------------------
9 | #!/sbin/runscript
10 | #file name: test
11 | .....<in start() {>
12 | start-stop-daemon -S -p "${PIDFILE}" -m -b -a "${EXECFILE}" --
13 --Pidfile "${PIDFILE}"
14 | .....
15 +---------------------------------------------------------------------------------------------------------------------------------------
16 sudo ./test start
17 * Starting Test ... [ ok ]
18 sudo ./test start
19 * Starting Test ...
20 process already running.
21 sudo ./test stop
22 * WARNING: test has not yet been started.
23 sudo ./test status
24 * status: stopped
25 but the bash script is running, and the $PIDFILE had filled with correct pid
26 number, so ,i can;t stop it with runscript.
27
28
29
30 in another way to write this script, but use bash this time, it totaly OK.
31
32
33
34 [FULL source code of these scripts]
35 +---------------------------------------------------------------------------------------------------------------------------------------
36 |
37 | #file name: test
38 | #!/sbin/runscript
39 | PIDFILE=/tmp/runsc/pid/test.pid
40 | EXECFILE=/tmp/runsc/testbash1
41 |
42 | depend() {
43 | need net
44 | }
45 |
46 | start() {
47 | ebegin "Starting Test"
48 | start-stop-daemon -S -p "${PIDFILE}" -m -b -a "${EXECFILE}" --
49 --Pidfile
50 "${PIDFILE}"
51
52 | eend
53 $?
54 | #return
55 0
56 |
57 }
58
59 |
60 | stop() {
61 | echo "stop daemon"
62 | ebegin "Stopping Test"
63 | start-stop-daemon -K -p "${PIDFILE}" -a "${EXECFILE}"
64 | #cat "${PIDFILE}" | xargs -i kill '{}'
65 | eend $?
66 |
67 | }
68 |
69 | status() {
70 | if [ -a "${PIDFILE}" ]; then
71 | echo "exit file"
72 | return 0;
73 | else
74 | echo "not exit file"
75 | return 1;
76 | fi
77 | }
78 |
79 +---------------------------------------------------------------------------------------------------------------------------------------
80 |
81 | #file name: test.sh
82 |
83 #!/bin/bash
84
85 |
86 PIDFILE=/tmp/runsc/pid/test.pid
87
88 |
89 EXECFILE=/tmp/runsc/testbash1
90
91 |
92
93 | start()
94 {
95 | echo "Starting
96 Test"
97 | echo start-stop-daemon -S -p "${PIDFILE}" -m -b -a "${EXECFILE}" --
98 --Pidfile
99 "${PIDFILE}"
100 | #return
101 0
102 |
103 }
104
105 |
106
107 | stop()
108 {
109 | echo "stop
110 daemon"
111 | echo "Stopping
112 Test"
113 | #start-stop-daemon -K -o -p
114 "${PIDFILE}"
115 | cat "${PIDFILE}" | xargs -i kill
116 '{}'
117 |
118 }
119
120 |
121
122 | status()
123 {
124 | if [ -a "${PIDFILE}" ];
125 then
126 | echo "exit
127 file"
128 | return
129 0;
130 |
131 else
132 | echo "not exit
133 file"
134 | return 1;
135 | fi
136 | }
137 |
138 | case "$1" in
139 | start)
140 | start
141 | ;;
142 | stop)
143 | stop
144 | ;;
145 | status)
146 | status
147 | ;;
148 | *)
149 | echo "Usage: $0 {start|stop|restart|force-reload|make}" >&2
150 | exit 1
151 | ;;
152 | esac
153 |
154 +---------------------------------------------------------------------------------------------------------------------------------------
155 |
156 | #file name: testbash1
157 | #!/bin/bash
158 | while true; do
159 | #echo '$pid_file='$pid_file
160 | echo "a" >> /tmp/runsc/pid/output.log; sleep 1
161 | echo "aa" >> /tmp/runsc/pid/output.log; sleep 1
162 | echo "aaa" >> /tmp/runsc/pid/output.log; sleep 1
163 | echo "aaaa" >> /tmp/runsc/pid/output.log; sleep 1
164 | echo "aaaaa" >> /tmp/runsc/pid/output.log; sleep 1
165 | done
166 |
167 +---------------------------------------------------------------------------------------------------------------------------------------