Hi there.
This is the last post in the series of a local AOSP gerrit server setup.
In this post, We’ll finalize the configuration of Gerrit, add new branches for development and see how to maintain the setup.

In the last post, we’ve finished creating the project in Gerrit.
When we develop locally, we should work on our own branches. Basically, you choose a branch/tag that you want to use as a baseline and start working from there.
As we know, in Android, there are too many projects to do it by hand for each project.
Let’s see how we can do it for all of them in one command.

How to create a baseline

For that, we’ll use the following Gerrit command line: gerrit create-branch.
As we did before, we’ll apply this command inside a repo forall command, so our Gerrit command will be applied to all projects.

First, we need to decide on the baseline. For each release, Google releases a build code associated with a manifest branch. We’ll need that tag. build code / manifest branch pairs can be taken from here.

For this tutorial, we’ll take the following Lollipop build LMY48B, which suits Nexus 5 (Which I own).

According to google, the associated branch for it is: android-5.1.1_r3

Let us first init an empty repository with that branch, and of course, we’ll do it from our server.

repo init -u ssh://ramon@localhost:29418/android/platform/manifest -b android-5.1.1_r3

Great, don’t just do repo sync yet. we want to examine the manifest first.
Open the file .repo/manifests/default.xml

You should see the following lines in the beginning:

<remote name="aosp"
fetch=".." />
<default revision="refs/tags/android-5.1.1_r3"
sync-j="4" />

The default revision tells which tag to checkout for each project.

Let’s take the android-5.1.1_r3 tag and branch out of this tag to our own branch. This will be our baseline and we could push our changes directly to that branch.

To do so, let’s go back to the mirror on the server, we’ll need to do another repo batch command.

repo forall -c 'echo $REPO_PATH; ssh -p 29418 ramon@localhost gerrit create-branch android/$REPO_PATH my_baseline android-5.1.1_r3'

You should see sometimes the error message “fatal: invalid revision “android-5.1.1_r3“”. This is ok, it happens on project which don’t have the tag. This project are not included in the manifest we set our baseline on.

Now, when the new branches are let’s create our own manifest. We’ll go back to the place we initialized the repo.

This is a git repository, it’s actually a project, so let’s create our own branch.

git checkout -b my_manifest_branch

Edit default.xml

git add manifest.xml
git commit -m "My new manifest branch"

git push ssh://ramon@localhost:29418/android/platform/manifest HEAD:refs/for/my_baseline
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 341 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1)
remote: Processing changes: new: 1, refs: 1, done
remote: New Changes:
remote: http://localhost:8080/36 Set Manifest for myself
To ssh://ramon@localhost:29418/android/platform/manifest
* [new branch] HEAD -> refs/for/my_baseline

Done. now, open gerrit and merge that change. From now on, people should init the repo like this:

repo init -u ssh://ramon@localhost:29418/android/platform/manifest -b my_baseline


How to update gerrit

Let’s see now how we can update our gerrit and mirror and get upstream changes from Google.

This is very easy. go to the mirror folder and just do

repo sync -j6

And now, run the batch script we ran before.

$ repo forall -c 'echo $REPO_PATH; git push ssh://ramon@localhost:29418/android/$REPO_PATH +refs/heads/* +refs/tags/*;'

How to set Gerrit as a system service

Our setup can’t be finished until we know for certain that after reboot our gerrit server will start again.

To achieve that, we need to add Gerrit as a system service. I’ll show here how to do it in Ubuntu server (Debian like), for other dists like please find another tutorial online.
Basically, gerrit can be easily be installed by chkconfig. problem is that chkconfig is no longer supported in Ubuntu, which now uses upstart for it’s init process.
The right way, is to write a new Gerrit config for upstart and place it in /etc/init
Couldn’t find a it on the net, so I need to write it myself.
When it will be ready, I’ll post it in the blog.

Meanwhile, here’s an ugly, working way to achieve that.

I’m assuming that Gerrit installation resides on /opt/gerrit-review

echo "GERRIT_SITE=/opt/gerrit-review" >> /etc/default/gerritcodereview
ln -snf /opt/gerrit-review/bin/ /etc/init.d/gerrit
update-rc.d gerrit defaults


Linux Serviio start up script

I created my own Serviio service script, I’m sharing it for reference and free usage here.

If you don’t know Serviio and you need a Media Server in your home network, this is your best choice. check it out here.

Actually, you only need to alter “/etc/default/serviio” with your username and path to Serviio installation.

When you’re done with the scripts add it to rc using:

sudo update-rc.d serviio default


NAME="Serviio Media Server"
DAEMON="/opt/serviio/bin/"    ## Update this to point at serviio_root/bin/
SERVICE_ACCOUNT="nativeguru"            ## change to an appropriate username, DON'T RUN UNDER ROOT!


#! /bin/sh
# Provides:          serviio
# Required-Start:    $local_fs $remote_fs $network $syslog 
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Serviio daemon script
# Description:       This file is a daemon script for Serviio to be
#                    placed in /etc/init.d.

# Author: Ramon Fried <ramon.fried at gmail dot com>

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the script
DESC="Serviio Daemon"

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Exit if the default config file is missing
#[ -x /etc/default/$NAME ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

# Function that starts the daemon/service
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started
	start-stop-daemon --start --quiet --pidfile $PIDFILE -c "${SERVICE_ACCOUNT}" --exec $DAEMON --test > /dev/null \
		|| return 1
	start-stop-daemon --start --quiet --pidfile $PIDFILE -m -b -c  "${SERVICE_ACCOUNT}" --exec $DAEMON -- \
		|| return 2

# Function that stops the daemon/service
	# Return
	#   0 if daemon has been stopped
	#   1 if daemon was already stopped
	#   2 if daemon could not be stopped
	#   other if a failure occurred
	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE -c "${SERVICE_ACCOUNT}"
	[ "$RETVAL" = 2 ] && return 2
	# Wait for children to finish too if this is a daemon that forks
	# and if the daemon is only ever run from this initscript.
	# If the above conditions are not satisfied then add some other code
	# that waits for the process to drop all resources that could be
	# needed by services started subsequently.  A last resort is to
	# sleep for some time.
	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 -c "${SERVICE_ACCOUNT}" --exec $DAEMON
	[ "$?" = 2 ] && return 2
	# Many daemons don't delete their pidfiles when they exit.
	rm -f $PIDFILE
	return "$RETVAL"

case "$1" in
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
	log_daemon_msg "Restarting $DESC" "$NAME"
	case "$?" in
		case "$?" in
			0) log_end_msg 0 ;;
			1) log_end_msg 1 ;; # Old process is still running
			*) log_end_msg 1 ;; # Failed to start
		# Failed to stop
		log_end_msg 1
	echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
	exit 3


Linux Serviio start up script