                 console.log "#{@name}: stopped, code #{code}, signal #{signal}"
                 @port = null
                 @process = null
-                @state = @states.stopped
+                @state 'stopped'
 
             # wait until it starts responding to TCP connections before connecting
             tester = =>

                    process.kill(child.PID)
                @process.kill()

module.exports =
    ServiceManager: ServiceManager
    Service: Service

        @port = null
        @process = null
        @stopTimeout = null
        @readyCallbacks = []

    start: (readyCallback) =>
        if @stopTimeout?
            clearTimeout @stopTimeout
        @stopTimeout = setTimeout @stop, @serviceManager.config.timeout

        if @state() == 'running'
            readyCallback()
            return

        @readyCallbacks.push readyCallback
        if @state() == 'starting'
            return

        @state 'starting'
        freeport (err, port) =>
            @port = port
            processName = "#{@serviceManager.config.dir}/#{@name}"
