ota

package
v0.9.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 9 Imported by: 0

README

Over-the-air updates

Lots of maintainers run their needles on a bare metal machines. As long as this project is so frequently updated, it might be a good idea to let them update it without the hassle.

  • Enabled automatic time-based version check
  • Enabled application self-restart after it downloaded the update

Description

Support for the application self-update by downloading the latest release from the official repository.

Stay strong, be the first in line!

The version should be embedded in the binary during the build, see the build target in the Makefile.

Usage

Available flags
  -enable-self-update
        Enable the application automatic updates on the startup
  -restart-on-update
        Allows application to restart upon the successful update (ignored if auto-update is disabled) (default true)
  -self-update-check-frequency duration
        How often to run auto-update checks (default 24h0m0s)
  -skip-update-check-on-start
        Allows to skip the update check at the startup (usually set automatically by the previous version) (default false)

The default behavior if the self-update enabled:

* Check for the update
* If update is available - download it
   * If auto-restart is enabled
      * Notify the user that a newer version is available
      * Fork-Exec a new process (will have a different PID), add a flag to skip the version check upon startup
      * Stop the current process
   * If auto-restart is disabled - notify user that manual restart is required
* If update is NOT available - schedule the next check
Examples

To update your needle, start it with a flag -enable-self-update

./db1000n -enable-self-update
Advanced options

Start the needle with the self-update & self-restart

$ ./db1000n -enable-self-update
0000/00/00 00:00:00 main.go:82: DB1000n [Version: v0.6.4][PID=75259]
0000/00/00 00:00:00 main.go:166: Running a check for a newer version...
0000/00/00 00:00:00 main.go:176: Newer version of the application is found [0.7.0]
0000/00/00 00:00:00 main.go:177: What's new:
* Added some great improvements
* Added some spectacular bugs
0000/00/00 00:00:00 main.go:180: Auto restart is enabled, restarting the application to run a new version
0000/00/00 00:00:00 restart.go:45: new process has been started successfully [old_pid=75259,new_pid=75262]

# NOTE: Process 75259 exited, Process 75262 has started with a flag to skip version check on the startup

0000/00/00 00:00:00 main.go:82: DB1000n [Version: v0.7.0][PID=75262]
0000/00/00 00:00:00 main.go:155: Version update on startup is skipped, next update check is scheduled in 24h0m0s

Start the needle with the self-update but do not restart the process upon update (systemd friendly)

$ ./db1000n -enable-self-update -self-update-check-frequency=5m -restart-on-update=false
0000/00/00 00:00:00 main.go:82: DB1000n [Version: v0.6.4][PID=75320]
0000/00/00 00:00:00 main.go:166: Running a check for a newer version...
0000/00/00 00:00:00 main.go:176: Newer version of the application is found [0.7.0]
0000/00/00 00:00:00 main.go:177: What's new:
* Added some great improvements
* Added some spectacular bugs
0000/00/00 00:00:00 main.go:191: Auto restart is disabled, restart the application manually to apply changes!

References

  1. Graceful restart with zero downtime for TCP connection - https://github.com/Scalingo/go-graceful-restart-example
  2. Graceful restart with zero downtime for TCP connection (two variants) https://github.com/rcrowley/goagain
  3. Graceful restart with zero downtime for TCP connection (alternative) https://grisha.org/blog/2014/06/03/graceful-restart-in-golang

Documentation

Overview

Package ota [allows hot update and reload of the executable]

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version is a release version embedded into the app
	Version = "v0.0.1"
	// Repository to check for updates
	Repository = "Arriven/db1000n" // Could be changed via the ldflags
)

Functions

func WatchUpdates added in v0.8.3

func WatchUpdates(logger *zap.Logger, cfg *Config)

WatchUpdates performs OTA updates based on the config.

Types

type Config added in v0.8.3

type Config struct {
	// contains filtered or unexported fields
}

Config defines OTA parameters.

func NewConfigWithFlags added in v0.8.3

func NewConfigWithFlags() *Config

NewConfigWithFlags returns a Config initialized with command line flags.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL