This is what I use:
1. sudo vi /etc/rc.local
2. Add the following code at the end, just before the “exit 0” line:
echo Waiting for controller
while ! ls /dev/js* 1>/dev/null 2>&1
echo Controller found
What this does is wait indefinitely at bootup until a controller is connected. It works perfectly for my PS3 controller over either bluetooth or USB.