Starting with Power Scripts™ for Jira v4.0 you can configure scripts to run at the start of your app (startup script) or at its end (shutdown script). The scripts are run every time because Power Scripts™ gets started / stopped, and this is usually either for administrative reasons (i.e. update of the app) or at Jira's own startup/shutdown.
You can configure both of them on the Administration > Add-ons > POWER SCRIPTS > Start/Stop Scripts page.