Check SystemDictionary>>addToStartUpList:, addToShutdownList: and processStartupList. You register and then implement startUp and shutDown. There are numerous examples in the image.