Kommandozeilenparameter eines laufenden Prozesses ausgeben

Stehe öfters mal vor der „Aufgabe“, das ich wissen möchte, mit exakt welchen Parametern ein Prozess gestartet wurde. Teilweise ist das zu „breit“ für eine „ps“ Ausgabe — besonders gerne bei Java Prozessen…

Weiterlesen

Leere Verzeichnisse auf *nix finden — portabel

Stand vorhin vor dem Problem, das ich auf Solaris alle leeren Verzeichnisse und leeren Dateien unterhalb eines Verzeichnisses finden wollte.

Auf Linux, bzw. genauer gesagt: mit GNU Tools und deren findutils, hätte ich dafür die Option „-empty“ von find(1) verwendet. Aus der Dokumentation:

[…]
— Test: -empty

True if the file is empty and is either a regular file or a directory. This might help determine good candidates for deletion. This test is useful with ‘-depth’ (see Directories) and ‘-delete’ (see Single File).

[…]

Aber, wie gesagt, ich war auf Solaris, bzw. genauer gesagt: ich hatte die GNU findutils nicht zur Verfügung und konnte sie auch nicht nachinstallieren… Also musste eine bessere (read: portable) Lösung her 🙂

Und die lautet:

find $DIR '(' -type d -links 2 \) -o -size 0

Dh. man lasse find nach Verzeichnissen („-type d“) suchen, in denen GENAU nur 2 „Links“ („-links 2“) sind — das sind alle die Verzeichnisse, die leer sind.
Und es sollen auch sonst alle „Einträge“ gefunden werden, die eine Grösse von 0 („-size 0“) habe — das sind alle leeren Dateien.

Dh. die Option „-empty“ von GNU find ist genau identisch zu der portablen Optionskombination „‚(‚ -type d -links 2 \) -o -size 0„.

Das zeigt exemplarisch auch wunderschön, was so schlecht ist an dem GNU Toolset – unnötige Optionen… Klar, ein „-empty“ ist schneller getippt als „‚(‚ -type d -links 2 \) -o -size 0„, aber dafür ist letzteres überall brauchbar. Wenn in der GNU Dokumentation wenigstens stünde, das beides identisch ist, dann wäre es ja vlt. noch gut. Oder wenn notiert wäre, das „-empty“ nur bei GNU find existiert und nicht im POSIX Standard steht… Da dem aber so nicht ist, ist „-empty“ schlecht.

Festplatte bei Solaris 10 x86 austauschen

Folgendes ist zu tun, wenn man auf einem Solaris 10 x86 (Intel) System eine Platte austauschen will, die bei ZFS verwendet wird, z.B. weil die Platte defekt ist.
  1. Im zpool die defekte Platte „offline“ nehmen
    • zpool offline pool c0t5d0s0
  2. VTOC der defekten Platte speichern:
    • prtvtoc /dev/rdsk/c0t5d0s2 > /c0t5d0.vtoc
  3. Platte aus der Solaris Konfiguration entfernen
    • cfgadm -c unconfigure c0::dsk/c0t5d0
  4. Defekte Platte entfernen
  5. Neue Platte einstecken
  6. Mit dmesg überprüfen, ob neue Platte von alleine gefunden wurde
    • Wenn nicht:
      • cfgadm -c configure c0::dsk/c0t5d0
    • Oder:
      • cfgadm -al > /cfgadm-al.0
      • devfsadm -c disk
      • cfgadm -al > /cfgadm-al.1
      • diff -u /cfgadm-al.0 /cfgadm-al.1
        • Notiz von Devicenamen der neuen Platte machen
    • Oder, falls nichts von dem hilft:
      • Rechner rebooten
      • cfgadm -c configure c0::dsk/c0t5d0
  7. Bestehende VTOC von defekter Platte übertragen:
    • fmthard -s /c0t5d0.vtoc /dev/rdsk/c0t5d0s2
  8. Im zpool die Platte austauschen:
    • zpool replace pool c0t5d0s0
  9. Die Platte wieder online nehmen
    • zpool online pool c0t5d0s0
  10. Ab und an den Status des Pools überprüfen, um feststellen zu können, ob der Resilver fertig ist
    • zpool status pool
  11. Counter für Module zfs-diagnosis und zfs-retire von fmstat zurücksetzen
    • fmadm reset zfs-diagnosis
    • fmadm reset zfs-retire
  12. Defekt Meldungen von fmadm auslesen und auf repariert setzen
    • fmadm faulty
    • fmadm repair <id> # Id wird bei "fmadm faulty" angezeigt
  13. Fertig.

