Also consider dual licensing as a solution. For instance, you can release code under a restrictive open source license (such as GPL or AGPL) and also offer the code for a fee under a non-open license that allows it to be used in closed-source projects.