You will probably want to use the Upstart system which is what is used on Ubuntu to manage system services that need to start at system startup and be kept running while the system is up.
You can look at the files in
/etc/init/ to use as models. In particular, these files are among those that use the
respawn instruction which keeps daemons running if they crash:
Some of those files have corresponding entries in
/etc/init.d that are symlinked to
/lib/init/upstart-job. Others have their own shell script. These are used to manage starting and stopping the daemon and can be used as models for your own script.
Please see this for more information on Upstart.
Please see this for more information on Process Management (although it doesn't include any Upstart information, it does have other useful tips).
Please feel free to ask additional separate questions about specific aspects of making use of this feature. If you have brief follow-ups, you can post them as comments or edits to your question, of course.