aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/rhodecode-setup86
1 files changed, 56 insertions, 30 deletions
diff --git a/scripts/rhodecode-setup b/scripts/rhodecode-setup
index 2b359d6..7f7d73e 100755
--- a/scripts/rhodecode-setup
+++ b/scripts/rhodecode-setup
@@ -16,7 +16,7 @@ REQUIRED_PACKAGES = ["python-pip", "python-webob", "python-bcrypt",
"python-formencode", "python-pylons", "python-dev",
"python-pastescript", "python-psycopg2", "python-nose",
"build-essential", "python-amqplib", "python-anyjson",
- "python-mailer", "apache2", "git-core"]
+ "python-mailer", "apache2", "git"]
# Packages required for celery integration.
CELERY_REQUIRED_PACKAGES = ["rabbitmq-server"]
@@ -95,10 +95,8 @@ def cli_args():
default=RHODECODE_ADMIN_USER,
help="The name of the admin user for RhodeCode.")
parser.add_argument("--rhodecode-admin-pwd",
- help="The password for RhodeCode admin user.",
- required=True)
+ help="The password for RhodeCode admin user.")
parser.add_argument("--rhodecode-admin-email",
- required=True,
help="The email address for RhodeCode admin user.")
parser.add_argument("--rhodecode-usr",
default=RHODECODE_DEFAULT_USER,
@@ -135,8 +133,7 @@ def cli_args():
help="The name to use for the RabbitMQ session. "
"Defaults to '%s'." % RABBITMQ_DEFAULT_USER)
parser.add_argument("--rabbitmq-pwd",
- help="The password for the RabbitMQ user.",
- required=True)
+ help="The password for the RabbitMQ user.")
parser.add_argument("--rabbitmq-vhost",
default=RABBITMQ_DEFAULT_VHOST,
help="The name of the RabbitMQ vhost for the user. "
@@ -154,13 +151,11 @@ def cli_args():
help="The PostgreSQL role to create. Defaults "
"to '%s'." % POSTGRES_ROLE)
parser.add_argument("--postgres-role-pwd",
- required=True,
help="The password for the PostgreSQL role.")
parser.add_argument("--update",
action="store_true",
help="Updates to the latest tagged version.")
parser.add_argument("--apache-conf",
- required=True,
help="Path to the Apache RhodeCode configuration.")
parser.add_argument("--apache-website-dir",
default=APACHE_DEFAULT_DIR,
@@ -175,41 +170,63 @@ def check_cli_args(args):
Logic to handle the various cases for the cli args.
:param args: The args passed on the command line.
"""
+ # Checks for required options during update.
if not args.rhodecode_config:
print ("It is necessary to specify the path to RhodeCode "
"configuration file.")
sys.exit(1)
- if not args.rhodecode_admin_pwd:
- print ("It is necessary to specify the administration password for "
- "RhodeCode")
- sys.exit(1)
- # Checks for required options during update.
if args.update:
if not args.rhodecode_usr:
print ("During update it is necessary to specify the RhodeCode"
"system user.")
sys.exit(1)
+ if not args.rhodecode_branch:
+ print ("During update it is necessary to specify the RhodeCode"
+ "repository tag to use (i.e. v1.5.1).")
+ sys.exit(1)
if not args.rhodecode_checkout_dir:
print ("During update it is necessary to specify the RhodeCode"
"checkout directory.")
sys.exit(1)
- if not args.db_name:
+ if not args.dbname:
print ("During update it is necessary to specify the RhodeCode"
"database name.")
sys.exit(1)
- if not args.no_celery:
- if (args.rabbitmq_usr == RABBITMQ_DEFAULT_USER or \
- args.rabbitmq_vhost == RABBITMQ_DEFAULT_VHOST):
- print ("Warning: default values for --rabbitmq-user and/or "
- "--rabbitmq-vhost are being used.")
-
+ else:
+ if not args.rhodecode_admin_pwd:
+ print ("It is necessary to specify the administration "
+ "password for RhodeCode")
+ sys.exit(1)
+ if not args.rhodecode_admin_email:
+ print ("It is necessary to specify the administration "
+ "email for RhodeCode")
+ sys.exit(1)
+ if not args.apache_conf:
+ print ("It is necessary to specify the path to apache "
+ "configuration file")
+ sys.exit(1)
+ if not args.postgres_role_pwd:
+ print ("It is necessary to specify the PostgreSQL "
+ "user password")
+ sys.exit(1)
if not args.rabbitmq_pwd:
- print ("To setup RhodeCode to correctly use Celery, it is "
- "necessary to specify also the RabbitMQ user password.")
+ print ("It is necessary to specify the RabbitMQ "
+ "password")
sys.exit(1)
+ if not args.no_celery:
+ if (args.rabbitmq_usr == RABBITMQ_DEFAULT_USER or \
+ args.rabbitmq_vhost == RABBITMQ_DEFAULT_VHOST):
+ print ("Warning: default values for --rabbitmq-user and/or "
+ "--rabbitmq-vhost are being used.")
+
+ if not args.rabbitmq_pwd:
+ print ("To setup RhodeCode to correctly use Celery, it is "
+ "necessary to specify also the RabbitMQ user password.")
+ sys.exit(1)
+
def setup_user(user, home_dir, group):
"""Creates the necessary user and its associated group.
@@ -501,7 +518,7 @@ def update_rhodecode(tag, work_dir):
execute_command(cmd_args, work_dir=work_dir, with_sudo=True)
-def update_database_schema(work_dir, config_file):
+def update_database_schema(work_dir, config_file, assume_yes=False):
"""Updates the database schema regardles of the database used.
:param work_dir: Working directory.
@@ -509,8 +526,13 @@ def update_database_schema(work_dir, config_file):
:param config_file: Config file to use, it will tell which db to update.
:type str
"""
+ input_str = None
+ if assume_yes:
+ input_str = "y"
+
cmd_args = ["paster", "upgrade-db", config_file]
- execute_command(cmd_args, work_dir=work_dir)
+ execute_command(cmd_args, work_dir=work_dir, input_str=input_str,
+ continue_on_error=True)
def backup_installation(home_dir):
@@ -526,7 +548,7 @@ def backup_installation(home_dir):
execute_command(cmd_args, work_dir=home_dir)
-def backup_postgres_db(home_dir, db_name):
+def backup_postgres_db(home_dir, db_name, postgres_usr="postgres"):
"""Backup the database as file in home directory.
:param home_dir: Working directory.
@@ -535,8 +557,12 @@ def backup_postgres_db(home_dir, db_name):
:type str
"""
date = datetime.date.today()
+ tempfile_name = "/%s/%s" % ("tmp", DB_BACKUP_FILENAME)
db_filename = "%s.%s" % (DB_BACKUP_FILENAME, date.strftime("%Y.%m.%d"))
- cmd_args = ["pg_dump", db_name, ">", DB_BACKUP_FILENAME]
+ cmd_args = ["-u", postgres_usr, "pg_dump", db_name, "-f", tempfile_name]
+ execute_command(cmd_args, work_dir=home_dir)
+
+ cmd_args = ["cp", tempfile_name, db_filename]
execute_command(cmd_args, work_dir=home_dir)
@@ -720,6 +746,8 @@ if __name__ == '__main__':
home_dir = os.path.join("/home", args.rhodecode_usr)
work_dir = os.path.join(home_dir, args.rhodecode_checkout_dir)
+ rhodecode_conf = os.path.join(home_dir,
+ os.path.basename(args.rhodecode_config))
if args.update:
# Stop rhodecode
@@ -731,11 +759,11 @@ if __name__ == '__main__':
backup_postgres_db(home_dir, args.dbname)
# Update the rhodecode code base. Reinstall Rhodecode.
- update_rhodecode(args.rhodecode_tag, work_dir)
+ update_rhodecode(args.rhodecode_branch, work_dir)
reinstall_rhodecode(work_dir)
# Update database schema.
- update_database_schema(work_dir, args.rhodecode_config)
+ update_database_schema(work_dir, rhodecode_conf, True)
# Start rhodecode and celery.
start_service("rhodecode")
@@ -797,8 +825,6 @@ if __name__ == '__main__':
set_owners(work_dir, args.rhodecode_usr)
install_rhodecode(work_dir, args.rhodecode_usr)
- rhodecode_conf = os.path.join(home_dir,
- os.path.basename(args.rhodecode_config))
copy_file(args.rhodecode_config, home_dir)
set_owners(rhodecode_conf, args.rhodecode_usr)