Skip to content

qpsmtpd-forkserver on debian

I had some problems getting qpsmtpd-forkserver to run on debian. The punchline: qpsmtpd-forkserver relies on an environment variable called QPSMTPD_CONFIG, which should point to the directory containing your config files.

$ export QPSMTPD_CONFIG=/etc/qpsmtp
$ qpsmtpd-forkserver ...

Problem solved.

I didn’t want to run qpsmtpd for its standard usage (wrapping a mail server on the same machine), I just wanted a mail proxy that ran some code whenever any email came in, and then forward the email to a real mail server running on a different machine. qpsmtpd has a great plugin system, and was the path of least resistance. However, Debian’s qpsmtpd package is setup to wrap another mail server running on the same machine, and its init scripts configure the QPSMTPD_CONFIG variable for you. This did not help when I tried to start qpsmtpd-forkserver on the command line. I eventually figured it out by reading through the perl code for qpsmtpd, and then the init script itself.

To add insult to injury, qpsmtpd-forkserver had no way to pass the config on the command line.

I don’t know if this behavior is debian-specific, or just an oversight by the qpsmtpd maintainers.

At any rate, I was able to look through the code and figure it out, which is more than I can say for my latest .NET problem. The solution to that one was to speed my move to a new machine.

Server Application Unavailable, no event log, .NET 2

A perplexing error while setting up my new system:

Server Application Unavailable

The web application you are attempting to access on this web server is currently unavailable.

Please hit the “Refresh” button in your web browser to retry your request.

Administrator Note: An error message detailing the cause of this specific request failure can be found in the system event log of the web server. Please review this log entry to discover what caused this error to occur.

The web leads me far astray. I did not have anything in the event log.

The solution? Give MACHINE/ASPNET permission to my project. I found this a LOT faster by switching to .NET 1.1 in IIS, and that gave a much more useful error message. I guess “Server Application Unavailable” is .NET 2’s way of crapping its pants.

Tightly coupled systems are unmaintainable

Yet another example of why I believe this:

Microsoft told me to update to IE7, so I did. To test something in IE6, I’m installing MS Virtual PC 2004 (provided free by MS), and running an image of Windows XP that has IE6 (also provided free by MS). I am following this article from the IEBlog: IE6 and IE7 Running on a Single Machine.

I downloaded both files, and now all I have to do is debug the installation of both. MS Virtual PC thinks I don’t have a checkbox checked, but my network settings disagree. Windows doesn’t think the compressed OS image I downloaded from Microsoft is a valid exe file.

I appreciate that Microsoft is trying to help me out, but making IE7 a separate program from IE6 would be much more helpful.

I guess I’ll try rebooting.

To Linux / Open Source Advocates

I just read another linux advocacy article off of reddit, in this case Five Reasons why Linux will eventually rule the world, and it hit a lot of my pet peeves about these kinds of articles. In a nutshell, for users, all that matters is that their work gets done, and all other arguments are wasted bits.

I have a few suggestions for open source / linux advocates:

  1. Don’t mention Microsoft
    Just don’t do it. My friend Nathan has a set of trolls, and regularly downmods anything referring to those in any setting (slashdot, reddit, what-have-you), and for you linux advocates, Microsoft should enter your troll-sphere. I’ve heard that any press is good press, and while that might not be true (ask Bush about Iraq), I do know that zero press is zero press. I also believe that branding-advertiso-brainwashing works (ask deBeers), so do everyone a favor and not mention the “competition”. At this point the fact that Microsoft exists is almost a non-issue to you. You solve all your problems without Microsoft products, so they are about as relevant to you as vitameatavegamin.
  2. Don’t mention intangibles
    For most people, the choice of operating system or office suite has nothing to do with freedom, morality, or elegance of the code. It’s a non-issue for non-techies, and a dead end for advocates. Technical folks can look all that up, and understand the advantages / disadvantages, but you don’t need to convince them. You need to convince the non-technical CEOs and managers who believe that using open source takes money from their pocket. I run into people in the course of my job who have little to no to false understanding of what “open source” really means. I’d guess half the CEOs in the country think that their codebase is their competitive advantage, and if they employ open source then competitors will steal their business. They will not be convinced by tirades about liberty.
  3. Blog your solutions
    Get a blogger account, and start blogging how you solved your problems using linux or open source. Please, don’t plan to run your own server from your apartment with your hand-rolled Erlang blog engine, cause you’ll never get to it. Just go ahead and start the blogger account with the crappy template that doesn’t use CSS classes the way you’d prefer. When people google to solve their problem, you want there to be multitudes of open source solutions clogging the results. This mostly already happens, but more content can’t hurt, and I’m curious how many dead accounts blogger will keep hosting.
  4. Appeal to the wallet
    In case you haven’t realized it, money makes the world go round. That will remain the case until the either the zombies or the aliens arrive, and then we’ll have a brief respite while exchange rates re-adjust. When people ask why they should use open source, the answer needs to be “because it saves you money”. Last week alone using Firefox with Firebug saved me probably 12 hours worth of time in debugging javascript and reverse-engineering colors and styling from a mock-up. That sort of productivity gain gives managers and CEOs a high equivalent to 3 whippets. Time and cost savings need to be a main point in any article designed to convince someone to switch.
  5. Focus on the user benefit
    Users care about how they benefit. That’s it. I feel this Gimp vs Photoshop article is a good example of open source advocacy. It’s focused on what benefits differentiate the two, and concludes:

    I know I’ve beat the horse to death, but unless you want to pirate software, there is no reason to use Photoshop if you’re not producing a print publication – use the Gimp.

    That is the essential message to send: “Unless you want to (increase cost | increase risk | break the law | behave irrationally), use the open source equivalent”.

  6. Be rational
    Lastly, and most importanly, you have to be rational. Avoid (or at least acknowledge) logical fallacies, call spades spades, and admit weaknesses where you believe them to be. Don’t speak as if you are the end-all, be-all authority. Computing is ridiculously varied, and your solution might not work for others for a wide variety of legitimate reasons. Your mileage will always vary. Don’t be whiny. I read many posts about linux, and sometimes all I can hear is Luke Skywalker whining “But I was going into Tosche Station to pick up some power converters…”. It doesn’t matter if its unfair, it doesn’t matter if its right, it doesn’t matter if its monopolist, don’t whine. Open source is going to take over the world, but not because M$ sux0rs or the mafiaa doesn’t want you to watch DVDs.

Advocates, next time you want to rant about Microsoft doing something bad for humanity, take some time and additionally post how you solve a day-to-day problem. Open source and linux will win because they will be the path of least resistance, and as advocates, it’s our job to make sure the path of least resistence is well-lit.

Restart a windows service remotely

I’ve been working with Shibboleth, an Internet2 project to ease authentication and authorization across institutions. So far, its a mess of XML files, and its been a lot of guess and check on various magic strings. One annoyance in working with it was that I’d update the config files, and then need to remote into the server to restart the windows service using those files. Shibboleth will reread some of the config, but not all, so to be safe I just restart it.

After making a nant task to publish the latest config files for me, the need to click around to restart got very annoying. I wanted to get a way to restart it from the command line so I could restart it from my nant task. After a little googling and some futzing, I got it.

The solution

The program to use is sc.exe, a Service Controller. Unlike net.exe, sc lets you specify a server, so you can do things remotely.

Find the service name

You’ll need the exact service name, which is stored in the registry. An easy way to find it is to enumerate all the services on the box, and then usually you can pick it out from there.

$ sc.exe \\\\server query | less

That will be a long list, so pipe it to less and page through it. That will list an entry for each service, like so:

SERVICE_NAME: shibd_Default
DISPLAY_NAME: Shibboleth 1.3 Daemon (Default)
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

This lets me know the service name I want to be using is “shibd_Default”.

Stopping the service

Stopping is another simple command:

$ sc.exe \\\\server stop shibd_Default

SERVICE_NAME: shibd_Default
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 3  STOP_PENDING
                                (STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x2
        WAIT_HINT          : 0x0
$

Note that is doesn’t wait to stop the service, it merely makes a request to stop, then prints out the current status. The status is predicably STOP_PENDING. It’s important to note that sc.exe doesn’t wait for the service to stop, and that the request to stop may fail.

Starting the service

Starting is another easy command:

$ sc.exe \\\\server start shibd_Default

SERVICE_NAME: shibd_Default
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 2  START_PENDING
                                (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x1
        WAIT_HINT          : 0xbb8
        PID                : 2628
        FLAGS              :

This also only puts in the request for the service to start. As with stop, this request may fail.

Restarting using nant

To put it all together in nant, here’s the plan:

  1. Send the stop request
  2. Sleep a little bit, to give the service a chance to stop
  3. Send the start request
  4. Sleep a little bit, to give the service a chance to start
  5. Send a query request, to check that it started ok

Here’s a simplistic snippet of Nant xml for this:
[xml]
















[/xml]
The sleep time of 5 seconds probably needs to be adjusted for different services.

Conclusion

For once I’m not horribly disappointed in the tools microsoft has provided me. It would be nice if there was a “restart” command, or if you could tell sc.exe to wait until the service actually started or stopped, but there’s at least something workable. Possible improvements would be to make this poll using sc \\server query shibd_Default to check for when the service actually stops or starts, I imagine 5 seconds isn’t a universal upper bound.

If I get ambitious I might package up a nant task wrapping sc and send it to nantcontrib.

C# generics and XML deserializing

I’ve been playing with generics more, trying to ease the slog of C# development. The .NET framework allows you to do damn near everything, but its so freaking verbose. Almost anything I want to do with framework classes ends up taking 4-5 nearly identical lines, so I end up writing a lot of little wrapper functions to make one-liners.

The task I had at hand this time was to take a string of XML and deserialize is back into a C# object. I generated the C# object off of an .xsd file using xsd.exe (more info), so it has the spaghetti of attributes needed for the XmlSerializer.

public static T DeserializeFromXml<T>(string xml){
	T result;
	XmlSerializer ser = new XmlSerializer(typeof(T));
	using(TextReader tr = new StringReader(xml)) {
		result = (T) ser.Deserialize(tr);				
	}
	return result;
}

With that utility function, now I can just:

MyClass obj = Utils.DeserializeFromXml<MyClass>(xml);

Working with these libraries, I always end up pondering why Microsoft didn’t think to include shortcuts like this.

Ease Parsing enums in C# using generics

Once constant annoyance I’ve had with C# has been parsing a string into an enum.

Original C#:

MyEnum e = (MyEnum) Enum.Parse(typeof(MyEnum), "myvalue");

Using generics let you write a function to help:

public static T ParseEnum<T>(string name) {   
  return (T)Enum.Parse(typeof(T), name); 
}

So then you can simply* say:

MyEnum e = ParseEnum<MyEnum>("myvalue");

A little nicer, but still annoying.
*: simply for C#