/[polypkg]/trunk/pp.back.solaris.svc
ViewVC logotype

Contents of /trunk/pp.back.solaris.svc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 229 - (show annotations)
Tue Oct 27 20:24:32 2009 UTC (3 weeks, 4 days ago) by rcweb
File size: 7762 byte(s)
Solaris no /etc/rc?.d/*quest-sshd fix, and label the HP packages a little better. 
1 # http://www.sun.com/bigadmin/content/selfheal/sdev_intro.html
2 # http://opensolaris.org/os/community/smf/faq
3
4 #@ pp_backend_solaris_init_svc_vars(): initialise service var defaults
5 pp_backend_solaris_init_svc_vars () {
6 pp_solaris_smf_category=
7 pp_solaris_service_shell=/sbin/sh
8 }
9
10 #@ pp_solaris_init_svc(): initialise solaris backend vars for services
11 pp_solaris_init_svc () {
12 smf_category=${pp_solaris_smf_category:-application}
13 smf_version=1
14 smf_type=service
15 solaris_user=
16 solaris_stop_signal=
17 solaris_sysv_init_start=S98 # invocation order for start scripts
18 solaris_sysv_init_kill=K30 # invocation order for kill scripts
19 solaris_sysv_init_start_states="2" # states to install start link
20 solaris_sysv_init_kill_states="S 0 1" # states to install kill link
21
22 #
23 # To have the service be installed to start automatically,
24 # %service foo
25 # solaris_sysv_init_start_states="S 0 1 2"
26 #
27 }
28
29 #@ pp_solaris_smf(svc): create an service file
30 # -- FIXME: incomplete
31 pp_solaris_smf () {
32 typeset f
33 f=/var/svc/manifest/$smf_category/$1
34 pp_add_file_if_missing $f ||
35 return 0
36
37 cat <<-. >$pp_destdir$f
38 <?xml version="1.0"?>
39 <!--
40 $copyright
41 Generated by PolyPackage $pp_version
42 -->
43
44 <service name='$smf_category/$1'
45 type='$smf_type'
46 version='$smf_version'>
47
48 <single_instance />
49
50 <exec_method type='method' name='start'
51 exec=''
52 timeout_seconds='60'>
53 <method_context>
54 <method_credential user='${solaris_user:-$user}' />
55 </method_context>
56 </exec>
57
58 <exec_method type='method' name='stop'
59 exec=':kill -${solaris_stop_signal:-$stop_signal}'>
60 <method_context>
61 <method_credential user='${solaris_user:-$user}' />
62 </method_context>
63 </exec>
64
65 </service>
66 .
67 }
68
69 #@ pp_solaris_make_service_group (group svcs): create a SysV service group
70 # script and adds it to %files.run if not there already
71 pp_solaris_make_service_group () {
72 typeset group out file svcs svc
73
74 group="$1"
75 svcs="$2"
76 file="/etc/init.d/$group"
77 out="$pp_destdir$file"
78
79 #-- return if the script is supplued already
80 pp_add_file_if_missing "$file" run 755 || return 0
81
82 echo "#! /sbin/sh" > $out
83 echo "# polypkg service group script for these services:" >> $out
84 echo "svcs=\"$svcs\"" >> $out
85
86 cat <<'.' >>$out
87
88 #-- starts services in order.. stops them all if any break
89 pp_start () {
90 undo=
91 for svc in $svcs; do
92 if /etc/init.d/$svc start; then
93 undo="$svc $undo"
94 else
95 if test -n "$undo"; then
96 for svc in $undo; do
97 /etc/init.d/$svc stop
98 done
99 return 1
100 fi
101 fi
102 done
103 return 0
104 }
105
106 #-- stops services in reverse
107 pp_stop () {
108 reverse=
109 for svc in $svcs; do
110 reverse="$svc $reverse"
111 done
112 rc=0
113 for svc in $reverse; do
114 /etc/init.d/$svc stop || rc=$?
115 done
116 return $rc
117 }
118
119 #-- returns true only if all services return true status
120 pp_status () {
121 rc=0
122 for svc in $svcs; do
123 /etc/init.d/$svc status || rc=$?
124 done
125 return $rc
126 }
127
128 case "$1" in
129 start) pp_start;;
130 stop) pp_stop;;
131 status) pp_status;;
132 restart) pp_stop && pp_start;;
133 *) echo "usage: $0 {start|stop|restart|status}" >&2; exit 1;;
134 esac
135 .
136 }
137
138
139 #@ pp_solaris_make_service (svc): create a SysV service script
140 # creates and adds the file /etc/init.d/$svc to %files.run if
141 # it isn't there already.
142 pp_solaris_make_service () {
143 typeset file out _cmd svc
144
145 svc="$1"
146 file="/etc/init.d/$svc"
147 out="$pp_destdir$file"
148
149
150 #-- return if we don't need to create the init script
151 pp_add_file_if_missing "$file" run 755 ||
152 return 0
153
154 echo "#! /sbin/sh" >$out
155 echo "#-- This service init file generated by polypkg" >>$out
156
157 #-- construct a start command that builds a pid file as needed
158 # and forks the daemon
159 _cmd="$cmd";
160 if test -z "$pidfile"; then
161 # The service does not define a pidfile, so we have to make
162 # our own up. On Solaris systems where there is no /var/run
163 # we must use /tmp to guarantee the pid files are removed after
164 # a system crash.
165 cat <<. >>$out
166 pp_piddir="/var/run"
167 test -d "\$pp_piddir/." || pp_piddir="/tmp"
168 pidfile="\$pp_piddir/$svc.pid"
169 .
170 _cmd="$cmd & echo \$! > \$pidfile"
171 else
172 # The service is able to write its own PID file
173 cat <<. >>$out
174 pidfile="$pidfile"
175 .
176 fi
177
178 if test "${user:-root}" != "root"; then
179 _cmd="su $user -c exec $_cmd";
180 fi
181
182 cat <<. >>$out
183 stop_signal="${stop_signal:-TERM}"
184 svc="${svc}"
185
186 # generated command to run $svc as a daemon process
187 pp_exec () { $_cmd; }
188 .
189
190 #-- write the invariant section of the init script
191 cat <<'.' >>$out
192
193 # returns true if $svc is running
194 pp_running () {
195 test -r "$pidfile" &&
196 read pid junk < "$pidfile" &&
197 test ${pid:-0} -gt 1 &&
198 kill -0 "$pid" 2>/dev/null
199 }
200
201 # prints a message describing $svc's running state
202 pp_status () {
203 if pp_running; then
204 echo "service $svc is running (pid $pid)"
205 return 0
206 elif test -f "$pidfile"; then
207 echo "service $svc is not running, but pid file exists"
208 return 2
209 else
210 echo "service $svc is not running"
211 return 1
212 fi
213 }
214
215 # starts $svc
216 pp_start () {
217 if pp_running; then
218 echo "service $svc already running" >&2
219 return 0
220 fi
221 echo "starting $svc... \c"
222 if pp_exec; then
223 echo "done."
224 else
225 echo "ERROR."
226 exit 1
227 fi
228 }
229
230 # stops $svc
231 pp_stop () {
232 if pp_running; then
233 echo "stopping $svc... \c"
234 if kill -$stop_signal $pid; then
235 rm -f "$pidfile"
236 echo "done."
237 else
238 echo "ERROR."
239 return 1
240 fi
241 else
242 echo "service $svc already stopped" >&2
243 return 0
244 fi
245 }
246
247 umask 022
248 case "$1" in
249 start) pp_start;;
250 stop) pp_stop;;
251 status) pp_status;;
252 restart) pp_stop && pp_start;;
253 *) echo "usage: $0 {start|stop|restart|status}" >&2; exit 1;;
254 esac
255 .
256 }
257
258
259 #@ pp_solaris_install_service($svc): generate commands to install svc
260 # output is intended to go to postinstall
261 pp_solaris_install_service () {
262 typeset s k l
263 s="${solaris_sysv_init_start}$1"
264 k="${solaris_sysv_init_kill}$1"
265
266 # echo 'case " $SERVICES " in *" '$1' "*)'
267 test -n "${solaris_sysv_init_start_states}" &&
268 for state in ${solaris_sysv_init_start_states}; do
269 l="/etc/rc$state.d/$s"
270 echo "echo '$l'"
271 echo "installf -c run \$PKGINST \$PKG_INSTALL_ROOT$l=../init.d/$1 s"
272 pp_solaris_space /etc/rc$state.d 0 1
273 done
274 test -n "${solaris_sysv_init_kill_states}" &&
275 for state in ${solaris_sysv_init_kill_states}; do
276 l="/etc/rc$state.d/$k"
277 echo "echo '$l'"
278 echo "installf -c run \$PKGINST \$PKG_INSTALL_ROOT$l=../init.d/$1 s"
279 pp_solaris_space /etc/rc$state.d 0 1
280 done
281 # echo " :;; esac"
282
283 }

Ted.Percival@quest.com
ViewVC Help
Powered by ViewVC 1.1.2