Automatically restart Microsoft IIS if website is not available

To automatically restart the Microsoft Internet Information Services (IIS) web server if a website is not available, you need:

  • Administrative access to your web server.
  • The WGET command line utility.
  • A text editor like Notepad to create a batch script file.
  • the Task Scheduler to make the batch script run every n Minutes (e.g. every 10 Minutes)

The batch file I created for one of my own web servers looks like:

@REM ==============================================
@REM Automatically restart IIS if website is not available.
@REM (Checks for a sub string in a page of the website).
@REM
@REM Created 2011-10-28, Uwe Keim uk@zeta.li
@REM ==============================================

@REM Remove any existing previous downloads.
del d:\scripts\index.html

@REM Change drive and folder so that WGET stored in a
@REM well-defined location.
D:
cd d:\scripts

@REM Download file.
D:\scripts\wget.exe ^
    --timeout=30 ^
    --tries=1 ^
    http://www.my-server.com/index.html 

@REM Search for the term in the previously downloaded file.
find /I /C "Some String On Website" d:\scripts\index.html

@REM Restart IIS if string is not found.
IF ERRORLEVEL 1 iisreset /RESTART /TIMEOUT:120 /REBOOTONERROR

Please note the following:

  • WGET downloads the URL to a file with the same file name („index.html“ in my above example)
  • The scheduled task must be created to run with an administrative user.
  • The scheduled task must have the „Run with highest privileges“ checkbox set, because IISRESET only runs with administrative privileges.

Error Message „The directory service is unavailable“ when querying ApacheDS LDAP Server

Quick note to myself: An error message

The directory service is unavailable (English)
Der Verzeichnisdienst ist nicht verfügbar (German)

when querying an LDAP ApacheDS server can be caused by the wrong authentication type.

The full exception trace was:

System.Runtime.InteropServices.COMException occurred
ErrorCode=-2147016689
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindAll()

In my code, I did a call to

var de =
  new DirectoryEntry(
    @"LDAP://localhost:10389/ou=users,ou=someou,dc=domain,dc=com",
    @"uid=admin, ou=system",
    @"********",
    AuthenticationTypes.Secure);

which failed. After I changed it to

var de =
  new DirectoryEntry(
    @"LDAP://localhost:10389/ou=users,ou=someou,dc=domain,dc=com",
    @"uid=admin, ou=system",
    @"********",
    AuthenticationTypes.None);

everything worked as expected.

Was hilft gegen Fruchtfliegen? Essig mit Spülmittel!

Kurzer Tipp von Jana:

Gegen Fruchtfliegen hilft ein großes bauchiges Glas (z.B. Weinglas), das zur Hälfte gefüllt wird mit einer Mischung aus Essig und Spülmittel.

Der Essig zieht die Fliegen an, das Spülmittel lässt die Oberflächenspannung verschwinden und somit die Fliegen ertrinken.

Das Glas einfach in der Nähe der Fliegen aufstellen. Nach ein paar Tagen sind viele ertrunken.

Das genaue Mischungsverhältnis Essig zu Spülmittel kenne ich nicht, ich mache das ggf. so 80 % Essig, 20  Spülmittel.

PHP not executing code

Just upgraded my PHP and Apache installation on Windows. After the upgrade, the PHP pages are not executed on the server anymore but the code was sent to the browser.

Doh!

Solution was to add a line to the „httpd.conf“ file:

AddType application/x-httpd-php .php

Seems that the upgrade somehow removed the line from somewhere, maybe in the „mime.types“ file.

The line has to be added inside the „IfModule mime_module“, like in the following excerpt:

<IfModule mime_module>
    AddType application/x-httpd-php .php
</IfModule>

Works well after that. Remember to restart Apache. 🙂