To shut a Mercedes diesel off the key is turned to the "off" position which allows vacuum from the main vacuum hose to go through a line and into a device attached to the back of the injection pump. When this device gets vacuum an arm contracts pulling a lever inside the IP which cuts fuel flow and the engine stops. At least that's what's supposed to happen. But, the IP shutoff device can fail by not holding vacuum itself, or there the vacuum switch on the back of the ignition kay could be bad (it needs to hold vacuum on both points with the key is not in the off position) or there's a vacuum leak somewhere else - maybe EGR, transmission line, locks, heat flaps - what have you - that's causing enough of a leak that there isn't enough vacuum in the mail line any more. If you could several of these problems. Divide and conquor! Each vacuum subsystem can be tested independantly of the others. This article describes the ins and outs of the shutoff circuit.
The part that fails the most often is the shutoff device on the injection pump, so lets start with that. Put a vacuum tester on it and see if it will hold 20 pounds of vacuum for 5 minutes. If it doesn't, replace it. If it does then you should find that as soon as you apply about 7 pounds of vacuum directly to it with your tester, then a running engine will quit. Replacement is fairly straightforward but a but of a pig. There's 4 10mm bolts that secure a cover plate which retains the shutoff valve. There are two gaskets and one metal spacer between the shutoff device and injection pump housing. Getting it out isn't to bad. Getting it back in is another story. Without the metal spacer it's very easy to install, and you can feel the little hook on the end of the shutoff devices arm catch on the lever inside the injection pump. When that's right you'll find it difficult to remove the shutoff device - there is some resistance. But, with the metal spaced sandwiched between the two paper gaskets it's a royal cow to get it in right. Just keep playing with it, eventually you'll get it. There's a notch that you have to align on the body of the shutoff device too, so you canonly install it one way.
So now, whether your car had a bad shutoff valve or not, you have a good one. If your car shuts off correctly when you turn the key off you're done. But if it doesn't, keep reading.
With a shutoff device that holds vacuum but the car will not shut off properly there are three things that can be wrong. The first is the lack of enough vacuum. You should have 21-23 pounds of vacuum in the main vacuum line. You need 5-7 pounds to pull the shutoff valve. If something else on the main vacuum line is leaking (ie, door locks, EGR, heat flaps, transmission modulator) then you may not have enough vacuum to pull the shutoff valve. So what you do to test this is to plug up everything else. I like to use a piece of rubber metric vacuum hose with a ball bearing stuffed in it larger that the diameter of the hard vacuum line. Make a couple of these and put them on the other branches coming off the main vacuum line so all you have hooked up us the shutoff and the brake booster.
If it doesn't work now either your brake booster has a leak - which you'd really notice as you'd have no power brakes any more - or you don't have any vacuum in your main vacuum line either because of physical damage to the line of your vacuum pump ist kerput.
If your vacuum pump is bad, replace it. If the main vacuum line leaks, fix it.
Now if your car shuts off with the key then you're done. If it's still not there's only one thing it can be, and that's the vacuum module on the back of the ignition switch. This is pretty hard to replace in situ unless you remove the instrument cluster, but luckily that's pretty easily done.
A little bit of common sense goes a long way here and you can quickly diagnose broken shutoff: pull vacuum on the shutoff device on a running engine. If it stops it's ok. If not replace it.
Now pull the brown shutoff vacuum line from the main vacuum hose. Pull vacuum on it with the engine running and key in the off position. If the engine stops your ignition switch is ok. If it doesn't it's bad. Replace it. Or maybe you have a bad connector or piece of hose. Point is, the vacuum you're pulling isn't going through the ignition switch and being passed to the shutoff device.
The actual mechanics of how the vacuum is plumbed varies from car to car. Some will have a single bleed from the main hose feeding this circuit others will have the shutoff in a Y connector with something like heater flap vacuum. The under-hood vacuum will also suffer if the EGR control vacuum leaks, or the tranny. But, these can all be viewed and tested as discrete systems and once you fix all the leaks everything will work normally.