# File lib/daemons/controller.rb, line 43
    def run
      @options.update @optparse.parse(@controller_part).delete_if { |k, v| !v }

      setup_options

      @group = ApplicationGroup.new(@app_name, @options)
      @group.controller_argv = @controller_part
      @group.app_argv = @app_part

      @group.setup

      case @command
        when 'start'
          @group.new_application.start
        when 'run'
          @options[:ontop] ||= true
          @group.new_application.start
        when 'stop'
          @group.stop_all(@options[:no_wait])
        when 'restart'
          unless @group.applications.empty?
            @group.stop_all(@options[:no_wait])
            sleep(1)
            @group.start_all
          else
            $stderr.puts "#{@group.app_name}: warning: no instances running. Starting..."
            @group.new_application.start
          end
        when 'reload'
          @group.reload_all
        when 'zap'
          @group.zap_all
        when 'status'
          unless @group.applications.empty?
            @group.show_status
            exit 3 if not @group.running?   # exit with status 3 to indicate that no apps are running
          else
            $stderr.puts "#{@group.app_name}: no instances running"
            exit 3                          # exit with status 3 to indicate that no apps are running
          end
        when nil
          fail CmdException.new('no command given')
        else
          fail Error.new("command '#{@command}' not implemented")
      end
    end