summaryrefslogtreecommitdiff
path: root/lib/leap_cli/commands/db.rb
blob: 3502d7e9bd86a89f484b062691eeeadae171fa71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module LeapCli; module Commands

  desc 'Database commands.'
  command :db do |db|
    db.desc 'Destroy all the databases. If present, limit to FILTER nodes.'
    db.arg_name 'FILTER', :optional => true
    db.command :destroy do |destroy|
      destroy.action do |global_options,options,args|
        unless global_options[:yes]
          say 'You are about to permanently destroy all database data.'
          bail! unless agree("Continue? ")
        end
        nodes = manager.filter(args)
        if nodes.any?
          nodes = nodes[:services => 'couchdb']
        end
        if nodes.any?
          ssh_connect(nodes, connect_options(options)) do |ssh|
            ssh.run('/etc/init.d/bigcouch stop && test ! -z "$(ls /opt/bigcouch/var/lib/ 2> /dev/null)" && rm -r /opt/bigcouch/var/lib/* && echo "db destroyed" || echo "db already destroyed"')
            ssh.run('grep ^seq_file /etc/leap/tapicero.yaml | cut -f2 -d\" | xargs rm -v')
          end
          say 'You must run `leap deploy` in order to create the databases again.'
        else
          say 'No nodes'
        end
      end
    end
  end

  private

end; end