1 SMF is the way Solaris 10 and later preferably manages services. It is intended
2 to replace the old init.d process and provides advances features, such as
3 automatic restarting of failing services.
5 The following blog entry by Piotr Hosowicz describes the process in more
6 detail. The original entry can be found at
7 <http://phosowicz.jogger.pl/2008/12/21/smf-izing-collectd/>.
9 The files in this directory are:
12 collectd Start / stop script
13 collectd.xml SMF manifest for collectd.
15 ------------------------------------------------------------------------
17 SMF-izing collectd <#>
19 Wpis na 0. poziomie, wysłany 21 grudnia 2008 o 16:30:49.
21 My two previous blog entries were about building and running collectd
22 <http://collectd.org/> on Sun Solaris 10. After the first one Octo
23 contacted me and was so kind as to release a packaged version for x86_64
24 <http://collectd.org/download.shtml#solaris>. I have put aside the build
25 I rolled on my own and decided to install and run the packaged one on
26 the production servers. This blog entry is about SMF-izing the collectd
29 A few words about the SMF – the Solaris'es Service Management Facility.
30 I think it appeared in Solaris 10. From then on the good old |/etc/rcN.d
31 || /etc/init.d| services are called /legacy services/. They still can be
32 run, but are not fully supported by SMF. SMF enables you to start and
33 stop services in the unified way, can direct you to man pages in case a
34 service enters maintenance mode, resolves dependencies between services,
35 can store properties of services and so on. A nice feature is that SMF
36 will take care of restarting services in case they terminate
37 unexpectedly, we will use it at the end to check that things are working
40 The 3V|L thing about SMF is that each service needs so called SMF
41 manifest written in XML and a script or scripts that are executed, when
42 the service needs to be stopped or started. It can be one script, which
43 should accept respective parameters. Even more 3V|L is the fact that the
44 manifest is imported into the SMF database and kept there in SQLite format.
46 Below you will find collectd manifest and the script. I will post them
47 to collectd mailing list in matter of minutes with this blog entry
48 serving as a README. Please read all down to the bottom, including the
51 Manifest (based on the work of Kangurek, thanks!), see the "collectd.xml"
55 <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
57 <service_bundle type='manifest' name='collectd'>
59 name='application/collectd'
63 <create_default_instance enabled='true' />
69 grouping='require_all'
72 <service_fmri value='svc:/milestone/network:default' />
76 name='filesystem-local'
77 grouping='require_all'
80 <service_fmri value='svc:/system/filesystem/local:default' />
86 exec='/lib/svc/method/collectd start'
89 <method_credential user='root' group='root' />
97 exec='/lib/svc/method/collectd stop'
100 <method_credential user='root' group='root' />
104 <stability value='Evolving' />
112 Script, see the "collectd" file:
117 PIDFILE=/opt/collectd/var/run/collectd.pid
118 DAEMON=/opt/collectd/sbin/collectd
120 . /lib/svc/share/smf_include.sh
124 if [ -f $PIDFILE ] ; then
125 echo "Already running. Stale PID file?"
127 echo "$PIDFILE contains $PID"
129 exit $SMF_EXIT_ERR_FATAL
132 if [ $? -ne 0 ] ; then
133 echo $DAEMON faild to start
134 exit $SMF_EXIT_ERR_FATAL
138 PID=`cat $PIDFILE 2>/dev/null`
139 kill -15 $PID 2>/dev/null
140 pwait $PID 1> /dev/null 2>/dev/null
147 ps -ef | grep collectd | grep -v status | grep -v grep
150 echo "Usage: $0 [ start | stop | restart | status ]"
160 So you have two files: |collectd| script and |collectd.xml| manifest.
161 What do you do with these files?
163 First – before you begin – make sure that collectd is not running, close
164 it down. My script above assumes that you are using the default place
165 for PID file. Second: remove / move away collectd's |/etc/rcN.d| and
166 |/etc/init.d| stuff, you won't need it from now on, because collectd
167 will be SMF-ized. Tada!
169 Next – install the script in place. It took me a minute or two to figure
170 out why Solaris'es |install| tool does not work as expected. It turned
171 out that the switches and parameters must be in exactly same order as in
172 man page, especially the -c parameter must be first:
174 |# install -c /lib/svc/method/ -m 755 -u root -g bin collectd|
176 Now is the moment to test once again that the script is working OK. Try
179 |# /lib/svc/method/collectd start
180 # /lib/svc/method/collectd stop
181 # /lib/svc/method/collectd restart
184 |pgrep| and |kill| are your friends here, also collectd logs. At last
185 stop the collectd service and continue.
187 Now is the time to /slurp/ attached XML manifest into the SMF database.
188 This is done using the |svccfg| tool. Transcript follows:
191 svc:> validate collectd.xml
192 svc:> import collectd.xml
196 It is good to run |validate| command first, especially if you copied and
197 pasted the XML manifest from this HTML document opened in your
198 browser!!! Second thing worth noting is that |svccfg| starts the service
199 immediately upon importing the manifest. It might be not what you want.
200 For example it will start collecting data on remote collectd server if
201 you use network plugin and it will do it under the hostname, that is not
202 right. So be sure to configure collectd prior to running it from SMF.
204 Now a few words about SMF tools. To see the state of all services issue
205 |svcs -a| command. To see state of collectd service issue |svcs
206 collectd| command. Quite normal states are enabled and disabled. If you
207 see maintenance state then something is wrong. Be sure that you stopped
208 all non-SMF collectd processes before you follow the procedure described
209 here. To stop collectd the SMF way issue the |svcadm disable
210 collectd|command. To start collectd the SMF way issue the |svcadm enable
211 collectd|command. Be aware that setting it this way makes the change
212 persistent across OS reboots, if you want to enable / disable the
213 service only temporarily then add |-t| switch after the |enable| /
216 And now is time for a grand finale – seeing if SMF can take care of
217 collectd in case it crashes. See PID of collectd either using |pgrep| or
218 seeing the contents of the PID file and kill it using |kill|. Then check
219 with |svcs collectd| command that SMF has restarted collectd soon
220 afterwards. You should see that the service is once again enabled in the
221 first column, without your intervention.
223 Things that could or should be clarified:
225 * How hard is it to correct mistakes in manifests? Does svccfg just
226 overwrite entries for specified service FMRI or does it require to
227 delete bad entry (and how to do it?!) and import the correct one?
228 * How does SMF know that a service has crashed / terminated? I
229 attended Sun's trainings and the trainer didn't know how to
230 explain this, we formed a hypothesis that it watches new PIDs
231 after starting a service or something like that. I think it is a
232 bad hypothesis, because SMF can watch PID for the startup script
233 itself but I think not the processes launched inside the script. I
234 have a slight idea that it is done based on so called contracts.
236 ------------------------------------------------------------------------
239 Komentarze do notki “SMF-izing collectd” <#comments>
246 ------------------------------------------------------------------------
251 * Grudzień 2008 (5) </2008/12/>
252 * Październik 2008 (4) </2008/10/>
253 * Wrzesień 2008 (7) </2008/09/>
254 * Sierpień 2008 (5) </2008/08/>
255 * Lipiec 2008 (12) </2008/07/>
256 * Czerwiec 2008 (11) </2008/06/>
257 * Maj 2008 (3) </2008/05/>
258 * Kwiecień 2008 (10) </2008/04/>
259 * Marzec 2008 (3) </2008/03/>
260 * Luty 2008 (1) </2008/02/>
261 * Styczeń 2008 (1) </2008/01/>
262 * Listopad 2007 (4) </2007/11/>
263 * Październik 2007 (6) </2007/10/>
264 * Wrzesień 2007 (10) </2007/09/>
265 * Sierpień 2007 (3) </2007/08/>
266 * Lipiec 2007 (8) </2007/07/>
267 * Czerwiec 2007 (10) </2007/06/>
268 * Maj 2007 (12) </2007/05/>
269 * Kwiecień 2007 (17) </2007/04/>
274 * Film (8) <http://phosowicz.jogger.pl/kategoria/film/>
275 * Książki (35) <http://phosowicz.jogger.pl/kategoria/ksiazki/>
276 * Muzyka (15) <http://phosowicz.jogger.pl/kategoria/muzyka/>
277 * Ogólne (20) <http://phosowicz.jogger.pl/kategoria/ogolne/>
278 * Polityka (59) <http://phosowicz.jogger.pl/kategoria/polityka/>
279 * Sprzedam (5) <http://phosowicz.jogger.pl/kategoria/sprzedam/>
280 * Techblog (20) <http://phosowicz.jogger.pl/kategoria/techblog/>
281 * Technikalia (34) <http://phosowicz.jogger.pl/kategoria/technikalia/>
282 * Wystawy (3) <http://phosowicz.jogger.pl/kategoria/wystawy/>
287 * ArsTechnica.com <http://arstechnica.com/>
288 * Fund. Orientacja <http://www.abcnet.com.pl/>
289 * Techblog Jogger'a <http://techblog.pl/>
290 * The Register <http://www.theregister.co.uk/>
295 * Bloody.Users <http://bloody.users.jogger.pl/>
296 * Dandys <http://dandys.jogger.pl/>
297 * Derin <http://derin.jogger.pl>
298 * Kefir87 <http://kefir87.jogger.pl/>
299 * Klisu <http://klisu.jogger.pl/>
300 * Kwantowe Krajobrazy <http://kwantowekrajobrazy.jogger.pl/>
301 * Paczor <http://paczor.fubar.pl/>
302 * Prestidigitator <http://prestidigitator.jogger.pl>
303 * Remiq <http://remiq.jogger.pl>
304 * Torero <http://torero.jogger.pl/>
305 * Zdzichubg <http://zdzichubg.jogger.pl/>
310 * www.delphi.org.pl <http://www.delphi.org.pl>
311 * www.hosowicz.com <http://www.hosowicz.com>
316 * Nakarm dzieci! <http://pajacyk.pl/>
321 * Panel administracyjny <https://login.jogger.pl/>
324 ------------------------------------------------------------------------
326 phosowicz is powered by Jogger <http://jogger.pl> and K2
327 <http://binarybonsai.com/k2/> by Michael <http://binarybonsai.com> and
328 Chris <http://chrisjdavis.org>, ported by Patryk Zawadzki.
329 <http://patrys.jogger.pl/>
330 Notki w RSS <http://phosowicz.jogger.pl/rss/content/html/20>