The key point is that this is invoked on boot.  Hence it needs to be a service (or at least invoked from one).