| 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. |
| 4 |
|
| 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/>. |
| 8 |
|
| 9 |
The files in this directory are: |
| 10 |
|
| 11 |
README This file |
| 12 |
collectd Start / stop script |
| 13 |
collectd.xml SMF manifest for collectd. |
| 14 |
|
| 15 |
------------------------------------------------------------------------ |
| 16 |
|
| 17 |
SMF-izing collectd <#> |
| 18 |
|
| 19 |
Wpis na 0. poziomie, wysłany 21 grudnia 2008 o 16:30:49. |
| 20 |
|
| 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 |
| 27 |
daemon. |
| 28 |
|
| 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 |
| 38 |
as they should. |
| 39 |
|
| 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. |
| 45 |
|
| 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 |
| 49 |
remarks. |
| 50 |
|
| 51 |
Manifest (based on the work of Kangurek, thanks!), see the "collectd.xml" |
| 52 |
file: |
| 53 |
|
| 54 |
<?xml version="1.0"?> |
| 55 |
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> |
| 56 |
|
| 57 |
<service_bundle type='manifest' name='collectd'> |
| 58 |
<service |
| 59 |
name='application/collectd' |
| 60 |
type='service' |
| 61 |
version='1'> |
| 62 |
|
| 63 |
<create_default_instance enabled='true' /> |
| 64 |
|
| 65 |
<single_instance/> |
| 66 |
|
| 67 |
<dependency |
| 68 |
name='network' |
| 69 |
grouping='require_all' |
| 70 |
restart_on='none' |
| 71 |
type='service'> |
| 72 |
<service_fmri value='svc:/milestone/network:default' /> |
| 73 |
</dependency> |
| 74 |
|
| 75 |
<dependency |
| 76 |
name='filesystem-local' |
| 77 |
grouping='require_all' |
| 78 |
restart_on='none' |
| 79 |
type='service'> |
| 80 |
<service_fmri value='svc:/system/filesystem/local:default' /> |
| 81 |
</dependency> |
| 82 |
|
| 83 |
<exec_method |
| 84 |
type='method' |
| 85 |
name='start' |
| 86 |
exec='/lib/svc/method/collectd start' |
| 87 |
timeout_seconds='60'> |
| 88 |
<method_context> |
| 89 |
<method_credential user='root' group='root' /> |
| 90 |
</method_context> |
| 91 |
</exec_method> |
| 92 |
|
| 93 |
|
| 94 |
<exec_method |
| 95 |
type='method' |
| 96 |
name='stop' |
| 97 |
exec='/lib/svc/method/collectd stop' |
| 98 |
timeout_seconds='60'> |
| 99 |
<method_context> |
| 100 |
<method_credential user='root' group='root' /> |
| 101 |
</method_context> |
| 102 |
</exec_method> |
| 103 |
|
| 104 |
<stability value='Evolving' /> |
| 105 |
|
| 106 |
</service> |
| 107 |
|
| 108 |
</service_bundle> |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
Script, see the "collectd" file: |
| 113 |
|
| 114 |
|
| 115 |
#!/sbin/sh |
| 116 |
|
| 117 |
PIDFILE=/opt/collectd/var/run/collectd.pid |
| 118 |
DAEMON=/opt/collectd/sbin/collectd |
| 119 |
|
| 120 |
. /lib/svc/share/smf_include.sh |
| 121 |
|
| 122 |
case "$1" in |
| 123 |
start) |
| 124 |
if [ -f $PIDFILE ] ; then |
| 125 |
echo "Already running. Stale PID file?" |
| 126 |
PID=`cat $PIDFILE` |
| 127 |
echo "$PIDFILE contains $PID" |
| 128 |
ps -p $PID |
| 129 |
exit $SMF_EXIT_ERR_FATAL |
| 130 |
fi |
| 131 |
$DAEMON |
| 132 |
if [ $? -ne 0 ] ; then |
| 133 |
echo $DAEMON faild to start |
| 134 |
exit $SMF_EXIT_ERR_FATAL |
| 135 |
fi |
| 136 |
;; |
| 137 |
stop) |
| 138 |
PID=`cat $PIDFILE 2>/dev/null` |
| 139 |
kill -15 $PID 2>/dev/null |
| 140 |
pwait $PID 1> /dev/null 2>/dev/null |
| 141 |
;; |
| 142 |
restart) |
| 143 |
$0 stop |
| 144 |
$0 start |
| 145 |
;; |
| 146 |
status) |
| 147 |
ps -ef | grep collectd | grep -v status | grep -v grep |
| 148 |
;; |
| 149 |
*) |
| 150 |
echo "Usage: $0 [ start | stop | restart | status ]" |
| 151 |
exit 1 |
| 152 |
;; |
| 153 |
esac |
| 154 |
|
| 155 |
|
| 156 |
exit $SMF_EXIT_OK |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
So you have two files: |collectd| script and |collectd.xml| manifest. |
| 161 |
What do you do with these files? |
| 162 |
|
| 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! |
| 168 |
|
| 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: |
| 173 |
|
| 174 |
|# install -c /lib/svc/method/ -m 755 -u root -g bin collectd| |
| 175 |
|
| 176 |
Now is the moment to test once again that the script is working OK. Try |
| 177 |
running: |
| 178 |
|
| 179 |
|# /lib/svc/method/collectd start |
| 180 |
# /lib/svc/method/collectd stop |
| 181 |
# /lib/svc/method/collectd restart |
| 182 |
| |
| 183 |
|
| 184 |
|pgrep| and |kill| are your friends here, also collectd logs. At last |
| 185 |
stop the collectd service and continue. |
| 186 |
|
| 187 |
Now is the time to /slurp/ attached XML manifest into the SMF database. |
| 188 |
This is done using the |svccfg| tool. Transcript follows: |
| 189 |
|
| 190 |
|# svccfg |
| 191 |
svc:> validate collectd.xml |
| 192 |
svc:> import collectd.xml |
| 193 |
svc:> |
| 194 |
| |
| 195 |
|
| 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. |
| 203 |
|
| 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| / |
| 214 |
|disable| keywords. |
| 215 |
|
| 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. |
| 222 |
|
| 223 |
Things that could or should be clarified: |
| 224 |
|
| 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. |
| 235 |
|
| 236 |
------------------------------------------------------------------------ |
| 237 |
|
| 238 |
|
| 239 |
Komentarze do notki “SMF-izing collectd” <#comments> |
| 240 |
|
| 241 |
|
| 242 |
Zostaw odpowiedź |
| 243 |
|
| 244 |
Nick |
| 245 |
|
| 246 |
------------------------------------------------------------------------ |
| 247 |
|
| 248 |
|
| 249 |
Archiwum |
| 250 |
|
| 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/> |
| 270 |
|
| 271 |
|
| 272 |
Kategorie |
| 273 |
|
| 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/> |
| 283 |
|
| 284 |
|
| 285 |
Czytuję |
| 286 |
|
| 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/> |
| 291 |
|
| 292 |
|
| 293 |
Inne blogi |
| 294 |
|
| 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/> |
| 306 |
|
| 307 |
|
| 308 |
Inne moje strony |
| 309 |
|
| 310 |
* www.delphi.org.pl <http://www.delphi.org.pl> |
| 311 |
* www.hosowicz.com <http://www.hosowicz.com> |
| 312 |
|
| 313 |
|
| 314 |
Pajacyk.pl |
| 315 |
|
| 316 |
* Nakarm dzieci! <http://pajacyk.pl/> |
| 317 |
|
| 318 |
|
| 319 |
Meta |
| 320 |
|
| 321 |
* Panel administracyjny <https://login.jogger.pl/> |
| 322 |
|
| 323 |
|
| 324 |
------------------------------------------------------------------------ |
| 325 |
|
| 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> |
| 331 |
|