There are built-in features for this in Windows Installer - no custom action necessary. In fact I would strongly advice against using a custom action for this unless your service is very special (for example, slow to stop, or in need of shutting down a lot of resources and you need to verify that it does so). Most normal services stop within half a minute or so. I am not sure how long the Windows Installer Engine is configured to wait for the service to stop.
The ServiceControl table of MSI is the "under the hood" feature for this. Most installation tools provide wizard like or GUI elements to control this in a simpler fashion though.
Here is the service control view in one Installshield version: