gg_updater

package
v0.2.36 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

README

Updater

Update and launch a program. Updater is a simple "live-update" utility that can update (searching on web for latest version) and launch a program.

When Updater starts, first read the latest version from remote "version.txt" file. If remote version is newer than the local version, Updater start download and install (unzip) new version. Finally, launch the program.

Optionally you can schedule remote check and auto-updates.

Start and Update

Updater standard behaviour is "update-and-start".

Every time you start a program using Updater, a version check is performed before launch your program.

Scheduled Checks

Scheduled checks keep your application updated.

At every update the program is stopped and restarted. Do not schedule updates if you do not want stop your program.

For scheduling tasks Updater uses: Scheduler

Configuration

Updater is fully configurable changing file updater.json.

{
  "version_file": "https://gianangelogeminiani.me/download/version.txt",
  "package_files": [
    {
      "file": "https://gianangelogeminiani.me/download/package.zip",
      "target": "./bin"
    }
  ],
  "command_to_run": "./bin/myservice",
  "scheduled_updates": [
    {
      "uid": "every_3_seconds",
      "start_at": "",
      "timeline": "second:3"
    }
  ]
}

Parameters

  • version_file: Path (relative or absolute) to text file containing latest version number.
  • package_files: Array of objects (PackageFile) to download and unzip (if archive). PackageFile contains "file" and "target" fields.
  • command_to_run: Command to run when screen launcher is active. Use this to run your program.

Variables

Some parameters (command_to_run, package_files.target) can contain variables.

  • $dir_home: Is replaced with Application absolute path.

Sample Code

    updater := gg_updater.NewUpdater()
	updater.Settings().VersionFile = "./versions/version.txt"
	updater.Settings().PackageFiles = make([]*lygo_updater.PackageFile, 0)
	updater.Settings().PackageFiles = append(updater.Settings().PackageFiles, &lygo_updater.PackageFile{
		File:   "./versions/test_fiber.zip",
		Target: "./versions_install",
	})
	updater.Settings().CommandToRun = "./versions_install/test_fiber"
	updater.OnError(func(err string) {
		fmt.Println("ERROR", err)
	})
	count:=0
	updater.OnUpgrade(func(fromVersion, toVersion string) {
		count++
		now := time.Now()
		t := fmt.Sprintf("%v:%v:%v", now.Hour(), now.Minute(), now.Second())
		fmt.Println("UPDATE", count, t, "\t" + fromVersion + " -> " + toVersion, "pid:", updater.GetProcessPid())
	})

    // use Start method to check for updates and go on
	// updater.Start()
    
    // use Wait method to Start and wait
    updater.Wait() 
    

Documentation

Index

Constants

View Source
const (
	VariableDirHome  = "$dir_home"  // root
	VariableDirStart = "$dir_start" // binary launch dir
	VariableDirApp   = "$dir_app"   // binary dir
	VariableDirWork  = "$dir_work"  // workspace

	DirStart = "start"
	DirApp   = "app"
	DirWork  = "*"
)

Variables

View Source
var (
	ErrorMissingConfigurationParameter = errors.New("missing_configuration_parameter_error")
)

Functions

This section is empty.

Types

type GenericEventHandler

type GenericEventHandler func(updater *Updater, eventName string, args []interface{})

type Launcher

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

func NewLauncher

func NewLauncher(keepHandle bool) *Launcher

func (*Launcher) Error

func (instance *Launcher) Error() error

func (*Launcher) GoString

func (instance *Launcher) GoString() string

func (*Launcher) IsKillable

func (instance *Launcher) IsKillable() bool

func (*Launcher) Kill

func (instance *Launcher) Kill() error

func (*Launcher) OnQuit

func (instance *Launcher) OnQuit(callback func(command string, pid int))

func (*Launcher) OnStart

func (instance *Launcher) OnStart(callback func(command string))

func (*Launcher) OnStarted

func (instance *Launcher) OnStarted(callback func(command string, pid int))

func (*Launcher) Output

func (instance *Launcher) Output() string

func (*Launcher) Pid

func (instance *Launcher) Pid() int

func (*Launcher) Run

func (instance *Launcher) Run(command string) error

func (*Launcher) String

func (instance *Launcher) String() string

func (*Launcher) Wait

func (instance *Launcher) Wait() error

