[Looking for Charlie's main web site?]

CF911: Tips for dealing with Windows service timeout, useful when CF's taking too long to stop/start

In my last entry, CF911: Is your ColdFusion service taking too long to shut down? Find out why, I discussed the first of a two part answer to helping people who are finding that sometimes ColdFusion takes too long to shut down (or startup). That one talks about how to find out where CF may be logging info to explain why it's taking so long.

In this second entry, I'll address the separate but related problem, particularly if you're running CF as a Windows service, that you may find you get timeout errors from the Windows Services panel itself. I'll share some tips to help with that, which I share often with clients of my independent consulting as a CF troubleshooter.

The first thing to understand is that there is indeed a timeout (configurable) for how long the Windows Services control panel is willing to wait. Beyond that, though, there are some 3 more tricks you can use to avoid that timeout.

Update: I should add that a commenter suggested that another solution was just to kill the task. Um, yeah. I knew that, of course. :-) But the point of this entry, like the last one, is when you DON'T just want to kill it. In particular, I made the point in the last entry that if you want to find out *why* CF is taking so long to shutdown, then you need to let it run to completion to see if it may log some diagnostics. See the last entry for more on that.

But yes, as Russ Michaels noted, sure, you can also just kill the task. I will say I try to avoid doing that whenever possible, to let CF end gracefully, unless I'm forced to kill it for urgency sake.

Note that these tips can be helpful for everyone who runs CF as a Windows service, and indeed for anyone running any application as a Windows service.

Tip 1: There is a timeout set for how long the Windows Services panel will wait

So the first thing to note is that, yes, the Windows Services control panel has a fixed duration for how long it's willing to wait for an action (start, stop, or restart) to take, which is configurable in the registry. If the service control action you request does not finish in time, you'll get an error like "The service did not respond to the start or control request in a timely fashion", with associated event log errors like 1053, 7000, 7009, 7011, and so on.

And technically, you should be able to control that timeout via a registry key, called ServicesPipeTimeout, which is discussed in this Microsoft technote and defined in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control.

Sadly, though I've tried it on multiple machines, I'm not finding it to work.

