startup script

hi,

i want to create script which contineously run in background. It started automatically when system is started. When any error will occur script restarted itself again.

how could i do that. any idea…

lets say i want to log, application name and time when it is started.