DEV Community

Cover image for Update any application binary with this launcher!
Toby Chui
Toby Chui

Posted on

Update any application binary with this launcher!

Recently, I was working on a software updater for my project and I found that there is no easy way for OTA update that is ready to use and work cross platform. So I decided to write one that is so universal, it works on all kind of application binaries or even interpreted languages, which I later called it the "Automatic Update Launcher"

GitHub logo tobychui / Automatic-Update-Launcher

A general purpose updater for updating program binaries when update folder exists

Automatic Update Launcher

A general purpose updater for updating (web) applications server when update folder exists

What is this?

The Automatic update launcher only do one simple task, which is to upgrade your application to the latest version if it finds a later version of such application in the ./updates folder.

Its logic basically goes like this

  1. If updates/ folder exists
    1. Backup the old application files and data
    2. Copy the updates for application from updates folder to current folder
    3. Remove the updates folder
  2. Start the application
  3. Check for crash, if crash happens after update
    1. Restore the old application files and data
    2. Remove the backup folder
  4. Restart the whole process unless crash retry count > max allowed

Build

Require Go 1.17 or above

go mod tidy
go build

or just grab a copy from the release page.

Usage

Configure the launcher with launcher.json. See the example below

{
    "version":"1.0"
    "start":"helloworld*",
    "backup":

Current Implementations

❔ How normal Desktop Programs Updates

Most desktop applications will use some kind of updater to update the main program by start and detaching the updater and allow it to do its things. This work on most desktop platforms but it will not works with systemd where the PID of the running application is important. (i.e. cannot change or otherwise systemd will assume it is dead and try to restart it)
Image description

❔ How embedded devices do OTA updates

Embedded devices usually uses two partitions (one for current running application, the other one for writing update files to) and a bootloader to do the switching. One common example ESP8266 which some projects utilize its bootloader's feature to do OTA update via WiFi or Bluetooth.
Image description

🌟 How the Automatic Update Launcher (auLauncher) works 🌟

The auLauncher works in a much simpler way following the logic described in the following diagram.
Image description

and the configuration of each steps and file names can be changed easily in a json file located next to the launcher's executable. Here is an example for that:

{
    "version":"1.0",
    "start":"helloworld*",
    "backup": ["./*.config","./*.exe"],
    "verbal": true,
    "resp_port": 25576,
    "max_retry": 3,
    "crash_time": 3
}
Enter fullscreen mode Exit fullscreen mode

All arguments that passed to the launcher is then passed through to the main binary. So you can easily slide this in between your starting script and your target binary without the need for changing anything.

❓ How do my program update itself then?

It is simple! If you program want to update itself, just download the update files to the ./updates folder and exit itself with code 0. This way, the launcher will start overwriting the application files based on the defination in the json file and the contents in the ./updates folder and restart your application with given start path.

This method works for most Go compiled application, but in theory should also work with other compiled binaries and some interpret language like python with a correct starting bash / batch script.

If you are interested to know more, or just wanna try this launcher and make your application OTA update a new features, feel free to take a look at this repo and left some comments :))

GitHub logo tobychui / Automatic-Update-Launcher

A general purpose updater for updating program binaries when update folder exists

Automatic Update Launcher

A general purpose updater for updating (web) applications server when update folder exists

What is this?

The Automatic update launcher only do one simple task, which is to upgrade your application to the latest version if it finds a later version of such application in the ./updates folder.

Its logic basically goes like this

  1. If updates/ folder exists
    1. Backup the old application files and data
    2. Copy the updates for application from updates folder to current folder
    3. Remove the updates folder
  2. Start the application
  3. Check for crash, if crash happens after update
    1. Restore the old application files and data
    2. Remove the backup folder
  4. Restart the whole process unless crash retry count > max allowed

Build

Require Go 1.17 or above

go mod tidy
go build

or just grab a copy from the release page.

Usage

Configure the launcher with launcher.json. See the example below

{
    "version":"1.0"
    "start":"helloworld*",
    "backup":

Top comments (0)