The technote shows clearly how to either update or add it (if it doesn't exist), including noting that you need to choose the "decimal" option to see the value, which is in milliseconds. The technote does note that you must restart Windows for that change to take effect (and I have done that, and double-checked the value, keyname, and location.)

If anyone has more thoughts on this, why it may not be working for me, feel free to share. Still, you will find many blog entries and discussions proposing this, for CF and other servers, so maybe it will work for you.

The technote doesn't clarify what the default is if the key is not there at all, though I've found some mention that it's 30 seconds. I suppose it could vary by version of Windows (anyone know for sure?).

(Note that there is another key you may see (or hear about) set in the same location: WaitToKillServiceTimeout. That is NOT related to this discussion. That key, instead, controls how long Windows should wait for any/all services to stop when you shutdown Windows itself, which is interesting to consider for itself, but not related to this particular blog entry about Services control panel timeouts.)

Of course, all the usual warnings apply about messing with the registry. But it's the solution, if you need it.

So again, this ServicesPipeTimeout registry key would seem to be the one that controls how long the Services panel is willing to wait for a requested action to finish.

Do beware that it's system-wide setting, controlling all services. What may be good for you (CF) may not be good for all services, so be careful. Second, again, note that the server will require a restart for that to take effect.

Whether it works for you or not, the remaining tips should be helpful.

For instance, if you can't change that registry settings, or don't want to, or you find some day the Services panel is still taking too long to stop a service and you worry it may timeout (the control panel), then there are 3 more tips I often share with my customers (and now you, dear readers).

Tip 2: Use stop/start, instead of restart

Again, if you're being plagued by a service start or stop taking a long time, here's something you may not have considered.

Most often when people want to restart CF (or some other service) they will use the "restart" action in the Services panel. That's logical, of course.

But consider that when you have a problem with the action taking too long (stop and/or start, since a restart does both), both have to finish in that configured timeout time (above).

You can help matters by doing not a restart but a stop and start separately. That way, each action can take whatever the max time is that's configured (per above) to do just the one action.

Sure, it's a little painful. You do have to wait for (and notice) the stop before then doing the start. There's also the risk that even the stop may take too long. I'll offer two more tips related to that.

Tip 3: Close the progress bar before its "times out"

This one may not be as obvious, but it does really help. When you have a start/stop/restart action (for the Windows Services control panel) taking a long time, you risk hitting that timeout above.

But notice that Services panel shows a progress bar indicating the duration of the action you've requested. Here's the tip: if/when it's about to reach the end of its indicated time, note that you can hit the "close" button.

That will prevent it complaining about not being able to stop the service. (And BTW, I've seen situations where hitting that timeout limit not only gives an error but even causes the start/stop/restart buttons to be disabled, requiring a restart of the box!)

Once you close the progress bar, you can use the refresh button in the Services panel (or f5) to watch for when the service goes from "stopping" to blank, meaning it's down. Same for when you "close" it while starting a service: it will go from "starting" to "started".

Tip 4: Consider not using the Services Panel at all

Still another tip (which I use regularly) is that you don't actually HAVE to use the Windows services panel to stop/start Windows services. You can do it from the command line (or a shortcut or batch file).

To be clear, I'm not talking about starting the program itself from the command line (CF, as I've been discussing in these last 2 entries), but the Windows service that starts the program. It's a subtle difference.

As an alternative to starting the Windows Service (for CF) using the Service control panel (Control Panel>Administrative Tools>Services, to be clear), you can use a command line command like this, which I use to stop CF:

net stop "ColdFusion 9 Application Server"

The service name is whatever is shown in the properties for the service you want to stop. (And of course you would use a "start" command instead to start the service. There is no "restart" command, buy you could create a batch file to do both.)

You can run this from the command line (Start>Run>cmd) or as a batch file, but I prefer instead to just setup a Windows shortcut, which you can do by right-clicking the desktop and choosing new>shortcut.

That will prompt you for the command (it just asks you to "type the location of the item", but just enter that command above). It will then ask for a name for the shortcut. I call mine simply "stop cf9".

And while you can then execute it by going to the desktop and double-clicking it, a niftier tip is that with more modern Windows versions (2008, 7, Vista), when you hit the the Window Start menu, it now offers a search feature, and you should be able to type "stop cf9" (or just type "stop " and leave it to pop any shortcuts you've created this way to stop various services.)

So why do I like this approach, of stop/starting the service from the command line instead? Because what happens is that a window pops opens (the traditional black background for DOS windows, so easy to observe) and it shows the stop (or start) taking place, however long it takes (which may be very fast). The key benefit is that the window will close on its own when the action is done (however long it takes). I just watch for the stop to be done, and then I do the start.

There is a possibility, of course, that there will be an error in the shortcut or batch file (or perhaps as a response to the correct command), in which case the window will close leaving no chance to see the error. In that case, I just go to the command line (Start>Run>cmd) and execute the same net stop or start command to see what the error is.

To be clear, using this command-line doesn't stop you or others from using the Services panel.

Conclusion

All that said, though, again, if the reason you need to worry about all this is that your CF Service is taking a long time to stop, and you want to find out why, then I would point you again to the last entry I did, In my last entry, CF911: Is your ColdFusion service taking too long to shut down? Find out why.

Hope all that was helpful, whether you use CF or not. Please do let me know in the comments below.

Saving windows command prompt history to a file

Do you find yourself working at the Windows (DOS) command prompt window (aka Start>Run>cmd), and after having entered many commands, wish you could save them to a file, such as before closing the window or perhaps when needing to restart?

This is a bit of esoterica, but as I've seen some searching for a solution in various help forums, I figured I'd share it here. It can be especially useful if you've been using the Microsoft LogParser command-line tool, which allows you to use SQL statements from the command line to analyze log files of all sorts. You may build up a large set of them during a session, and wish you could save them off before closing the command prompt window.

Quick Answer:

doskey /history > commands.log

Explanation

This solution and its meaning will be old hat to some, but it seems to be a revelation to others (judging by how many I found searching for a solution to this challenge, and not being offered any useful answer).

Using the Command History

First, some may know that you can recall past commands on the command prompt (to re-execute them) using the up arrow. You can also "see" a list of the past commands (to choose from them, to re-execute) using f7. But that old-school dos popup can't be edited or saved in any way.

Well, all this command-line history goodness is really driven by a command that's executed implicitly when you open a command prompt window, called DOSKEY.

And if you enter doskey /?, you get some available help (including reminders of the shortcut keys above, and more). But you will see that it has the /history argument I've used, and that lists (to the screen) all the past commands you've entered during the current command prompt session.

Of course, from there, if the list is small enough to appear all on screen, you can just copy/paste the stuff to some file (if you know how to copy content from/to the command window), but if it scrolls off screen, that's where the command I offered is most handy (yes, I know about the "more" command to cause paging of DOS command output, but really, I'd sooner use the one command above then doing a copy, then page forward, and copy. To each his own.)

Piping the history to a file

So saving the displayed history to a file just involves a little more old-school DOS trickeration, whereby you can redirect the output of any command to a file, using the ">" argument, and naming the file to hold the output. The named file will be created in the current directory (indicated in the command prompt window).

Beware, though, that that command will overwrite any previous content in that file. If you want to append to it, instead, use ">>" in the command above. This could be useful if you, for instance, wanted to always write the log to some file, such as in your drive root, so it would become:

doskey /history >> \commands.log

Just be really careful you don't forget those two brackets, or you'll lose what you have!

I instead write it to a file (not worrying where it is), then open it and save that off to evernote. (There may even be some trick to route the save directly to evernote, but I don't know that.)

More on Doskey and command prompt power

For more info on fun with this command prompt doskey and related features, see these docs, which while for XP are good for Vista/Windows 7 (I couldn't find the same content in a more updated page at Microsoft.)

Hope that helps someone. (Just couldn't fit it in a tweet. Darn!)

Have you sought a keyboard shortcut to "open table" in SQL Server 2005 Mgt Studio?

I'm a huge fan of keyboard shortcuts, so imagine my dismay when I noticed that the new SQL Server 2005 "open table" option, available in Management Studio when you're viewing the tables in a database, had no keyboard shortcut (or Admin menu equivalent). The feature opens an editable grid of data in the table, which is a great when you need to do a quick fix of the data. But you have to right-click to see the option--I wonder how many never even notice it?

So I asked around and got an answer to my keyboard dilemma which actually is a generic windows solution. Did you know that you can get the equivalent of the right-click by using Shift-f10? Whatever you have the keyboard focus on, it will open its corresponding context menu. Very nice.

So in SQL Mgt Studio, open the database, then its tables, then select the table (all of which can be done with the keyboard), and then use shift-F10. You'll suddenly see that each context menu option shows the standard underline under the key to hit to execute that command (it's the "o" for open table).

Hope that may help others.

Switching among source windows in Eclipse/CFEclipse

Those who know me well know I'm a big fan of keyboard shortcuts. I could give a whole session on them (and perhaps someday will), so I want to share one that I learned and which is useful if using Eclipse, CFEclipse, or FusionDebug. While many know ctrl-tab will swap among windows in many programs, that doesn't work in Eclipse. Try ctrl-F6 instead, which will show a drop down list of open files and let you scroll forward through them. To go backwards in the list, use Shift-ctrl-f6. Cheers.

PS For other keyboard shortcuts I've shared, going beyond things related to CF, check out the category/tag on the topic at my other (older) blog, tipicalcharlie.com: http://www.tipicalcharlie.com/tags/?/keyboard%2Bshortcuts (domain gone, page recovered from Archive.org)

PPS The entry above on ctrl-f6 is just one more point to be made about looking at Eclipse as a whole when using either CFE or FD. Don't just focus on what those plug-ins add, but rather also on the built-in features of the Eclipse interface which may help you with day-to-day functionality.

Update: Since writing this in 2006, note the several comments below where people offered still more. And of course since then CFBuilder has come out, and with its built-in Aptana offers still more of them. Indeed, in a talk I did on hidden gems, I list other shortcuts for switching windows.

BlogCFC was created by Raymond Camden. This blog is running version 5.005.

Managed Hosting Services provided by
Managed Dedicated Hosting