I've always used the technique that Andy described (event policy that watches for the system event "Starting of initial processes complete"). That has always worked for me.
However, I will also give you this bit of advice:
If Junos is restarting, then there may be an *awful lot* of things going on. Your event script action *might* get delayed, or just flat-out fail sometimes due to a flurry of higher-priority tasks going on. (I have mostly run across this issue in scripts that needed to do something with the SNMP agent, or on devices with thousands of IFLs to bring up...)
1. make sure that you check the status for any/all rpc operations you do in your event script. Then act accordingly. I.e., retry the command some number of times.
2. Log execution to syslog. I.e. use jcs:syslog(). It'll make troubleshooting a *lot* easier.