Im grossen und ganzen von http://download.oracle.com/docs/cd/E19082-01/817-2271/ghzvx/index.html kopiert.

Keine kostenlosen Patches für Solaris 10!

SunSolve Seite von Sun

SunSolve - hier "gab's" mal Patche für Solaris

Nach der Übernahme von Sun durch Oracle hat sich eine „Kleinigkeit“ in Bezug auf Patches für Solaris 10 geändert.

Bisher war es möglich, auch ohne Wartungsvertrag bestimmte Patches zu downloaden – in der Regel Security Patches konnte man so bekommen.

Dem ist seit heute nicht mehr so.

Weiterlesen

Linux „at“ ignores timezone

While trying to solve some Nagios issue, I remembered that there’s the „at“ command scheduler. It allows to execute a given command at a specified time. So, for example, it’s possible to say „run the SMS sending command at 7 o’clock“:

echo sms-sending-command | at 07:00

If invoked like that, 07:00 is interpreted to mean „07:00 in the current timezone„. It’s also possible to say that 07:00 is supposed to be in the UTC timezone, like so:

echo sms-sending-command | at 07:00 UTC

On my Solaris 10 machines (and also on my Mac OS X notebook), this really works like it should — but on Linux (I tested ArchLinux, Debian & Mandriva), it doesn’t 😦 Check this out: Weiterlesen

Installing Nagios / Icinga

After having installed the depencency libraries, now Nagios has to be installed.

Nagios Core

First of all, the current version of Nagios Core (ie. 3.2.0) has to be fetched and unpacked. We’ll also need to apply a patch to fix the issues shown in the Icinga Installation Troubles post.

Run the following „script“ to download, compile and install (using sudo) Nagios 3.2.0 (yes, it’s indeed one humongous line. You can paste it exactly like it is shown into a terminal):

src_url=http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.0.tar.gz && \
patch_url=http://esisteinfehleraufgetreten.s3.amazonaws.com/nagios/fix-nagios-3.2.0.patch && \
gnu_patch=$(which gpatch) && \
src_dir=$HOME/src/$(basename $src_url .tar.gz) && \
\
mkdir -p $HOME/src && cd $HOME/src && \
(
 if [[ -r $HOME/src/$(basename $src_url) ]];
  then cat $HOME/src/$(basename $src_url)
  else wget -qO- $src_url | tee $HOME/src/$(basename $src_url)
 fi
) | gzcat | tar xf - && \
(
 if [[ -r $HOME/src/$(basename $patch_url) ]];
  then cat $HOME/src/$(basename $patch_url)
  else wget -qO- $patch_url | tee $HOME/src/$(basename $patch_url)
 fi
) | $gnu_patch -d $src_dir -p1 && \
test -L $src_dir/base/snprintf.o || ln -s ../common/snprintf.o $src_dir/base && \
\
cd $src_dir && \
\
CFLAGS="-fast -xtarget=sparc64vii -xarch=sparcima -xchip=sparc64vii -xcache=64/64/2:5120/256/10 -xautopar -fma=fused           -xipo=2 -zlazyload" \
CC=/opt/sunstudio12.1/bin/cc \
PATH=/opt/sunstudio12.1/bin:/usr/sfw/bin:/usr/xpg6/bin:/usr/xpg4/bin:/usr/openwin/bin:/usr/X11/bin:/usr/bin:/usr/sbin:/usr/ucb \
LDFLAGS=-R/opt/local/lib \
    ~+/configure --prefix=/opt/local/nagios-3.2.0 \
      --enable-nanosleep --enable-statusmap --with-perlcache --enable-statuswrl \
      --with-gd-lib=/opt/local/lib --with-gd-inc=/opt/local/include \
      --with-cgiurl=/cgi-bin/nagios-3.2.0 --with-htmurl=/nagios-3.2.0 \
      --with-nagios-user=$(id -un) --with-nagios-group=$(id -gn) \
      --with-init-dir=\${prefix}/etc/init.d --with-httpd-conf=\${prefix}/etc/apache && \
\
CFLAGS="-fast -xtarget=sparc64vii -xarch=sparcima -xchip=sparc64vii -xcache=64/64/2:5120/256/10 -xautopar -fma=fused           -xipo=2 -zlazyload" \
CC=/opt/sunstudio12.1/bin/cc \
PATH=/opt/sunstudio12.1/bin:/usr/sfw/bin:/usr/xpg6/bin:/usr/xpg4/bin:/usr/openwin/bin:/usr/X11/bin:/usr/bin:/usr/sbin:/usr/ucb \
LDFLAGS=-R/opt/local/lib \
    make all && \
\
    sudo sh -c '
      make install && make install-init && make install-commandmode && make install-config && make install-webconf
    '

SMF Manifest

In order to be able to manage (start, stop, control) Nagios with SMF, there needs to be a manifest for Nagios which has to be imported to the system.

url=http://esisteinfehleraufgetreten.s3.amazonaws.com/nagios/application-nagios.manifest.xml
wget -P /tmp $url && \
sudo svccfg import /tmp/$(basename $url)

Icinga

Instead of Nagios Core, it should be possible to use Icinga instead.

src_url=http://prdownloads.sourceforge.net/sourceforge/icinga/icinga-0.8.4.tar.gz && \
patch_url=http://esisteinfehleraufgetreten.s3.amazonaws.com/nagios/fix-icinga-0.8.4.patch && \
gnu_patch=$(which gpatch) && \
src_dir=$HOME/src/$(basename $src_url .tar.gz) && \
\
mkdir -p $HOME/src && cd $HOME/src && \
(
 if [[ -r $HOME/src/$(basename $src_url) ]];
  then cat $HOME/src/$(basename $src_url)
  else wget -qO- $src_url | tee $HOME/src/$(basename $src_url)
 fi
) | gzcat | tar xf - && \
(
 if [[ -r $HOME/src/$(basename $patch_url) ]];
  then cat $HOME/src/$(basename $patch_url)
  else wget -qO- $patch_url | tee $HOME/src/$(basename $patch_url)
 fi
) | $gnu_patch -d $src_dir -p1 && \
test -L $src_dir/base/snprintf.o || ln -s ../common/snprintf.o $src_dir/base && \
\
cd $src_dir && \
\
CFLAGS="-fast -xtarget=sparc64vii -xarch=sparcima -xchip=sparc64vii -xcache=64/64/2:5120/256/10 -xautopar -fma=fused           -xipo=2 -zlazyload" \
CC=/opt/sunstudio12.1/bin/cc \
PATH=/opt/sunstudio12.1/bin:/usr/sfw/bin:/usr/xpg6/bin:/usr/xpg4/bin:/usr/openwin/bin:/usr/X11/bin:/usr/bin:/usr/sbin:/usr/ucb \
LDFLAGS=-R/opt/local/lib \
    ~+/configure --prefix=/opt/local/icinga-0.8.4 \
      --enable-nanosleep --enable-statusmap --with-perlcache --enable-statuswrl \
      --with-gd-lib=/opt/local/lib --with-gd-inc=/opt/local/include \
      --with-cgiurl=/cgi-bin/icinga-0.8.4 --with-htmurl=/icinga-0.8.4 \
      --with-icinga-user=$(id -un) --with-icinga-group=$(id -gn) \
      --with-init-dir=\${prefix}/etc/init.d --with-httpd-conf=\${prefix}/etc/apache && \
\
CFLAGS="-fast -xtarget=sparc64vii -xarch=sparcima -xchip=sparc64vii -xcache=64/64/2:5120/256/10 -xautopar -fma=fused           -xipo=2 -zlazyload" \
CC=/opt/sunstudio12.1/bin/cc \
PATH=/opt/sunstudio12.1/bin:/usr/sfw/bin:/usr/xpg6/bin:/usr/xpg4/bin:/usr/openwin/bin:/usr/X11/bin:/usr/bin:/usr/sbin:/usr/ucb \
LDFLAGS=-R/opt/local/lib \
    make all && \
\
    sudo sh -c '
      make install && make install-init && make install-commandmode && make install-config && make install-webconf
    '

SMF Manifest

Exactly like with Nagios Core, there needs to be SMF Manifest for Icinga. Install it:

url=http://esisteinfehleraufgetreten.s3.amazonaws.com/nagios/application-icinga.manifest.xml
wget -P /tmp $url && \
sudo svccfg import /tmp/$(basename $url)

