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
- Variables
- func NeedUpdate(currentVersion, remoteVersion string, versionIsRequired bool) bool
- type GenericEventHandler
- type Launcher
- func (instance *Launcher) Error() error
- func (instance *Launcher) GoString() string
- func (instance *Launcher) IsKillable() bool
- func (instance *Launcher) Kill() error
- func (instance *Launcher) OnQuit(callback func(command string, pid int))
- func (instance *Launcher) OnStart(callback func(command string))
- func (instance *Launcher) OnStarted(callback func(command string, pid int))
- func (instance *Launcher) Output() string
- func (instance *Launcher) Pid() int
- func (instance *Launcher) Run(command string) error
- func (instance *Launcher) String() string
- func (instance *Launcher) Wait() error
- type LauncherQuitHandler
- type LauncherStartHandler
- type LauncherStartedHandler
- type PackageFile
- type Settings
- type TaskHandler
- type Updater
- func (instance *Updater) GetDirApp() string
- func (instance *Updater) GetDirStart() string
- func (instance *Updater) GetDirWork() string
- func (instance *Updater) GetProcessOutput() string
- func (instance *Updater) GetProcessPid() int
- func (instance *Updater) GetRoot() string
- func (instance *Updater) GetSettingKeepAlive() bool
- func (instance *Updater) GetSettingVersionFile() string
- func (instance *Updater) GetUid() string
- func (instance *Updater) GetVariable(name string) string
- func (instance *Updater) HasUpdates() bool
- func (instance *Updater) IsProcessRunning() bool
- func (instance *Updater) IsUpdating() bool
- func (instance *Updater) IsUpgradable(currentVersion, remoteVersion string) bool
- func (instance *Updater) OnError(handler UpdaterErrorHandler)
- func (instance *Updater) OnEvent(handler GenericEventHandler)
- func (instance *Updater) OnLaunchQuit(handler LauncherQuitHandler)
- func (instance *Updater) OnLaunchStart(handler LauncherStartHandler)
- func (instance *Updater) OnLaunchStarted(handler LauncherStartedHandler)
- func (instance *Updater) OnTask(handler TaskHandler)
- func (instance *Updater) OnUpgrade(handler UpdaterUpgradeHandler)
- func (instance *Updater) ReLaunch()
- func (instance *Updater) ReStart()
- func (instance *Updater) SetRoot(path string)
- func (instance *Updater) SetUid(uid string)
- func (instance *Updater) SetVariable(name, value string)
- func (instance *Updater) Settings() *Settings
- func (instance *Updater) Start() (updated bool, fromVersion string, toVersion string, files []string, err error)
- func (instance *Updater) Stop()
- func (instance *Updater) Wait()
- type UpdaterErrorHandler
- type UpdaterUpgradeHandler
Constants ¶
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 ¶
var (
ErrorMissingConfigurationParameter = errors.New("missing_configuration_parameter_error")
)
Functions ¶
func NeedUpdate ¶ added in v0.2.44
Types ¶
type GenericEventHandler ¶
type Launcher ¶
type Launcher struct {
// contains filtered or unexported fields
}
func NewLauncher ¶
func (*Launcher) IsKillable ¶
type LauncherQuitHandler ¶
type LauncherStartHandler ¶
type LauncherStartHandler func(command string)
type LauncherStartedHandler ¶
type PackageFile ¶
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 Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
func NewUpdater ¶
func NewUpdater(settings ...interface{}) *Updater
func (*Updater) GetDirStart ¶
func (*Updater) GetDirWork ¶
func (*Updater) GetProcessOutput ¶
func (*Updater) GetProcessPid ¶
func (*Updater) GetSettingKeepAlive ¶
func (*Updater) GetSettingVersionFile ¶
func (*Updater) GetVariable ¶
func (*Updater) HasUpdates ¶
func (*Updater) IsProcessRunning ¶
func (*Updater) IsUpdating ¶
func (*Updater) IsUpgradable ¶
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) SetVariable ¶
type UpdaterErrorHandler ¶
type UpdaterErrorHandler func(err string)