Setting up GitBucket on Raspberry Pi 3 with an Ubuntu Server 15.10.3 image
With multiple Raspberry Pis around the house, it was time for me to setup a Git server to synchronise the source codes residing on my development laptop with those that are deployed on my Raspberry Pi servers.
As I am using GitHub at my workplace, I seek to emulate similar development operations at home. GitBucket seems to be an ideal candidate for my home Git server since it comes as a war file having API compatibility with GitHub.
Since I had created a LEMP server on my Raspberry Pi 3 with on Ubuntu Server 15.10.3, it makes sense for me to setup my GitBucket server on it.
This post describes how I setup GitBucket on my Raspberry Pi 3 with an Ubuntu Server 15.10.3 image. To make this post complete, the first seven steps are taken from previous posts.
Getting the hardware
The hardware that I used for this setup is as follows:
- A Raspberry Pi 3 motherboard
- A PiBlox LEGO® Compatible Case
- A SanDisk Ultra 32GB microSDHC UHS-I Card with Adapter
As my laptop comes with a SD card reader, I did not have to get a SD card reader.
Getting the Ubuntu Server 15.10.3 image for my Raspberry Pi 3 onto the micro SD card
After I got the hardware that I needed, the next step was to get the Ubuntu Server 15.10.3 image for my Raspberry Pi 3. The awesome folks at Ubuntu Pi Flavour Maker had made a few variations of Ubuntu images available for me to download.
I downloaded a copy of the Ubuntu Server Standard 15.10.3 image onto my windows machine via torrent.
Booting into Ubuntu Server 15.10.3 on my Raspberry Pi 3
Once Win32 Disk Imager completed writing the Ubuntu Server 15.10.3 image onto my SanDisk microSD card, I removed it from my SD card reader and inserted it to the SD card slot on the Raspberry Pi 3 motherboard. Note that unlike the Raspberry Pi 2, the microSD slot of the Raspberry Pi 3 motherboard is not a spring loaded one. This means that you just push to insert your microSD card and pull to remove your microSD card.
I then attached my trusty mouse, keyboard, monitor, a RJ45 network cable from my DLink router and my old samsung charger to my Raspberry Pi 3 motherboard. After turning on the power, the login screen appears. The default username is 'ubuntu' and the password is 'ubuntu'.
Adding a new user
I do not like a default username for my web server, even though it is not going to be used as the production server. Hence, I first added a new user via the command as follows:
sudo adduser techcoil
I then went through the following Q and As:
Adding user `techcoil' ... Adding new group `techcoil' (1000) ... Adding new user `techcoil' (1000) with group `techcoil' ... Creating home directory `/home/techcoil' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for techcoil Enter the new value, or press ENTER for the default Full Name : Techcoil Room Number : #1234 Work Phone : 12345678 Home Phone : 12345678 Other : 12345678
After I had created my new user account, I proceeded to add it to the sudo group so that I was able to continue with installing the necessary software:
sudo adduser techcoil sudo
Deleting the default user
Once I had created my user, I proceeded to delete the default user.
I first restarted the server:
After the server booted up again, I logged in with my new user.
Once I had logged into the server, I typed the following in the terminal to delete the default user:
sudo deluser --remove-home ubuntu
Resizing the file system of my Ubuntu Server 15.10.3 image to utilize the entire microSD card space on my Raspberry Pi 3
By default, the Ubuntu Server 15.10.3 image does not utilize the entire microSD card space on my Raspberry Pi 3.
Therefore, I proceeded on to resize the file system of my Ubuntu Server 15.10.3 image to utilize the entire microSD card space on my Raspberry Pi 3.
Adding swap space to my Ubuntu Server 15.10.3 image
1 GB of ram is not going to be enough to run GitBucket alongside the other pieces that run the WordPress instance on my Raspberry Pi 3. As such, I also went on to add swap space to the Ubuntu Server 15.10.3 image so as to complement the 1GB of ram on my Raspberry Pi 3.
Installing Java 8
The GitBucket version that I had downloaded runs on Java 8 and above. With that, I installed Oracle Java 8:
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get -y install oracle-java8-installer
Prior to installing Oracle Java 8, I had tried OpenJDK 8. However, the performance of OpenJDK 8 on my Raspberry Pi was sluggish. Switching to Oracle Java 8 made my Java programs run faster on my Raspberry Pi 3.
Installing Tomcat 8
After I had installed Java 8, I went ahead to install Tomcat 8:
sudo apt-get install tomcat8
The installation script also created the user 'tomcat8' and the user group 'tomcat8'. To verify the install, I accessed
192.168.0.200:8080 with my browser, where
192.168.0.200 is the ip address of my Raspberry Pi 3. My Raspberry Pi 3 returned the following response body to my browser:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Apache Tomcat</title> </head> <body> <h1>It works !</h1> <p>If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!</p> <p>This is the default Tomcat home page. It can be found on the local filesystem at: <code>/var/lib/tomcat8/webapps/ROOT/index.html</code></p> <p>Tomcat8 veterans might be pleased to learn that this system instance of Tomcat is installed with <code>CATALINA_HOME</code> in <code>/usr/share/tomcat8</code> and <code>CATALINA_BASE</code> in <code>/var/lib/tomcat8</code>, following the rules from <code>/usr/share/doc/tomcat8-common/RUNNING.txt.gz</code>.</p> <p>You might consider installing the following packages, if you haven't already done so:</p> <p><b>tomcat8-docs</b>: This package installs a web application that allows to browse the Tomcat 8 documentation locally. Once installed, you can access it by clicking <a href="docs/">here</a>.</p> <p><b>tomcat8-examples</b>: This package installs a web application that allows to access the Tomcat 8 Servlet and JSP examples. Once installed, you can access it by clicking <a href="examples/">here</a>.</p> <p><b>tomcat8-admin</b>: This package installs two web applications that can help managing this Tomcat instance. Once installed, you can access the <a href="manager/html">manager webapp</a> and the <a href="host-manager/html">host-manager webapp</a>.</p> <p>NOTE: For security reasons, using the manager webapp is restricted to users with role "manager-gui". The host-manager webapp is restricted to users with role "admin-gui". Users are defined in <code>/etc/tomcat8/tomcat-users.xml</code>.</p> </body> </html>
This told me that my Tomcat 8 was successfully installed on my Raspberry Pi 3.
Configuring Tomcat 8
After Tomcat 8 was successfully installed, the next step was to configure Tomcat 8.
To do so, I create a
setenv.sh in the /usr/share/tomcat8/bin directory:
sudo nano /usr/share/tomcat8/bin/setenv.sh
Setting JAVA_HOME in setenv.sh
One of the configurations was to tell Tomcat 8 where to look for the copy of Java 8 that was installed earlier.
To do so, I include the following content inside
Getting Tomcat 8 to use a larger heap size
By default, my Tomcat 8 was using a maximum size of 128MB of memory on my Raspberry Pi 3 as the heap size.
Since, I have more memory to spare on my Raspberry Pi 3, I went on to get my Tomcat 8 to use more heap size.
To do so, I include the following content inside
export JAVA_OPTS="-Dfile.encoding=UTF-8 -Xms128m -Xmx512m"
This will result in my Tomcat 8 server to use a minimum heap size of 128 MB and a maximum heap size of 512 MB when it needs to.
Getting Tomcat 8 to take the configurations
Once I was done with the configurations, I saved
After that, I made it executable:
sudo chmod +x /usr/share/tomcat8/bin/setenv.sh
and restarted my Tomcat 8 server for it to take the configuration changes:
sudo systemctl restart tomcat8.service
Creating the directory for GitBucket to use for persistence
GitBucket will use the
/usr/share/tomcat8/.gitbucket directory for data persistence. Since the
/usr/share/tomcat8 directory does not belong to the tomcat8 user, I proceeded to create the
.gitbucket folder and change its owner to the tomcat8 user:
sudo mkdir /usr/share/tomcat8/.gitbucket sudo chown tomcat8:tomcat8 /usr/share/tomcat8/.gitbucket
Downloading a copy of the GitBucket war file
Before downloading a copy of the GitBucket war file, I first stop my Tomcat 8 service:
sudo systemctl stop tomcat8.service
After configuring a user to access host-manager webapp, I continued on to download a copy of GitBucket 4.2 into the
webapp directory of my Tomcat 8:
cd /var/lib/tomcat8/webapps sudo wget https://github.com/gitbucket/gitbucket/releases/download/4.2/gitbucket.war
Accessing GitBucket on my Raspberry Pi 3
Once the downloading of gitbucket.war had been completed, I proceeded to start my Tomcat 8 again:
sudo systemctl start tomcat8.service
After my Tomcat 8 successfully started GitBucket, I accessed
http://192.168.0.200:8080/gitbucket with my browser and was greeted with the following screen:
Once I saw this screen, I clicked on the sign in button at the top right corner and enter 'root' as both the username and password. That enabled me to proceed on with administration matters, such as adding new users, removing the root user and adding new repositories for my codes.
Buying the Raspberry Pi 3 hardware to host your GitBucket
If you do not have the Raspberry Pi 3 hardware mentioned in this post yet, you may want to purchase them from Amazon. Simply click on the button below to add the Raspberry Pi 3 hardware to your cart. You may remove anything that you already have or replace some of the hardware with other hardware.