Nagios Plugins

After having installed Nagios Core, it’s now time to turn to the Nagios Plugins. At the time of this writing, v1.4.13 is the current stable version. The plugins need to be installed in the same directory, where Nagios Core is installed (an alternative might be to fix/change the supplied default configuration to point to the installation directory of Nagios Plugins).

src_url=http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz && \
gnu_patch=$(which gpatch) && \
\
mkdir -p $HOME/src && cd $HOME/src && \
(
 if [[ -r $HOME/src/$(basename $src_url) ]];
  then cat $HOME/src/$(basename $src_url)
  else wget -qO- $src_url | tee $HOME/src/$(basename $src_url)
 fi
) | gzcat | tar xf - && \
\
cd $HOME/src/$(basename $src_url .tar.gz) && \
\
CFLAGS="-fast -xtarget=sparc64vii -xarch=sparcima -xchip=sparc64vii -xcache=64/64/2:5120/256/10 -xautopar -fma=fused -xc99=all -xipo=2 -zlazyload" \
CC=/opt/sunstudio12.1/bin/cc CXX=/opt/sunstudio12.1/bin/CC \
PATH=/opt/sunstudio12.1/bin:/usr/sfw/bin:/usr/xpg6/bin:/usr/xpg4/bin:/usr/openwin/bin:/usr/X11/bin:/usr/bin:/usr/sbin:/usr/ucb:/export/home/webservd/flexlm/UGS/Teamcenter2005/Visualization/bin \
LDFLAGS="-R/opt/local/lib -R/usr/sfw/lib -L/usr/sfw/lib" \
    ~+/configure --prefix=/opt/local/nagios-3.2.0 \
    --with-nagios-user=$(id -un) --with-nagios-group=$(id -gn) \
    --with-cgiurl=/cgi-bin/nagios-3.2.0 \
    --with-trusted-path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/sfw/bin:/usr/xpg6/bin:/usr/xpg4/bin:/usr/openwin/bin:/usr/X11/bin:/opt/csw/bin:/opt/csw/sbin \
    \
    --with-ping-command="/usr/sbin/ping -s %s 64 %u" --without-ipv6 \
    --with-nslookup-command=/usr/sbin/nslookup --with-uptime-command=/bin/uptime \
    --with-dig-command=/usr/sbin/dig --with-ssh-command=/usr/bin/ssh \
    \
    --with-mysql=/usr/sfw --with-openssl=/usr/sfw && \
\
CFLAGS="-fast -xtarget=sparc64vii -xarch=sparcima -xchip=sparc64vii -xcache=64/64/2:5120/256/10 -xautopar -fma=fused -xc99=all -xipo=2 -zlazyload" \
CC=/opt/sunstudio12.1/bin/cc CXX=/opt/sunstudio12.1/bin/CC \
PATH=/opt/sunstudio12.1/bin:/usr/sfw/bin:/usr/xpg6/bin:/usr/xpg4/bin:/usr/openwin/bin:/usr/X11/bin:/usr/bin:/usr/sbin:/usr/ucb:/export/home/webservd/flexlm/UGS/Teamcenter2005/Visualization/bin \
LDFLAGS="-R/opt/local/lib -R/usr/sfw/lib -L/usr/sfw/lib" \
    make && \
\
    sudo make install

SysAdmin’s Journey has these additional ps(1) related configure options:

    --with-ps-command="/bin/ps -eo 's uid pid ppid vsz rss pcpu etime comm args'" \
    --with-ps-format='%s %d %d %d %d %d %f %s %s %n' \
    --with-ps-cols=10 \
    --with-ps-varlist='procstat,&;procuid,&;procpid,&;procppid,&;procvsz,&;procrss,&;procpcpu,procetime,procprog,&pos'

When I add those, make ultimately fails with:

