diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-17 12:40:56 -0800 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-17 12:40:56 -0800 |
commit | 309e2ceaf85929cc1d8dceaa24620cc1bdae0ede (patch) | |
tree | e2146eed8d9a306f10c71f9b824e0aca38c9ac49 | |
parent | 4bb1664aaee18f801c3268bd855a654fc64fa722 (diff) | |
parent | 65c35466b695b06807c997859ce4ca5b515b6550 (diff) | |
download | gitlab-ce-309e2ceaf85929cc1d8dceaa24620cc1bdae0ede.tar.gz |
Merge pull request #2650 from riyad/setup-task-warning
Improve setup task, by making it less dangerous
-rw-r--r-- | doc/install/installation.md | 2 | ||||
-rw-r--r-- | doc/raketasks/maintenance.md | 13 | ||||
-rw-r--r-- | lib/tasks/gitlab/setup.rake | 26 | ||||
-rw-r--r-- | lib/tasks/gitlab/task_helpers.rake | 27 |
4 files changed, 47 insertions, 21 deletions
diff --git a/doc/install/installation.md b/doc/install/installation.md index f96045c7b4f..8bfcf5c5d44 100644 --- a/doc/install/installation.md +++ b/doc/install/installation.md @@ -260,7 +260,7 @@ used for the `email.from` setting in `config/gitlab.yml`) ## Initialise Database and Activate Advanced Features - sudo -u gitlab -H bundle exec rake gitlab:app:setup RAILS_ENV=production + sudo -u gitlab -H bundle exec rake gitlab:setup RAILS_ENV=production ## Install Init Script diff --git a/doc/raketasks/maintenance.md b/doc/raketasks/maintenance.md index 758580b6832..ee5a8a3b5fb 100644 --- a/doc/raketasks/maintenance.md +++ b/doc/raketasks/maintenance.md @@ -1,16 +1,3 @@ -### Setup production application - -Runs the following rake tasks: - -* db:setup (Create the database, load the schema, and initialize with the seed data) -* db:seed_fu (Loads seed data for the current environment.) -* gitlab:app:enable_automerge (see "Features") - -``` -bundle exec rake gitlab:app:setup RAILS_ENV=production -``` - - ### Gather information about GitLab and the system it runs on This command gathers information about your GitLab installation and the System diff --git a/lib/tasks/gitlab/setup.rake b/lib/tasks/gitlab/setup.rake index 572a22aa1f6..5699e5d6188 100644 --- a/lib/tasks/gitlab/setup.rake +++ b/lib/tasks/gitlab/setup.rake @@ -1,10 +1,22 @@ namespace :gitlab do - namespace :app do - desc "GITLAB | Setup production application" - task :setup => [ - 'db:setup', - 'db:seed_fu', - 'gitlab:enable_automerge' - ] + desc "GITLAB | Setup production application" + task :setup => :environment do + setup + end + + def setup + warn_user_is_not_gitlab + + puts "This will create the necessary database tables and seed the database." + puts "You will lose any previous data stored in the database." + ask_to_continue + puts "" + + Rake::Task["db:setup"].invoke + Rake::Task["db:seed_fu"].invoke + Rake::Task["gitlab:enable_automerge"].invoke + rescue Gitlab::TaskAbortedByUserError + puts "Quitting...".red + exit 1 end end diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake index 12fd5181ecb..d494125f76c 100644 --- a/lib/tasks/gitlab/task_helpers.rake +++ b/lib/tasks/gitlab/task_helpers.rake @@ -1,5 +1,18 @@ +module Gitlab + class TaskAbortedByUserError < StandardError; end +end + namespace :gitlab do + # Ask if the user wants to continue + # + # Returns "yes" the user chose to continue + # Raises Gitlab::TaskAbortedByUserError if the user chose *not* to continue + def ask_to_continue + answer = prompt("Do you want to continue (yes/no)? ".blue, %w{yes no}) + raise Gitlab::TaskAbortedByUserError unless answer == "yes" + end + # Check which OS is running # # It will primarily use lsb_relase to determine the OS. @@ -22,6 +35,20 @@ namespace :gitlab do os_name.try(:squish!) end + # Prompt the user to input something + # + # message - the message to display before input + # choices - array of strings of acceptible answers or nil for any answer + # + # Returns the user's answer + def prompt(message, choices = nil) + begin + print(message) + answer = STDIN.gets.chomp + end while choices.present? && !choices.include?(answer) + answer + end + # Runs the given command and matches the output agains the given pattern # # Returns nil if nothing matched |