I have heard a few people on HN casually mention that one can pass code on to a client “in escrow”. This is suggested as a way one may alleviate a client’s concerns that should you or your business stop supporting the software for any number of reasons, they can pull the source code from escrow and presumably keep running the system.
How does this actually work in practice?
First, a local smallish legal firm that specialised in intellectual property (trade marks, patents, etc) offered an escrow service. We would send them a list of customers and their contact details, updated for each sale, and a DVD (this was a few years ago) of the source code and build scripts for the product: you need to deliver enough to enable the customer to build (and fix) all their licensed products.
Then we got a larger customer who insisted on using what was then called Iron Mountain as their escrow service. That business was sold, and is now owned by NCC Group. Their process was similar, but a bit more bureaucratic.
In both cases, the escrow agents would actually check the build instructions, and make sure they worked: once we forgot to include a file, and they called us up about a week later and asked for it, because their attempt to build it had failed.
The local lawyer was remarkably cheap; Iron Mountain less so, but still reasonable.
They have standard language you can then put in your contracts to give clients the right to acquire the source code (with appropriate rights to transfer to successor organizations, but not to re-distribute, etc) in circumstances where you either cancel the product or go out of business.
My company ended up cancelling one particular product, and one of our customers exercised their escrow rights. They maintained it in-house (with a little bit of help from a couple of our engineers) for many years afterwards.
The whole process was remarkably painless.