The “best” `start on` value for an Upstart (init) scripts

initupstart

I often see start on runlevel [2345] in Upstart init scripts, but sometimes (e.g., here) I see other events being used to determine start time. How do I know which events (or status codes) should be used for a given program? For instance, I am currently using just runlevel [2345] for Postgres and Pgbouncer, but I'm not sure if that's really the best idea.

Best Answer

You should probably spend some time looking at some documentation (generally good advice for anything) as it really depends upon your service and what it's requirements are. There is no generic 'best' only that which meets the requirements of your service.

The difference in whether to use the more generic 'runlevel' or the more explicit local-filesystems(7) and net-device-up events should be guided by your job's behaviour. If your service will come up without a valid network interface (for instance, it binds to 0.0.0.0, or uses setsockopt(2) SO_FREEBIND), then the runlevel event is preferable, as your service will start a bit earlier and start in parallel with other services.

However if your service requires that a non-loopback interface is configured for some reason (i.e., it will not start without broadcasting capabilities), then explicitly saying "once a non loopback device has come up" can help...