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"
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
- If updates/ folder exists
- Backup the old application files and data
- Copy the updates for application from updates folder to current folder
- Remove the updates folder
- Start the application
- Check for crash, if crash happens after update
- Restore the old application files and data
- Remove the backup folder
- 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)
โ 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.
๐ How the Automatic Update Launcher (auLauncher) works ๐
The auLauncher works in a much simpler way following the logic described in the following diagram.
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
}
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 :))
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
- If updates/ folder exists
- Backup the old application files and data
- Copy the updates for application from updates folder to current folder
- Remove the updates folder
- Start the application
- Check for crash, if crash happens after update
- Restore the old application files and data
- Remove the backup folder
- 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)