A good way to get an indication of whether the server is running and accepting connections is to just run a query against the master database from within your script. A response means it's 'up', otherwise 'down'.
For example:
SELECT TOP 1 message_id FROM sys.messages