Cutting GitHub out of the loop

The recent curtailing of the popular BitBucket repository service* made me re-think my method of code deployment. Instead of using GitHub Actions or other proprietary service as my sole method of pushing code to my own server, I am cutting GitHub out of the loop and going direct.

*Bitbucket used to have no storage limit – now it’s 1GB for the free version. I had 14GB already on there!! GitHub will do this too at some point, no doubt..

SSH to the rescue

It turns out that pushing directly to your own VPS via ssh is not only supported by git, it is easy, fast and effective. I made my server re-load the web based code automatically (for me Flask) whenever I push. Here are the commands.

1. Set up bare git repository on VPS

mkdir -p /srv/git/myproject.git
cd /srv/git/myproject.git
git init --bare

2. Set up automatic update

create hooks/post-receive:

#!/bin/bash
GIT_WORK_TREE=/var/www/myproject git checkout -f main

make hooks/post-receive executable:

chmod +x /srv/git/myproject.git/hooks/post-receive

3. Add server as a remote

on your local machine:

git remote add server username@your-server-ip:/srv/git/myproject.git

(origin is still set to github, for backup)

4. Push code

git push server main

That’s it! Simple

Now I push main to the server and it deploys. There is much more to look at – the hooks are pretty powerful, you can do a bunch of stuff like update database, re-start web service and more whenever post is received.

Note: Permissions

/srv/git I gave user ownership of:

sudo chown -R username:username /srv/git

Bonus: restarting services with sudo

Allow your command to run as root in the /etc/sudoers file:

visudo
# add a line to the file
username ALL=(ALL) NOPASSWD: /usr/sbin/service myproject restart

Add restart command to hooks/post-receive file:

#!/bin/bash
GIT_WORK_TREE=/var/www/myproject git checkout -f main
echo "Restarting myproject service"
/usr/bin/sudo /usr/sbin/service myproject restart

Now when you push to server the service will automatically restart (and you get a message in the terminal).

Ubuntu Snap update SPOILED the World Cup

Goodbye Ubuntu, Goodbye Snaps

I missed two goals in the World Cup Finals because of this. It’s not the first time Snap has been a problem, but it’s most definitely the last straw.

What happened?

I was happily watching the second half of the Fifa World Cup Final, using “ShowMax” – a South African paid streaming platform, on Firefox. All of a sudden the screen freezes and the Firefox Snap decides to update. I couldn’t even close the window to open up Chromium.

In a panic I force shut down the laptop but somehow the boot-up wasn’t recognizing my hard drive anymore?? I don’t know what happened there, it works now, maybe I pressed the power button too many times – I was IN A HURRY.

I ended up watching the rest of the game on my phone.

Go Argentina! If my team hadn’t won I would have probably been even more pissed.

It’s the last straw Ubuntu – I have heard that Snaps have added an “Experimental” option to ignore updates but that’s not good enough. I’m moving to something that gives me full control. You can say what you like about me – It’s my fault for using the “Schedule updates for Sunday night” option and forgetting about it, or not using the new “Ignore updates” feature I only found out about on Reddit last week, but I’m done.

From now on, I love Arch

I am going back to Arch. My computer is my computer, and I don’t care anymore how much work it takes, I’m going to take charge so nothing like this ever happens again.

Look forward to a follow-up article where I rant about annoying Arch flaws and insane breaking changes in updates. \s


Update: Wow I actually made the front page of hacker news! Lots of discussion on the topic here: https://news.ycombinator.com/item?id=34041272

Upgrading DigitalOcean Ubuntu Droplet from 20.04 to 22.04

The problem

Recently I found out that PHP 7.4 is going to reach End Of Life at the end of November, 2022. This was an unfortunate situation considering I have several websites running on a couple of Ubuntu Server 20.04 DigitalOcean Droplets. It’s unfortunate because I found out that the only supported version of PHP for Ubuntu Server 20.04 is the soon to be obsolete version 7.4.

The Solution

There are two ways to do this – upgrade PHP via a PPA on Ubuntu 20.04, or upgrade Ubuntu to 22.04. I already upgraded my desktop without any issues, so I went with the latter option.

I will outline the procedure I used below. It went without a hitch, apart from having to do it twice due to a broken WordPress plug-in. I am embarrassed to admit that the plug-in was my own creation (in my defense I am not a PHP developer)

  1. Check all WordPress plug-ins for compatibility with PHP 8.1
  2. Create a snapshot of the Droplet
  3. Use the snapshot to create a new Droplet with the same specs as the old one.
  4. Power on the new server, login and proceed to upgrade to 22.04. I used screen to keep the upgrade process alive in case of ssh dropout.
  5. Once this process is completed, you still need to switch the version of PHP that Apache is using (I’m not sure if this is necessary for Nginx). It was something like:
    sudo a2dismod php7.4
    sudo a2enmod php8.1
    sudo service apache2 restart
  6. In the control panel, switch over your website’s DNS to point to the new domain. Depending on TTL this can take a while to propagate – I did mine one at a time and checked them with the ping command.
    ping circusscientist.com – returns the IP address
  7. If anything went wrong, it’s easy to switch back to the old 20.04, so I left that running for a few days. Worpress.org has some great articles here and here which I sometimes use to help with troubleshooting
  8. Finally, switch off the old 20.04 server and remember to delete it (keep the snapshot, though, just in case!)

postmarketOS first look

At home we have a bunch of old Android devices and laptops. The laptops all have some version of Linux running on them by now, but so far I have only had limited use for the oldest Android devices. I have an old S3 mini for example which has a great screen, but unfortunately LineageOS (the Android Upgrade) latest version available is Nougat, and that runs rather slowly. Besides, I already have two Android devices working with later versions.

PostmarketOS is a fairly new project with the goal of porting Alpine Linux (really small) with mainline kernel to ALL Android devices. Also you can run all types of UI on top of postmarketOS for example Plasma Mobile. I just wanted to see if I could have a device with WiFi which I could use to run some Bash scripts, c programs and possibly Python.

Here is how it works:

  1. You need a computer running linux – install the pmbootstrap program
  2. put phone into fastboot mode – making sure to follow instructions on postmarketOS wiki – S3 mini page was here
  3. after following the install guide (really comprehensive and simple), and choosing the kernel (mainline or the old one from Android), the Desktop (mate, xfce, plasma mobile, and many more), just run the install scripts
  4. ssh into phone via usb (or just use the phone touch screen)
  5. to install any program (from alpine linux) type apk add <program>
  6. a good one to have is corekeyboard (onscreen keyboard for phone)

So here it is then: Mate desktop running on postmarketOS in my S3 mini. (not mainline kernel though):

This is my phone screen now. The menu works and everything! (date and time no)

So far I have not been able to get WiFi working, or Bluetooth, however there is an option to share the laptop internet via USB, so I can still install programs. I installed gcc and compiled and ran a c program, and of course a shell script. This is really a great project and worth checking out if you have an old phone or two lying around.