source='check_procs.c' object='check_procs.o' libtool=no \
DEPDIR=.deps depmode=none /bin/bash ../build-aux/depcomp \
/opt/sunstudio12.1/bin/cc -DLOCALEDIR=\"/opt/local/nagios-plugins-1.4.13/share/locale\" -DHAVE_CONFIG_H -I. -I. -I.. -I.. -I../lib -I../gl -I../intl  -I/usr/include/pgsql -I/usr/sfw/include   -I/usr/sfw/include  -fast -xtarget=sparc64vii -xarch=sparcima -xchip=sparc64vii -xcache=64/64/2:5120/256/10 -xautopar -fma=fused -xc99=all -xipo=2 -zlazyload -c check_procs.c
"check_procs.c", line 185: syntax error before or at: ;
"check_procs.c", line 185: syntax error before or at: ;
"check_procs.c", line 185: syntax error before or at: ;
"check_procs.c", line 185: syntax error before or at: ;
"check_procs.c", line 185: syntax error before or at: ;
"check_procs.c", line 185: syntax error before or at: ;
"check_procs.c", line 185: syntax error before or at: )
cc: acomp failed for check_procs.c
*** Error code 1
make: Fatal error: Command failed for target `check_procs.o'
Current working directory /export/home/webservd/src/nagios-plugins-1.4.13.failing/nagios-plugins-1.4.13/plugins

Dunno how Justin got nagios-plugins to compile with these flags; I suppose it’s because he used an older version of nagios-plugins. Anyway, he writes, that he HAD to use these flags, otherwise, make would error out on him in check_procs. For me, it’s the opposite – don’t use --with-ps-XYZ flags, and it compiles fine. Use those --with-ps-XYZ flags, and make fails.

Start

Nagios

Now, after having installed BOTH Nagios Core and Nagios Plugins, it should be possible to start application/nagios:

$ svcs application/nagios
STATE          STIME    FMRI
disabled        9:12:23 svc:/application/nagios:default

$ sudo svcadm enable -s application/nagios

$ svcs application/nagios
STATE          STIME    FMRI
maintenance     9:12:38 svc:/application/nagios:default

Reviewing the log file /var/svc/log/application-nagios:default.log shows this fault:

[...]
[ Sep 29 09:12:37 Executing start method ("/opt/local/nagios-3.2.0/etc/init.d/nagios start") ]
Starting nagios: done.
[ Sep 29 09:12:37 Method "start" exited with status 0 ]
[ Sep 29 09:12:37 Stopping because process dumped core. ]
[ Sep 29 09:12:37 Executing stop method ("/opt/local/nagios-3.2.0/etc/init.d/nagios stop") ]
Stopping nagios: done.
[ Sep 29 09:12:37 Method "stop" exited with status 0 ]
[...]

Main fault: „Stopping because process dumped core.„. Interestingly, when trying to start nagios manually (by running /opt/local/nagios-3.2.0/etc/init.d/nagios start), Nagios starts up just fine – please also see the blogpost Core Dumps when run in SMF, fine otherwise‽.

Haven’t found a reason for the core dump (and also have NOT found the core core dump file itself by running find / -type f -name core, for that matter…). Because of that, switching to the OpenCSW Nagios „Core“ and Nagios Plugins packages. 😦

For the self compiled stuff, this is a:

#fail

Icinga

Try to start icinga:

$ svcs icinga
STATE          STIME    FMRI
disabled       10:21:42 svc:/application/icinga:default

$ sudo svcadm enable -s svc:/application/icinga:default
svcadm: Instanz "svc:/application/icinga:default" befindet sich im Wartungszustand.

$ svcs icinga
STATE          STIME    FMRI
maintenance    10:22:24 svc:/application/icinga:default

And just like Nagios, icinga fails as well:

[...]
[ Sep 29 10:25:30 Executing start method ("/opt/local/icinga-0.8.4/etc/init.d/icinga start") ]
-n Starting icinga:
 done.
[ Sep 29 10:25:30 Method "start" exited with status 0 ]
[ Sep 29 10:25:30 Stopping because process dumped core. ]
[ Sep 29 10:25:30 Executing stop method ("/opt/local/icinga-0.8.4/etc/init.d/icinga stop") ]
Stopping icinga: done.
[...]

Like I said:

#fail

Core Dumps when run in SMF, fine otherwise‽

I discovered, that my self compiled version of Nagios 3.2.0 core dumps, when I run it using the Solaris SMF facility. But when I run it manually, everything’s fine. Strange…

After VERY shortly „trying out“ Icinga, I changed by mind, and decided to go the more stable road and installed Nagios. As there’s only an „ancient“ version of 3.0.6 available at OpenCSW in their „Current Tree“ at the time of this writing, I went ahead and downloaded the now up-to-date version 3.2.0 from Nagios and installed it. This also involved installing libjpeg, libpng, FreeType and finally gd.

Weiterlesen