I have a unix installation that's supposed to be usable both as a chroot and as a standalone system. If it's running as a chroot, I don't want to run any service (cron, inetd, and so on), because they would conflict with the host system or be redundant.
How do I write a shell script that behaves differently depending on whether it's running in a chroot? My immediate need is a modern Linux system, with
/proc mounted in the chroot, and the script is running as root, but more portable answers are welcome as well.
More generally, suggestions that work for other containment methods would be interesting. The practical question is, is this system supposed to be running any services? (The answer being no in a chroot, and yes in a full-fledged virtual machines; I don't know about intermediate cases such as jails or containers.)