OnStart

Is it possible to add OnStart?
I have a script that I want to run when moc starts and I want to stop when moc stops.

Is there another "nice" way to do it?