<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[196190] trunk/Websites/perf.webkit.org</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/196190">196190</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2016-02-05 14:28:20 -0800 (Fri, 05 Feb 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Perf dashboard should have a script to setup database
https://bugs.webkit.org/show_bug.cgi?id=153906

Reviewed by Chris Dumez.

Added tools/setup-database.py to setup the database. It retrieves the database name, username, password
and initializes a database at the specified location.

* Install.md: Updated instruction to setup postgres to use setup-database.py.
* tools/setup-database.py: Added.
(main):
(load_database_config):
(determine_psql_dir):
(start_or_stop_database):
(execute_psql_command):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebsitesperfwebkitorgChangeLog">trunk/Websites/perf.webkit.org/ChangeLog</a></li>
<li><a href="#trunkWebsitesperfwebkitorgInstallmd">trunk/Websites/perf.webkit.org/Install.md</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkWebsitesperfwebkitorgtoolssetupdatabasepy">trunk/Websites/perf.webkit.org/tools/setup-database.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebsitesperfwebkitorgChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Websites/perf.webkit.org/ChangeLog (196189 => 196190)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/ChangeLog        2016-02-05 21:53:00 UTC (rev 196189)
+++ trunk/Websites/perf.webkit.org/ChangeLog        2016-02-05 22:28:20 UTC (rev 196190)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2016-02-04  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
+
+        Perf dashboard should have a script to setup database
+        https://bugs.webkit.org/show_bug.cgi?id=153906
+
+        Reviewed by Chris Dumez.
+
+        Added tools/setup-database.py to setup the database. It retrieves the database name, username, password
+        and initializes a database at the specified location.
+
+        * Install.md: Updated instruction to setup postgres to use setup-database.py.
+        * tools/setup-database.py: Added.
+        (main):
+        (load_database_config):
+        (determine_psql_dir):
+        (start_or_stop_database):
+        (execute_psql_command):
+
</ins><span class="cx"> 2016-01-12  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         buildbot syncing scripts sometimes schedule more than one requests per builder
</span></span></pre></div>
<a id="trunkWebsitesperfwebkitorgInstallmd"></a>
<div class="modfile"><h4>Modified: trunk/Websites/perf.webkit.org/Install.md (196189 => 196190)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/Install.md        2016-02-05 21:53:00 UTC (rev 196189)
+++ trunk/Websites/perf.webkit.org/Install.md        2016-02-05 22:28:20 UTC (rev 196190)
</span><span class="lines">@@ -39,14 +39,6 @@
</span><span class="cx"> 
</span><span class="cx"> # Configuring Apache
</span><span class="cx"> 
</span><del>-You can use apachectl to start/stop/restart apache server from the command line:
-
- - Starting httpd: `sudo apachectl start`
- - Stopping httpd: `sudo apachectl stop`
- - Restarting httpd: `sudo apachectl restart`
-
-The apache logs are located at `/private/var/log/apache2`.
-
</del><span class="cx"> ## Instructions if you're using Server.app
</span><span class="cx"> 
</span><span class="cx">  - Enable PHP web applications
</span><span class="lines">@@ -68,6 +60,16 @@
</span><span class="cx">  - In El Capitan and later, comment out the `LockFile` directive in `/private/etc/apache2/extra/httpd-mpm.conf`
</span><span class="cx">    since the directive has been superseded by `Mutex` directive.
</span><span class="cx"> 
</span><ins>+## Starting Apache
+
+You can use apachectl to start/stop/restart apache server from the command line:
+
+- Starting httpd: `sudo apachectl start`
+- Stopping httpd: `sudo apachectl stop`
+- Restarting httpd: `sudo apachectl restart`
+
+The apache logs are located at `/private/var/log/apache2`.
+
</ins><span class="cx"> ## Production Configurations
</span><span class="cx"> 
</span><span class="cx">  1. Update ServerAdmin to your email address
</span><span class="lines">@@ -102,19 +104,18 @@
</span><span class="cx"> 
</span><span class="cx"> # Configuring PostgreSQL
</span><span class="cx"> 
</span><del>-1. Create database: `/Applications/Server.app/Contents/ServerRoot/usr/bin/initdb /Volumes/Data/perf.webkit.org/PostgresSQL`
-2. Start database: `/Applications/Server.app/Contents/ServerRoot/usr/bin/pg_ctl -D /Volumes/Data/perf.webkit.org/PostgresSQL -l logfile -o &quot;-k /Volumes/Data/perf.webkit.org/PostgresSQL&quot; start`
</del><ins>+Run the following command to setup a Postgres server at `/Volumes/Data/perf.webkit.org/PostgresSQL` (or wherever you'd prefer):
+`python ./setup-database.py /Volumes/Data/perf.webkit.org/PostgresSQL`
</ins><span class="cx"> 
</span><del>-## Creating a Database and a User
</del><ins>+It automatically retrieves the database name, the username, and the password from `config.json`.
</ins><span class="cx"> 
</span><del>-The binaries located in PostgreSQL's directory, or if you're using Server.app in /Applications/Server.app/Contents/ServerRoot/usr/bin/
</del><ins>+## Starting PostgreSQL
</ins><span class="cx"> 
</span><del>-1. Create a database: `/Applications/Server.app/Contents/ServerRoot/usr/bin/createdb webkit-perf-db -h localhost`
-2. Create a user: `/Applications/Server.app/Contents/ServerRoot/usr/bin/createuser -P -S -e webkit-perf-db-user -h localhost`
-3. Connect to database: `/Applications/Server.app/Contents/ServerRoot/usr/bin/psql webkit-perf-db -h localhost`
-4. Grant all permissions to the new user: `grant all privileges on database &quot;webkit-perf-db&quot; to &quot;webkit-perf-db-user&quot;;`
-5. Update database/config.json.
</del><ins>+The setup script automatically starts the database but you may need to run the following command to manually start the database after reboot.
</ins><span class="cx"> 
</span><ins>+- Starting the database: `/Applications/Server.app/Contents/ServerRoot/usr/bin/pg_ctl -D /Volumes/Data/perf.webkit.org/PostgresSQL -l /Volumes/Data/perf.webkit.org/PostgresSQL/logfile -o &quot;-k /Volumes/Data/perf.webkit.org/PostgresSQL&quot; start`
+- Stopping the database: `/Applications/Server.app/Contents/ServerRoot/usr/bin/pg_ctl -D /Volumes/Data/perf.webkit.org/PostgresSQL -l /Volumes/Data/perf.webkit.org/PostgresSQL/logfile -o &quot;-k /Volumes/Data/perf.webkit.org/PostgresSQL&quot; start`
+
</ins><span class="cx"> ## Initializing the Database
</span><span class="cx"> 
</span><span class="cx"> Run `database/init-database.sql` in psql as `webkit-perf-db-user`:
</span><span class="lines">@@ -122,7 +123,5 @@
</span><span class="cx"> 
</span><span class="cx"> ## Making a Backup and Restoring
</span><span class="cx"> 
</span><del>-Run `/Applications/Server.app/Contents/ServerRoot/usr/bin/pg_dump -h localhost --no-owner -f &lt;filepath&gt; webkit-perf-db | gzip &gt; backup.gz`
-
-To restore, setup a new database and run
-`gunzip backup.gz | /Applications/Server.app/Contents/ServerRoot/usr/bin/psql webkit-perf-db -h localhost --username webkit-perf-db-user`
</del><ins>+- Backing up the database: `/Applications/Server.app/Contents/ServerRoot/usr/bin/pg_dump -h localhost --no-owner -f &lt;filepath&gt; webkit-perf-db | gzip &gt; backup.gz`
+- Restoring the database: `gunzip -c backup.gz | /Applications/Server.app/Contents/ServerRoot/usr/bin/psql webkit-perf-db -h localhost --username webkit-perf-db-user`
</ins></span></pre></div>
<a id="trunkWebsitesperfwebkitorgtoolssetupdatabasepy"></a>
<div class="addfile"><h4>Added: trunk/Websites/perf.webkit.org/tools/setup-database.py (0 => 196190)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/tools/setup-database.py                                (rev 0)
+++ trunk/Websites/perf.webkit.org/tools/setup-database.py        2016-02-05 22:28:20 UTC (rev 196190)
</span><span class="lines">@@ -0,0 +1,105 @@
</span><ins>+#!/usr/bin/python
+
+import json
+import os
+import shutil
+import subprocess
+import sys
+import time
+
+
+def main():
+    if len(sys.argv) &lt;= 1:
+        sys.exit('Specify the database directory')
+
+    database_dir = os.path.abspath(sys.argv[1])
+    if os.path.exists(database_dir) and not os.path.isdir(database_dir):
+        sys.exit('The specified path is not a directory')
+
+    database_config = load_database_config()
+
+    database_name = database_config['name']
+    username = database_config['username']
+    password = database_config['password']
+
+    psql_dir = determine_psql_dir()
+
+    print &quot;Initializing database at %s&quot; % database_dir
+    execute_psql_command(psql_dir, 'initdb', [database_dir])
+
+    print &quot;Starting postgres at %s&quot; % database_dir
+    start_or_stop_database(psql_dir, database_dir, 'start')
+    postgres_is_running = False
+    for unused in range(0, 5):
+        try:
+            execute_psql_command(psql_dir, 'psql', ['--list', '--host', 'localhost'], suppressStdout=True)
+            postgres_is_running = True
+        except subprocess.CalledProcessError:
+            time.sleep(0.5)
+
+    if not postgres_is_running:
+        sys.exit('Postgres failed to start in time')
+    print 'Postgres is running!'
+
+    done = False
+    try:
+        print &quot;Creating database: %s&quot; % database_name
+        execute_psql_command(psql_dir, 'createdb', [database_name, '--host', 'localhost'])
+
+        print &quot;Creating user: %s&quot; % username
+        execute_psql_command(psql_dir, 'psql', [database_name, '--host', 'localhost', '--command',
+            &quot;create role \&quot;%s\&quot; with nosuperuser login encrypted password '%s';&quot; % (username, password)])
+
+        print &quot;Granting all access on %s to %s&quot; % (database_name, username)
+        execute_psql_command(psql_dir, 'psql', [database_name, '--host', 'localhost', '--command',
+            'grant all privileges on database &quot;%s&quot; to &quot;%s&quot;;' % (database_name, username)])
+
+        print &quot;Successfully configured postgres database %s at %s&quot; % (database_name, database_dir)
+
+        done = True
+    except Exception as exception:
+        start_or_stop_database(psql_dir, database_dir, 'stop')
+        shutil.rmtree(database_dir)
+        raise exception
+
+    sys.exit(0)
+
+
+def load_database_config():
+    config_json_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../config.json'))
+    with open(config_json_path) as config_json_file:
+        database_config = json.load(config_json_file).get('database')
+
+    if database_config.get('host') != 'localhost':
+        sys.exit('Cannot setup a database on a remote machine')
+
+    return database_config
+
+
+def determine_psql_dir():
+    psql_dir = ''
+    try:
+        subprocess.check_output(['initdb', '--version'])
+    except OSError:
+        psql_dir = '/Applications/Server.app/Contents/ServerRoot/usr/bin/'
+        try:
+            subprocess.check_output([psql_dir + 'initdb', '--version'])
+        except OSError:
+            sys.exit('Cannot find psql')
+    return psql_dir
+
+
+def start_or_stop_database(psql_dir, database_dir, command):
+    execute_psql_command(psql_dir, 'pg_ctl', ['-D', database_dir,
+        '-l', os.path.join(database_dir, 'logfile'),
+        '-o', '-k ' + database_dir,
+        command])
+
+
+def execute_psql_command(psql_dir, command, args=[], suppressStdout=False):
+    return subprocess.check_output([os.path.join(psql_dir, command)] + args,
+        stderr=subprocess.STDOUT if suppressStdout else None)
+
+
+if __name__ == &quot;__main__&quot;:
+    main()
</ins><span class="cx">Property changes on: trunk/Websites/perf.webkit.org/tools/setup-database.py
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnexecutable"></a>
<div class="addfile"><h4>Added: svn:executable</h4></div>
</div>

</body>
</html>