Wait wait command terminated

type LauncherQuitHandler

type LauncherQuitHandler func(command string, pid int)

type LauncherStartHandler

type LauncherStartHandler func(command string)

type LauncherStartedHandler

type LauncherStartedHandler func(command string, pid int)

type PackageFile

type PackageFile struct {
	File   string `json:"file"`
	Target string `json:"target"`
}

type Settings

type Settings struct {
	Uid                 string                   `json:"uid"`
	KeepAlive           bool                     `json:"keep_alive"`            // launch again if program is closed
	VersionFileRequired bool                     `json:"version_file_required"` // if true, first start will update all if version file does not exists
	VersionFile         string                   `json:"version_file"`
	PackageFiles        []*PackageFile           `json:"package_files"`
	CommandToRun        string                   `json:"command_to_run"`
	ScheduledUpdates    []*gg_scheduler.Schedule `json:"scheduled_updates"`
	ScheduledRestart    []*gg_scheduler.Schedule `json:"scheduled_restart"`
	ScheduledTasks      []*gg_scheduler.Schedule `json:"scheduled_tasks"`
}

type TaskHandler

type TaskHandler func(taskUID string, payload map[string]interface{})

type Updater

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

func NewUpdater

func NewUpdater(settings ...interface{}) *Updater

func (*Updater) GetDirApp

func (instance *Updater) GetDirApp() string

func (*Updater) GetDirStart

func (instance *Updater) GetDirStart() string

func (*Updater) GetDirWork

func (instance *Updater) GetDirWork() string

func (*Updater) GetProcessOutput

func (instance *Updater) GetProcessOutput() string

func (*Updater) GetProcessPid

func (instance *Updater) GetProcessPid() int

func (*Updater) GetRoot

func (instance *Updater) GetRoot() string

func (*Updater) GetSettingKeepAlive

func (instance *Updater) GetSettingKeepAlive() bool

func (*Updater) GetSettingVersionFile

func (instance *Updater) GetSettingVersionFile() string

func (*Updater) GetUid

func (instance *Updater) GetUid() string

func (*Updater) GetVariable

func (instance *Updater) GetVariable(name string) string

func (*Updater) HasUpdates

func (instance *Updater) HasUpdates() bool

func (*Updater) IsProcessRunning

func (instance *Updater) IsProcessRunning() bool

func (*Updater) IsUpdating

func (instance *Updater) IsUpdating() bool

func (*Updater) IsUpgradable

func (instance *Updater) IsUpgradable(currentVersion, remoteVersion string) bool

func (*Updater) OnError

func (instance *Updater) OnError(handler UpdaterErrorHandler)

func (*Updater) OnEvent

func (instance *Updater) OnEvent(handler GenericEventHandler)

func (*Updater) OnLaunchQuit

func (instance *Updater) OnLaunchQuit(handler LauncherQuitHandler)

func (*Updater) OnLaunchStart

func (instance *Updater) OnLaunchStart(handler LauncherStartHandler)

func (*Updater) OnLaunchStarted

func (instance *Updater) OnLaunchStarted(handler LauncherStartedHandler)

func (*Updater) OnTask

func (instance *Updater) OnTask(handler TaskHandler)

func (*Updater) OnUpgrade

func (instance *Updater) OnUpgrade(handler UpdaterUpgradeHandler)

func (*Updater) ReLaunch

func (instance *Updater) ReLaunch()

func (*Updater) ReStart

func (instance *Updater) ReStart()

func (*Updater) SetRoot

func (instance *Updater) SetRoot(path string)

func (*Updater) SetUid

func (instance *Updater) SetUid(uid string)

func (*Updater) SetVariable

func (instance *Updater) SetVariable(name, value string)

func (*Updater) Settings

func (instance *Updater) Settings() *Settings

func (*Updater) Start

func (instance *Updater) Start() (updated bool, fromVersion string, toVersion string, files []string, err error)

Start run the update job and also check immediately for updates

func (*Updater) Stop

func (instance *Updater) Stop()

func (*Updater) Wait

func (instance *Updater) Wait()

type UpdaterErrorHandler

type UpdaterErrorHandler func(err string)

type UpdaterUpgradeHandler

type UpdaterUpgradeHandler func(fromVersion, toVersion string, files []string)

Jump to

Keyboard shortcuts

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