I'm sure you'll get a lot of advice on this thread about what to do to break out of purgatory. I think the most valuable advice is to realize that while in purgatory it's quite easy to dismiss any advice due to pessimism or "fuck it I just need to do work"-ism. I think most of the battle is breaking free from your guilty timewasting/not-sleeping habits, and mustering up the willpower to try any of things people suggest. At least that's how it was for me.
I was an insomniac for a few years as a child and part of the cycle was stressing about not being able to get to sleep. Thus the part about deciding to have a restful time without being dead set on sleeping is particularly important for me.
if you ask me, the real question is not what to do when you can´t sleep, but what to do before you get to sleep.
as you say, you´re thinking about your product(s), features, business plans, the next steps,...
the best thing is, at some point i´d say at least 30min before you wanna go to bed) you have to stop.
stop thinking about whatever you work.
stop thinking about future stuff.
and start to relax. read a book. get out with friends (even if its just for an hour).
perhaps you might think that this is time you need for developing ideas, plan stuff...
perhaps it is, BUT your (mine too of course) performance in the night sucks, and if you can´t sleep your tired the next day and then your performance sucks too.
another point is that you can´t work all day and night forever.
i had a day that summer when i realised that all the work i´m doing is bullshit and i´d rather stop today than tomorrow. so i took some days off...
don´t let it get that far.
and most important:
have fun (outside work too)
The key is to occupy my mind with something external so my body can seize the opportunity to fall asleep.
For everyday use, fLux is awsome.
If I just can’t sleep for other reasons, I usually read a book. Within 20 minutes or so my body will finally give in and I can catch some zzz.
2. Otherwise, one can take a walk, or lie down and do #1.
http://en.wikipedia.org/wiki/Savasana
worked for me - better sleep 'quality', no more waking up feeling tired or those sudden jump from the bed from a nightmare.