diff options
author | Stevan Radaković <stevan.radakovic@linaro.org> | 2013-01-24 18:53:25 +0100 |
---|---|---|
committer | Stevan Radaković <stevan.radakovic@linaro.org> | 2013-01-24 18:53:25 +0100 |
commit | 356ff61cf712ea4aa42173b21eeace04bbf4b650 (patch) | |
tree | cd3b58beb57348105be1e5396048fe3e0ab7c855 | |
parent | 8a6a221638d43a9b2a033a9dba4a01fed6c514e9 (diff) | |
parent | 4819e01c0fd5a117c15e78f8cd7a5203d4cf5722 (diff) |
Merge from milo branch.
-rw-r--r-- | INSTALL | 275 | ||||
-rw-r--r-- | config/production.ini | 14 | ||||
-rw-r--r-- | config/rhodecode | 19 | ||||
-rwxr-xr-x | scripts/rhodecode-setup | 305 | ||||
-rw-r--r-- | scripts/rhodecode-upstart.conf | 4 |
5 files changed, 497 insertions, 120 deletions
@@ -1,47 +1,262 @@ -= Rhodecode installation from source instructions = +RhodeCode Installation and Setup +================================ -== Dependencies == +RhodeCode is an open soruce git hosting solution written in Python. Linaro +uses its own RhodeCode instance to server git repositories. -sudo apt-get install python-software-properties -sudo apt-add-repository ppa:git-core/ppa -sudo apt-get update && sudo apt-get install git-core -sudo apt-get install python-pip python-webob python-bcrypt python-mock python-babel python-detautil python-markdown python-webhelpers python-docutils python-formencode python-pylons python-celery python-dev -sudo apt-get install build-essential +Installation +============ -For sqlite backend: -sudo apt-get install sqlite +TL;DR +----- -For PostgreSQL: +In the 'scripts/' directory there is a Python script to automate the setup +process. -sudo apt-get install postgresql-9.1 pgadmin3 postgresql-server-dev-9.1 -sudo -u postgres createdb rhodecode +To use that script, these are the steps: -Pip packages: + * Edit the 'config/production.ini' file and change the following lines: -sudo pip install psycopg2 -sudo pip install -I beaker==1.6.4 --upgrade -sudo pip install -I sqlalchemy==0.7.8 --upgrade -sudo pip install -I mako==0.7.2 --upgrade -sudo pip install -I pygments==1.5 --upgrade -sudo pip install -I whoosh==2.4.0 --upgrade -sudo pip install -I simplejson==2.5.2 --upgrade -sudo pip install -I waitress==0.8.1 --upgrade + sqlalchemy.db1.url = postgresql://rhodecode:XXXX@localhost/rhodecode + broker.password = XXXX + Change the 'XXXX' with appropriate passwords, that need to be passed on the + command line to run the script. + * Run the following command: -== Clone Rhodecode from git == + python scritps/rhodecode-setup --rhodecode-config config/production.ini \ + --rhodecode-admin-email $EMAIL --rhodecode-admin-pwd $ADMIN_PWD \ + --assume-yes --rabbitmq-pwd $RABBIT_PWD --postgres-role-pwd $DB_PWD \ + --apache-conf config/rhodecode -git clone git://github.com/marcinkuzminski/rhodecode.git -cd rhodecode && git checkout v1.5.1 + Changing $RABBIT_PWD with tha password written in 'broker.password', and + $DB_PWD with the one set up on the database configuration line. Fill in also + the other values: $EMAIL and $ADMIN_PWD for the RhodeCode administration. -== Install Rhodecode == +At the end, the script will print all the installation details. -python setup.py install +Dependencies +------------ -= Setup rhodecode = + * apache2 + * build-essential + * git-core + * mercurial (v2.4.1, not in Ubuntu repositories, need to install via pip) + * pgadmin3 + * postgresql-9.1 + * postgresql-server-dev-9.1 + * python + * python-amqplib + * python-anyjson + * python-babel + * python-bcrypt + * python-celery + * python-dateutil + * python-dev + * python-docutils + * python-formencode + * python-mailer + * python-markdown + * python-nose + * python-pastescript + * python-pip + * python-psycopg2 + * python-pylons + * python-webhelpers + * python-webob + * rabbitmq-server + * waitress (v0.8.1, not in Ubuntu repositories, need to install via pip) -#Get our configuration from git repository instructions should go here. +The package git-core can also be installed via the Ubuntu Git Maintainers PPA +that usually has more updated versions of git. The PPA is: ppa:git-core/ppa -== Start Rhodecode == +Users Configuration +------------------- -paster serve production.ini +The RhodeCode installation will be done with a dedicated system user and group. + * System user: rhodecode + * Group: rhodecode + * Home: /home/rhodecode + +Necessary Directories +--------------------- + +The following directories need to created and be writable at least by the +'rhodecode' user and/or group: + + * /var/log/celery + * /var/log/rhodecode + * /opt/rhodecode + * /opt/git_repos + +The '/opt/rhodecode' directory is where RhodeCode will store its local data and +caches. + +The '/opt/git_repos' directory is where RhodeCode will store the git +repositories directories. + +PostgreSQL Configuration +------------------------ + +For PostgreSQL it is necessary to create a role called 'rhodecode' with its +own password and the permit to create databases, and a database always called +'rhodecode'. + +Once this is done, modify the file 'config/production.ini' at the line: + + sqlalchemy.db1.url = postgresql://rhodecode:XXXX@localhost/rhodecode + +with the correct values. + +The default config file assumes PostreSQL to be installed on the same host of +RhodeCode. + +Celery and RabbitMQ +------------------- + +For better performance with more than 10 repositories hosted on RhodeCode, it +is recommended to use Celery with RabbitMQ. + +Once RabbitMQ has been installed, it is necessary to set up the correct user +and vhost. Commands have to be run as root. + + * Add a new user called 'rhodecode' to RabbitMQ, set up its own password: + + sudo rabbitmqctl add_user rhodecode $PASSWORD + + * Create a new RabbitMQ vhost called 'rhodecode-vhost': + + sudo rabbitmqctl add_vhost rhodecode-vhost + + * Set the correct permission to the new user for the created vhost: + + sudo rabbitmqctl set_permissions -p rhodecode-vhost rhodecode ".*" ".*" ".*" + +Once RabbitMQ has been configured, modify the file 'config/production.ini' with +the correct values. The lines to modify are: + + broker.vhost = rhodecode-vhost + broker.user = rhodecode + broker.password = XXXX + +The default config file assumes RabbitMQ to be installed on the same host of +RhodeCode. + +For more information about Celery and RabbitMQ configurations, see: + + http://docs.celeryproject.org/en/master/getting-started/brokers/rabbitmq.html + +RhodeCode Configuration File +---------------------------- + +In the 'config/' directory there is a default configuration file for a production +RhodeCode instance. + +Copy the file 'config/production.ini' into the home directory of the 'rhodecode' +user and sets its permissions accordingly: + + sudo cp config/production.ini /home/rhodecode/production.ini + sudo chown rhodecode:rhodecode /home/rhodecode/production.ini + +Download, Setup and Install RhodeCode +------------------------------------- + +We install RhodeCode from source, from a Linaro dedicated branch, wich might +contain changes applied by us. All these operation are assumed to be performed +under the 'rhodecode' home directoy, with the user 'rhodecode'. + + * Clone the 'rhodecode' repository from git.linaro.org: + + git clone http://git.linaro.org/git-ro/infrastructure/rhodecode.git + + * Move in the 'rhodecode' directory, checkout the decicated branch and update: + + cd rhodecode && git checkout linaro && git pull origin linaro + + * Always as the 'rhodecode' user, and in the 'rhodecode' git directory: + + paster setup-rhodecode $CONF_FILE --user=$USER --email=$EMAL \ + --password=$PWD --repos=$REPOS + + The variable means: + * $CONF_FILE: path to the 'production.ini' file, that for these instructions + should be '/home/rhodecode/production.ini' + * $USER: the name for the administrator user on the website + * $EMAIL: the email of the administrator + * $PWD: the password for the administrator + * $REPOS: the path of the directory where the git repositories will be saved, + that for these instructions should be '/opt/git_repos' + + * Install RhodeCode, using the 'rhodecode' user home directory as the base: + python setup.py install --user + +Apache Configuration +-------------------- + +In the 'config/' directory there is a working Apache configuration to serve +RhodeCode on port 80. + +To use that configuration it is necessary to enable two Apache modules: + + * proxy + * proxy_http + * ssl (if HTTPS is going to be used) + +Disable also the 'default' Apache module. + +If the directory where git repositories will be stored, is different than +'/opt/git_repos', modify the Apache RhodeCode virtual host accordingly. + +Copy the file 'config/rhodecode' into the appropriate Apache directory and +reload the configuration. + +Start the services +------------------ + +In order to be able to start the services when the server boots, there are two +upstart configuration files that can be used. + +They are located in the 'config/' directory: + + * celeryd-upstart.conf + * rhodecode-upstart.conf + +Copy these files respectively in: + + /etc/init/celeryd.conf + /etc/init/rhodecode.conf + +To start Celery and RhodeCode: + + service celeryd start + service rhodecode start + +To manually start the services, as the 'rhodecode' user: + + paster celeryd $PATH/production.ini + paster server $PATH/production.ini + +LDAP Support +============ + +At the moment, LDAP support is not enabled in RhodeCode nor in the automated +install script. + +To enable LDAP: + + * Install the python-ldap package: + + sudo apt-get install python-ldap + + * Login as admin to RhodeCode, and from the Admin menu choose LDAP + + * LDAP configuration has to be done in there. For more info see: + + http://packages.python.org/RhodeCode/setup.html#setting-up-ldap-support + +Configuration +============= + +All RhodeCode configuration, like creating groups and modifying some of its +setting, happens from the web interface when logged in as the admin user. diff --git a/config/production.ini b/config/production.ini index 7cebc39..abfdb9d 100644 --- a/config/production.ini +++ b/config/production.ini @@ -1,7 +1,5 @@ ################################################################################ # RhodeCode - Pylons environment configuration # -# # -# The %(here)s variable will be replaced with the parent directory of this file# ################################################################################ [DEFAULT] @@ -31,8 +29,7 @@ pdebug = false #WAITRESS threads = 5 use = egg:waitress#main - -host = 0.0.0.0 +host = 127.0.0.1 port = 5000 [filter:proxy-prefix] @@ -135,11 +132,10 @@ auth_ret_code = #################################### use_celery = true broker.host = localhost -broker.vhost = rhodecode +broker.vhost = rhodecode-vhost broker.port = 5672 -#broker.user = rabbitmq -broker.user = $USER -broker.password = $PASSWORD +broker.user = rhodecode +broker.password = XXXX celery.imports = rhodecode.lib.celerylib.tasks @@ -335,7 +331,7 @@ logview.pylons.util = #eee #sqlalchemy.db1.url = sqlite:////opt/rhodecode/rhodecode.db # POSTGRESQL -sqlalchemy.db1.url = postgresql://postgres:postgres@localhost/rhodecode +sqlalchemy.db1.url = postgresql://rhodecode:XXXX@localhost/rhodecode # MySQL # sqlalchemy.db1.url = mysql://user:pass@localhost/rhodecode diff --git a/config/rhodecode b/config/rhodecode new file mode 100644 index 0000000..852d5f2 --- /dev/null +++ b/config/rhodecode @@ -0,0 +1,19 @@ +<VirtualHost *:80> + ServerName staging.git.linaro.org + ServerAlias staging.git.linaro.org + + <Proxy *> + Order allow,deny + Allow from all + </Proxy> + + Alias /git-ro/ /opt/git_repos/ + Alias / /opt/git_repos/ + + #Directive to properly generate url (clone url) for pylons + ProxyPreserveHost On + + #rhodecode instance + ProxyPass / http://127.0.0.1:5000/ + ProxyPassReverse / http://127.0.0.1:5000/ +</VirtualHost> diff --git a/scripts/rhodecode-setup b/scripts/rhodecode-setup index 479f954..b4d0de6 100755 --- a/scripts/rhodecode-setup +++ b/scripts/rhodecode-setup @@ -13,29 +13,20 @@ REQUIRED_PACKAGES = ["python-pip", "python-webob", "python-bcrypt", "python-mock", "python-babel", "python-dateutil", "python-markdown", "python-webhelpers", "python-docutils", "python-formencode", "python-pylons", "python-dev", - "build-essential", "apache2"] + "python-pastescript", "python-psycopg2", "python-nose", + "build-essential", "python-amqplib", "python-anyjson", + "python-mailer", "apache2", "git-core"] # Packages required for celery integration. -CELERY_REQUIRED_PACKAGES = ["python-celery", "rabbitmq-server"] +CELERY_REQUIRED_PACKAGES = ["rabbitmq-server"] # Packages for the backend to use. SQLITE_DB = "sqlite" -POSTGRESQL_DB = ["postgresql-9.1", "pgadmin3", "postgresql-server-dev-9.1"] +POSTGRESQL_DB = ["postgresql-9.1"] # The name of the DB for PostgreSQL. DB_NAME = "rhodecode" # Packages to be installed via PIP. -PIP_PACKAGES = { - "psycopg2": None, - "celery": "2.2.10", - "dulwich": "0.8.7", - "beaker": "1.6.4", - "sqlalchemy": "0.7.9", - "mako": "0.7.3", - "pygments": "1.5", - "whoosh": "2.4.0", - "simplejson": "2.5.2", - "waitress": "0.8.1", -} +PIP_PACKAGES = {} # RhodeCode source to clone and which branch to use. RHODECODE_SOURCE_GIT_URL = \ @@ -47,6 +38,9 @@ RHODECODE_CO_DIR = "rhodecode" # install the RhodeCode code and to run RhodeCode. RHODECODE_DEFAULT_USER = "rhodecode" +# Default RhodeCode directory for data and cache. +RHODECODE_DATA_DIR = "/opt/rhodecode" + # Default parameters for RabbitMQ setup. RABBITMQ_DEFAULT_USER = "rhodecode" RABBITMQ_DEFAULT_VHOST = "rhodecode-vhost" @@ -59,10 +53,26 @@ RHODECODE_UPSTART_CONF = "rhodecode-upstart.conf" CELERY_UPSTART_CONF = "celeryd-upstart.conf" # SQL string to create the new role in PostgreSQL. -POSTGRES_CREATE_USER = "CREATE ROLE %(role)s LOGIN CREATEDB PASSWORD '%(pwd)s'" +POSTGRES_CREATE_ROLE = "CREATE ROLE %(role)s LOGIN CREATEDB PASSWORD '%(pwd)s'" +# The name of the PostgreSQL role to create. POSTGRES_ROLE = "rhodecode" +# Default directory where to store git repositories. +REPOS_DIR = "/opt/git_repos" + +# Default Celery log directory. +CELERY_LOG_DIR = "/var/log/celery" +# Default RhodeCode log directory. +RHODECODE_LOG_DIR = "/var/log/rhodecode" + +# Default websites directory. +APACHE_DEFAULT_DIR = "/etc/apache2/sites-available/" +# Default modules to enalbe in Apache +APACHE_ENABLE_MODULES = ["proxy", "proxy_http"] +# Apache websites to disable. +APACHE_DISABLE_SITES = ["default"] + def cli_args(): """Sets up the cli argument parser.""" @@ -71,9 +81,14 @@ def cli_args(): help="Path to the config INI file.", required=True) parser.add_argument("--rhodecode-data-dir", - default="/opt/rhodecode", + default=RHODECODE_DATA_DIR, help="The directory where to store RhodeCode data " - "and cache.") + "and cache. Defaults to '%s'." % + RHODECODE_DATA_DIR) + parser.add_argument("--rhodecode-log-dir", + default=RHODECODE_LOG_DIR, + help="The directory to store RhodeCode logs. Defaults " + "to '%s'." % RHODECODE_LOG_DIR) parser.add_argument("--rhodecode-admin-usr", default=RHODECODE_ADMIN_USER, help="The name of the admin user for RhodeCode.") @@ -90,12 +105,11 @@ def cli_args(): parser.add_argument("--rhodecode-git-url", default=RHODECODE_SOURCE_GIT_URL, help="The URL where to clone RhodeCode source " - "code from. Defaults to '%s'" % - RHODECODE_SOURCE_GIT_URL) + "code from.") parser.add_argument("--rhodecode-checkout-dir", default=RHODECODE_CO_DIR, help="The destination directory where to clone " - "RhodeCode code into. Defaults to %s" % + "RhodeCode code into. Defaults to '%s'." % RHODECODE_CO_DIR) parser.add_argument("--rhodecode-branch", default=RHODECODE_SOURCE_BRANCH, @@ -110,21 +124,29 @@ def cli_args(): parser.add_argument("--no-celery", action="store_true", help="If Celery integration should be disabled.") + parser.add_argument("--celery-log-dir", + default=CELERY_LOG_DIR, + help="The Celery log directory. Defaults to '%s'." % + CELERY_LOG_DIR) parser.add_argument("--rabbitmq-usr", default=RABBITMQ_DEFAULT_USER, - help="The name to use for the RabbitMQ session.") + 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) parser.add_argument("--rabbitmq-vhost", default=RABBITMQ_DEFAULT_VHOST, - help="The name of the RabbitMQ vhost for the user.") + help="The name of the RabbitMQ vhost for the user. " + "Defaults to '%s'." % RABBITMQ_DEFAULT_VHOST) parser.add_argument("--dbname", default=DB_NAME, - help="The name to use for the database.") + help="The name to use for the database. Defauls to " + "'%s'." % DB_NAME) parser.add_argument("--repos-dir", - default="/opt/git_repos", - help="Where the git repositories will be stored.") + default=REPOS_DIR, + help="Where the git repositories will be stored. " + "Defaults to '%s'." % REPOS_DIR) parser.add_argument("--postgres-role", default=POSTGRES_ROLE, help="The PostgreSQL role to create. Defaults " @@ -135,6 +157,13 @@ def cli_args(): 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, + help="Path the the Apache sites directory. Defaults " + "to '%s'." % APACHE_DEFAULT_DIR) return parser.parse_args() @@ -170,41 +199,34 @@ def setup_user(user, home_dir, group): :param user: The name of the user and group to create. """ - # Add the user. - cmd_args = ["adduser", "--system", "--home", home_dir, user] - execute_command(cmd_args) - # Add the user group. cmd_args = ["addgroup", "--system", group] execute_command(cmd_args) - # Add the user to its group. - cmd_args = ["adduser", user, group] + # Add the user. + cmd_args = ["adduser", "--system", "--home", home_dir, "--ingroup", + group, user] execute_command(cmd_args) -def setup_directories(data_dir, repos_dir, rhodecode_usr): - if not os.path.exists(data_dir): - cmd_args = ["mkdir", "-p", data_dir] - execute_command(cmd_args) - - if not os.path.exists(repos_dir): - cmd_args = ["mkdir", "-p", repos_dir] - execute_command(cmd_args) +def setup_directories(directories, rhodecode_usr): + """Sets up the correct necessary directories.""" + if not isinstance(directories, list): + directories = [directories] - # Set ownership of the directories to the RhodeCode user. - set_owners(data_dir, rhodecode_usr) - - set_owners(repos_dir, rhodecode_usr) + for directory in directories: + if not os.path.exists(directory): + cmd_args = ["mkdir", "-p", directory] + execute_command(cmd_args) + # Set ownership of the directories to the RhodeCode user. + set_owners(directory, rhodecode_usr) def execute_command(cmd_args, work_dir=os.getcwd(), with_sudo=True, input_str=None, - stderr=subprocess.PIPE, - stdin=subprocess.PIPE, - stdout=None): + continue_on_error=False): """Runs the command passed. :param cmd_args: List of command and options to run. @@ -217,6 +239,9 @@ def execute_command(cmd_args, :param input_str: String to pass to the process as input, in order to automate as much as possible. :type str + :param continue_on_error: If an error arise, continue instead of exiting. + Default to False. + :type bool """ if not isinstance(cmd_args, list): cmd_args = list(cmd_args) @@ -225,6 +250,7 @@ def execute_command(cmd_args, if input_str: process = subprocess.Popen(cmd_args, cwd=work_dir, +<<<<<<< HEAD stderr=stderr, stdin=stdin, stdout=stdout) @@ -238,6 +264,18 @@ def execute_command(cmd_args, p_out, p_err = process.communicate() return p_out, p_err if process.returncode != 0: +======= + stdin=subprocess.PIPE) + process.communicate(input=input_str) + else: + process = subprocess.Popen(cmd_args, + cwd=work_dir) + process.communicate() + + if continue_on_error: + return + elif process.returncode != 0: +>>>>>>> milo print "Error executing the following command: %s" % " ".join(cmd_args) sys.exit(1) @@ -276,20 +314,27 @@ def install_packages(packages, assume_yes=False): execute_command(cmd_args, input_str=input_str) -def install_pip_packages(packages): +def install_pip_packages(packages, user=None): """Installs packages from PIP. :param packages: The packages to install. It has to be a dictionary, with key the name of the package, and value the version number or None. :type dict + :param user: The user to install the PIP package as. This will append + --user to the command line. + :type str """ for key, value in packages.iteritems(): - cmd_args = ["pip", "install", "-q", "-I"] + print "Installing package %s with PIP..." % key + cmd_args = ["pip", "install", "-I"] if value: cmd_args.append("%s==%s" % (key, value)) else: cmd_args.append(key) - cmd_args.append("--upgrade") + cmd_args.append("-U") + if user: + cmd_args = ["-u", user] + cmd_args + cmd_args.append("--user") execute_command(cmd_args) @@ -316,10 +361,9 @@ def create_postgresql_role(role, pwd, postgres_usr="postgres"): :param postgres_usr: The superuser for PostreSQL. Defaults to 'postgres'. :type str """ - postgres_commamd = POSTGRES_CREATE_USER % dict(role=str(role), + postgres_commamd = POSTGRES_CREATE_ROLE % dict(role=str(role), pwd=str(pwd)) - cmd_args = ["-u", postgres_usr, "psql", "-c", - '"%s"' % str(postgres_commamd)] + cmd_args = ["-u", postgres_usr, "psql", "-c", str(postgres_commamd)] execute_command(cmd_args) @@ -353,7 +397,7 @@ def setup_rabbitmq_server(user, password, vhost): execute_command(cmd_args) cmd_args = ["rabbitmqctl", "set_permissions", "-p", vhost, user, - '".*"', '".*"', '".*"'] + ".*", ".*", ".*"] execute_command(cmd_args) @@ -379,6 +423,9 @@ def clone_rhodecode_code(url, branch, work_dir, source_co): cmd_args = ["git", "checkout", branch] execute_command(cmd_args, work_dir=source_path) + cmd_args = ["git", "pull", "origin", branch] + execute_command(cmd_args, work_dir=source_path) + def set_owners(directory, usr, group=None): """Sets the correct ownership on the given directory. @@ -398,14 +445,33 @@ def set_owners(directory, usr, group=None): execute_command(cmd_args) -def install_rhodecode(work_dir): +def set_permissions(file_or_dir, permissions): + """Sets the permissions on the given path. + + :param file_or_dir: A list of paths to set the permissions. + :type list + :param permissions: String containing the permissions as passed to the + 'chmod' command. + """ + if not isinstance(file_or_dir, list): + file_or_dir = [file_or_dir] + for element in file_or_dir: + cmd_args = ["chmod", "-R", permissions, element] + execute_command(cmd_args) + + +def install_rhodecode(work_dir, user=None): """Installs RhodeCode on the system. :param work_dir: The directory containing RhodeCode setup file. :type str """ cmd_args = ["python", "setup.py", "install"] - execute_command(cmd_args, work_dir=work_dir, with_sudo=True) + + if user: + cmd_args = ["-u", user, "-H"] + cmd_args + cmd_args.append("--user") + execute_command(cmd_args, work_dir=work_dir) def reinstall_rhodecode(work_dir): """Re-installs RhodeCode on the system. @@ -432,7 +498,7 @@ def update_rhodecode(work_dir): def setup_rhodecode(rhodecode_dir, config_file, git_repos, admin_usr, - admin_pwd, admin_email, user=None): + admin_pwd, admin_email, user=None, assume_yes=False): """Sets up RhodeCode instance. :param rhodecode_dir: The directory where RhodeCode code was checked out. @@ -447,6 +513,8 @@ def setup_rhodecode(rhodecode_dir, config_file, git_repos, admin_usr, :type str :param user: The user to run the process as. :type str + :param assume_yes: Tries to automate the process. + :type bool """ usr_arg = "--user=%s" % admin_usr pwd_arg = "--password=%s" % admin_pwd @@ -454,7 +522,7 @@ def setup_rhodecode(rhodecode_dir, config_file, git_repos, admin_usr, repos = "--repos=%s" % os.path.abspath(git_repos) if user: - cmd_args = ["-u", user] + cmd_args = ["-u", user, "-H"] cmd_args += ["paster", "setup-rhodecode", config_file] cmd_args.append(usr_arg) @@ -462,7 +530,10 @@ def setup_rhodecode(rhodecode_dir, config_file, git_repos, admin_usr, cmd_args.append(email_arg) cmd_args.append(repos) - execute_command(cmd_args, work_dir=rhodecode_dir, stderr=None) + input_str = None + if assume_yes: + input_str = "y" + execute_command(cmd_args, work_dir=rhodecode_dir, input_str=input_str) def install_upstart_conf(no_celery): @@ -484,10 +555,7 @@ def install_upstart_conf(no_celery): def copy_file(source, dest): - """Copies the config file to the destination directory. - - Copies RhodeCode destination file to the specified directory, setting the - corret user and group for the copied file. + """Copies the a file to the defined destination. :param source: Path to the file to copy. :param dest: Where to copy the source file. @@ -496,13 +564,64 @@ def copy_file(source, dest): execute_command(cmd_args) -def start_services(no_celery): - """Starts the installed services. +def start_service(service): + """Starts a service. - :param no_celery: If Celery has to be started or not. - :type bool + Start a service by using the 'service' command. + + :param service: The service to start. + :type str """ - pass + cmd_args = ["service", service, "start"] + execute_command(cmd_args, continue_on_error=True) + + +def reload_apache_service(): + """Reloads Apache configuration.""" + cmd_args = ["service", "apache2", "reload"] + execute_command(cmd_args) + + +def disable_apache_sites(sites): + """Disables Apache sites. + + :param sites: The list of sites to disable. + :type list + """ + if not isinstance(sites, list): + sites = [sites] + + for site in sites: + cmd_args = ["a2dissite", site] + execute_command(cmd_args) + + +def enable_apache_sites(sites): + """Enables Apache sites. + + :param sites: The list of sites to enable. + :type list + """ + if not isinstance(sites, list): + sites = [sites] + + for site in sites: + cmd_args = ["a2ensite", site] + execute_command(cmd_args) + + +def enable_apache_modules(modules): + """Enables Apache modules. + + :param modules: List of modules to enable. + :type list + """ + if not isinstance(modules, list): + modules = [modules] + + for module in modules: + cmd_args = ["a2enmod", module] + execute_command(cmd_args) def print_install_report(args, home_dir, config_file): @@ -511,15 +630,17 @@ def print_install_report(args, home_dir, config_file): :param args: The command line arguments. """ print "\n\nRhodeCode Linaro Installation Report\n" - print "\nRhodeCode Information" + + print "\nRhodeCode Information\n" print "\tCode cloned from: %s" % args.rhodecode_git_url - print "\tInstallation Dir: %s" % home_dir + print "\tInstallation Directory: %s" % home_dir print "\tConfiguration file: %s" % config_file - print "\tData Dir: %s" % args.rhodecode_data_dir - print "\tRepos Dir: %s" % args.repos_dir + print "\tData Directory: %s" % args.rhodecode_data_dir + print "\tRepos Directory: %s" % args.repos_dir print "\tAdmin Username: %s" % args.rhodecode_admin_usr print "\tAdmin Password: %s" % args.rhodecode_admin_pwd print "\tAdmin Email: %s" % args.rhodecode_admin_email + print "\nDatabase Information\n" if args.development: print "\tDatabase Backend: SQLite" @@ -527,6 +648,9 @@ def print_install_report(args, home_dir, config_file): else: print "\tDatabase Backend: PostreSQL" print "\tDatabase Name: %s" % args.dbname + print "\tDatabase Role: %s" % args.postgres_role + print "\tDatabase Role Password: %s" % args.postgres_role_pwd + print "\nCelery/RabbitMQ Integration\n" print "\tCelery activated: %s" % (not args.no_celery) if not args.no_celery: @@ -534,6 +658,7 @@ def print_install_report(args, home_dir, config_file): print "\tRabbitMQ Password: %s" % args.rabbitmq_pwd print "\tRabbitMQ Vhost: %s" % args.rabbitmq_vhost + if __name__ == '__main__': args = cli_args() check_cli_args(args) @@ -543,9 +668,16 @@ if __name__ == '__main__': setup_user(args.rhodecode_usr, home_dir, args.rhodecode_usr) # Create the necessary directories to store RhodeCode data and cache. - setup_directories(args.rhodecode_data_dir, - args.repos_dir, - args.rhodecode_usr) + directories = [args.rhodecode_data_dir, args.repos_dir, + args.rhodecode_log_dir] + if not args.no_celery: + directories.append(args.celery_log_dir) + + setup_directories(directories, args.rhodecode_usr) + + # Set the correct permissions to the directories, at least the group + # should be able to write. + set_permissions(directories, "g+w") # Take git-core package from Launchpad PPA of git maintainers. install_git_from_ppa(assume_yes=args.assume_yes) @@ -562,11 +694,11 @@ if __name__ == '__main__': install_packages(REQUIRED_PACKAGES, assume_yes=args.assume_yes) # Install packages through PIP - install_pip_packages(PIP_PACKAGES) + # install_pip_packages(PIP_PACKAGES) if not args.development: create_postgresql_role(args.postgres_role, args.postgres_role_pwd) - create_postgresql_db(args.dbname) + create_postgresql_db(args.dbname, args.postgres_role) if not args.no_celery: setup_rabbitmq_server(args.rabbitmq_usr, @@ -581,7 +713,7 @@ if __name__ == '__main__': work_dir = os.path.join(home_dir, args.rhodecode_checkout_dir) # Need to set the correct owners of the directory. set_owners(work_dir, args.rhodecode_usr) - install_rhodecode(work_dir) + install_rhodecode(work_dir, args.rhodecode_usr) rhodecode_conf = os.path.join(home_dir, os.path.basename(args.rhodecode_config)) @@ -594,8 +726,23 @@ if __name__ == '__main__': args.rhodecode_admin_usr, args.rhodecode_admin_pwd, args.rhodecode_admin_email, - args.rhodecode_usr) + user=args.rhodecode_usr, + assume_yes=args.assume_yes) + # Apache configurations. + apache_conf = os.path.abspath(args.apache_conf) + copy_file(apache_conf, args.apache_website_dir) + + disable_apache_sites(APACHE_DISABLE_SITES) + enable_apache_modules(APACHE_ENABLE_MODULES) + enable_apache_sites(os.path.basename(apache_conf)) + reload_apache_service() + + # Install upstart scripts for Celery and RhodeCode install_upstart_conf(args.no_celery) + start_service("rhodecode") + + if not args.no_celery: + start_service("celeryd") print_install_report(args, home_dir, rhodecode_conf) diff --git a/scripts/rhodecode-upstart.conf b/scripts/rhodecode-upstart.conf index 0ed8685..6d8f15d 100644 --- a/scripts/rhodecode-upstart.conf +++ b/scripts/rhodecode-upstart.conf @@ -12,8 +12,8 @@ respawn umask 0022 -env PIDFILE=/var/rhodecode/rhodecode.pid -env LOGFILE=/var/rhodecode/log/rhodecode.log +env PIDFILE=/tmp/rhodecode.pid +env LOGFILE=/var/log/rhodecode/rhodecode.log env HOME=/home/rhodecode env APPINI=/home/rhodecode/production.ini env USER=rhodecode |