In a previous article I configured a headless Raspberry Pi for Wifi and SSH. Next, I’ll set up a personal Gogs server on it.
Change the Password
First things first, change the password for the pi
user to something different than raspberry
.
$ passwd
Changing password for pi.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Please tweet your new password to @quakkels /s
Arrange the Prerequisites
Next, I’ll make sure the prerequisites are set up. Since Raspbian is based on Debian I can use the Debian/Ubuntu commands. I’m skipping the database step because I’m happy with this Gogs instance using SQLite3.
$ sudo apt-get update
$ sudo apt-get install git
Before proceeding farther, I’m going to create a brand new user specifically for Gogs. This new user will be everything Gogs.
$ sudo adduser iamgogs
Note: If I were a more experienced Gogs administrator I would have created a user named
git
since that’s Gogs' best practice and it’s less work later on. Scripts and default configuration usegit
as the Gogs user by default.
Be prepared to have a password ready for the new iamgogs
user.
Add the iamgogs
user to the sudo group.
$ sudo usermod -aG sudo iamgogs
Now switch to the iamgogs
user with:
$ su - iamgogs
And test the sudo ability by running any command as sudo:
$ sudo pwd
Install Gogs from Binary
From here, I could install Go and proceed to install from source. But instead, to keep the number of steps to a minimum, I’m going to install from binary.
Being currently logged in as the iamgogs
user, I’ll use the wget
command to download the Raspberry PI build from this download page. Use wget
with the url for the binary built specifically for Raspberry PI.
$ wget {raspberrypibinaryurl}
Now that I’ve got it downloaded, I can unzip it using the unzip
command.
$ unzip {gogszipfilename}
If you run the ls
command you should see the new gogs
folder that was extracted into the iamgogs
home directory.
And now for something completely expected…
Configuring and Running Gogs on Raspberry PI
Running and configuring the Gogs server is handled by the Gogs install process. There’s lots of information online about manually creating and editing custom app.ini configuration file, but it looks like (for the most recent versions of Gogs) all I need to do is run the gogs
executable from the $HOME/gogs
folder with the web
parameter.
$ cd $HOME/gogs
$ ./gogs web
I saw server information appear in the console. Since my Raspberry Pi is set up for headless operation, I don’t have the benefit of being able to access Gogs via a graphical web browser over localhost. So, from my windows machine, I navigated to {IpAddressOfRPi}:3000 and was greeted by a pleasant installation form which I filled out. Upon submitting the form, I had an admin account and a functioning Gogs server.
I’m nearing the end of this Gogs journey, but I still need to set this up as a service running in the background. Otherwise I’m stuck with this SSH session running Gogs forever.
I was able to find some instructions for configuring a Gogs service with systemd that seemed straightforward enough.
Copy the systemd service file from Gogs to the appropriate folder
$ sudo cp /home/iamgogs/scripts/systemd/gogs.service /lib/systemd/system/gogs.service
Then I edited the new file.
$ sudo nano /lib/systemd/system/gogs.service
I updated the values for:
- User
- Group
- WorkingDirectory
- ExecStart
- Environment
Since my Gogs user is iamgogs
rather than git
I needed to make sure the paths and users got updated accordingly. Once the file is updated and saved I tested to make sure it was working with:
$ sudo systemctl start gogs.service
After switching over to my windows machine and confirming the site loads in the browser, I returned to my ssh session to make sure systemd will automatically start the Gogs service on reboot.
$ sudo systemctl enable gogs.service
And then a final test to make sure Gogs will start automatically when the RPi boots:
$ sudo reboot
Lo and behold, it works.
Please share this post with a friend, and subscribe to get notified of new posts.
Comments may be sent to blog@quakkels.com.