The Core Technologies Blog

Professional Software for Windows Services / 24×7 Operation


Hey scripters, http-ping now returns the HTTP status code

Savvy programmers and administrators often use our free http-ping command line utility to check that their web servers up and serving pages. http-ping’s return code (the percentage of page downloads that succeeded) lets them know when the web server is not responding, enabling them to take the appropriate action (for example sending an email or rebooting the server). This works very well when a web server fails to respond but it can’t detect more subtle problems, such as when the server is responding but returning an error.

http-ping version 6.0 addresses that problem. By returning the HTTP status code from the server’s response, a script can detect 404’s (Not Found), 500’s (Internal Server Error) or any other non-standard replies.

Users of AlwaysUp (and Service Protector) can deploy http-ping to detect failures and restart their web servers when necessary. For example, this sample “sanity check plugin” script below signals a restart when it detects a server error (500-599).

Enjoy!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@echo off
:: This batch file uses the http-ping application to detect when
:: a web server is not responding, or responds with a 5XX status
:: code. It returns 0 if the server responds properly and 1 if not.
:: It is intended for use with AlwaysUp
:: (http://www.coretechnologies.com/products/AlwaysUp/)
:: or Service Protector
:: (http://www.coretechnologies.com/products/ServiceProtector/).
:: Copyright 2001-2013 Core Technologies Consulting, LLC. All
:: rights reserved.


:: Here are a few variables that you should adjust.
:: ** Please specify the URL you wish to ping, and the full path
:: to the http-ping executable on your system **
SET url=http://localhost:80
SET http-ping-exe-path="C:\Temp\http-ping.exe"
:: num-times-to-ping == The number of ping attempts that will be
:: made. The default of 5 is probably OK, but you can increase
:: it if errors are frequent (but tolerable).
SET num-times-to-ping=5
:: num-seconds-between-pings == The time to wait between ping
:: attempts. Increase this to give your server more time to get
:: back on its feet after an error.
SET num-seconds-between-pings=10


:: Loop "num-times-to-ping" times.
FOR /L %%X IN (1,1,%num-times-to-ping%) DO CALL :loopbody %%X


:: If we get here, then all ping attempts failed.
echo All %num-times-to-ping% attempts of http-ping failed^! ^
Exiting with 1.
exit 1


:loopbody
:: Ping your web server once, returning the HTTP status code
:: (or 0 if the ping failed to connect).
%http-ping-exe-path% -e -n 1 %url%
:: http-ping returns the HTTP status code or 0 if the ping
:: failed to connect. The list of HTTP status codes is
:: described here:
:: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
:: For this script, we'll panic on 0 or 5XX (server error)
:: and consider all other codes as a success.
IF %ERRORLEVEL% GTR 0 (
   IF %ERRORLEVEL% LSS 500 (
      echo http-ping returned %ERRORLEVEL% - not an error. ^
Exiting with 0.
      exit 0
   ) else IF %ERRORLEVEL% GTR 599 (
      echo http-ping returned %ERRORLEVEL% - not an error. ^
Exiting with 0.
      exit 0
   )
)
echo On attempt #%1, http-ping returned %ERRORLEVEL% - an error.
:: If this was not the last attempt, pause before trying again.
:: Since DOS doesn't have a "sleep" command, use ping with an
:: invalid address and a timeout (in milliseconds) to wait for
:: a while. You can adjust the timeout value
:: (num-seconds-between-pings) above.
IF %1 LSS %num-times-to-ping% (
	SET /A milliseconds=%num-seconds-between-pings% * 1000
	echo Pausing for %num-seconds-between-pings% second^(s^)^
before the next attempt...
	ping 1.1.1.1 -n 1 -w %milliseconds% > nul
)
Posted in http-ping | Tagged , | Leave a comment

Service Protector works with Windows 8.1 Preview

Windows 8.1, the first major update to Microsoft’s controversial Windows 8, is set to be released on October 18. With a restored (but trimmed down) start button, the ability to boot straight into the desktop and other practical improvements, this new OS has the potential to reduce the pain when switching from an older version of Windows.

It is vitally important to us that our applications work with all versions of Windows so we took the recently unveiled 8.1 Preview for an extended test drive with Service Protector – our market-leading tool designed to keep any windows service running 24/7. So far all is well (knock on wood!), and our entire suite of tests has passed successfully. Here is a screenshot of Service Protector doing its job on Windows 8.1 Preview:

Needless to say, we will re-test Service Protector (and all of our applications) in October when Windows 8.1 is officially available, but based on what we have seen so far there shouldn’t be any problems.

Posted in Service Protector | Tagged , | Leave a comment

MyFolders 3.5: Save time working with your files and folders

MyFolders, our free utility that helps you copy or move files to your favorite folders, has been updated. Version 3.5 focuses on improving compatibility with Windows 8 and Server 2012 while fixing a bug handling some non-English file names. MyFolders remains compatible with all versions of Windows released after 2001 (32-bit and 64-bit).

And while we’re discussing MyFolders, here is a youtube video (created by a happy user) showing how to use this time-saving tool:

Posted in MyFolders | Tagged , , | Leave a comment

Trouble running Google Drive 1.9 with AlwaysUp on Windows XP & Server 2003

Over the past couple of years, several of our customers have been using AlwaysUp to run Google Drive as a Windows Service. But this past week, two customers, one on Windows XP and another running Windows Server 2003, reported that AlwaysUp was suddenly failing to start Google Drive, despite having run flawlessly for weeks. Very mysterious!

We downloaded the latest release of Google Drive (version 1.9.4536.8202, from April 29 2013) and had no trouble reproducing the issue on one of our Server 2003 machines. Just like our customers reported, Google Drive would run for a few seconds before dying. And with no error popup, no log file, and no other hint of what went wrong, we were left completely in the dark. (Note to the folks at Google – please improve your error reporting!)

So with 1.9 not cooperating, we decided to take the previous version (1.8.4357.4863, circa May 16 2013) for a test drive. A quick uninstall and install later, we had Google Drive running normally, with no problems whatsoever. It seems that the bug foiling AlwaysUp had been introduced in version 1.9 in the past month.

However this riveting story doesn’t end with a simple recommendation to stick with Google Drive 1.8. After running for a day, our installation suddenly failed again, because version 1.9 was back! Yes, thanks to an automatic update at 2:50 AM, we were back to square one.

Thus in addition to rolling back to version 1.8, we also recommend disabling Google’s automatic updates. Google employs a confusing mix of services and tasks to manage updates, but the two scheduled tasks seem to do the honors for Google Drive. Disable them to prevent automatic updates and keep the stable 1.8 release synchronizing files happily on your PC:

So to summarize, if you are having trouble running Google Drive 1.9 as a Windows Service with AlwaysUp on Windows XP or Server 2003:

  • Uninstall version 1.9
  • Install version 1.8
  • Disable Google’s automatic updates

Please get in touch if you have any questions!

Posted in AlwaysUp | Tagged , , , | Leave a comment

Working with Interactive Services? Switch to Session 0 whenever you like!

If you have a Windows Service that displays GUI elements in the isolated Session 0, then you know how frustrating it can be to work with Microsoft’s Interactive Services Detection Dialog. It pops up constantly, screaming for attention on the task bar, yet when you dismiss it by clicking on the “Ask me later” button, it goes away and is nowhere to be found when you actually need it. Very annoying!

After hours of irritation, we decided to do something about it. Our new (and completely free) Switch To Session 0 utility resides quietly in the task tray and quickly transports you to Session 0 when you double click it. And even better, it can help you banish the Interactive Services Detection Dialog forever (well, almost).


Switch to Session 0 from a Taskbar Tray Icon

Click here to find out more about Switch To Session 0. As always, feedback is appreciated.

Posted in Switch To Session 0 | Tagged , , , | 1 Comment