vc

package module
v0.0.0-...-ecafc04 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

README

vc

Maintainability Rating Security Rating Technical Debt

vc is a cloud-init-alike tool for running a script once, and only once, to bootstrap a server. Unlike cloud-init, or similar tools, it is distributed as a statically compiled binary and does sod-all beyond run a script and store the output.

Running

This tool can either be invoked directly on the CLI as per:

$ vc run some-job.toml

Where some-job.toml is a file following the below spec.

It can also be run as a vinit job with a job such as this.

Job Spec

The following sample job is a good jumping off point:

name = "My simple vc script"
description = "Run a single script to say hello <3"

[script]
interpreter = "/bin/sh"
body = '''
#!/usr/bin/env bash
#

set -axe

echo "Hello from vc!"
'''

The most important section is the [script] section. It has the following keys:

  1. interpreter - this must be set; this tool expects an interpreter to be set to encourage clear, easily grokkable scripts
  2. body - a script which can be run via the interpretter.
  3. url - vc can also download a script to run

Only one of body or url can be included.

Jobs can be validated with:

$ vc validate some-job.yaml

Other commands

$ vc

Usage:
  vc [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  run         Run a vc script
  status      Show the status of either the specified script, or all scripts
  validate    Validate a vc config is correct
  version     Return server and client version information

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingScript      = fmt.Errorf("missing script section")
	ErrMissingInterpreter = fmt.Errorf("interpreter is either empty or unset")
	ErrUrlOrBodyOnly      = fmt.Errorf("only one of url or body may be set at once")
	ErrUrlAndBodyUnset    = fmt.Errorf("either script url or body must be set")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Name        string    `toml:"name"`
	Description string    `toml:"description"`
	Script      *Script   `toml:"script"`
	Finaliser   Finaliser `toml:"finaliser"`

	Sum string `toml:"-"`
}

func LoadConfig

func LoadConfig(fn string) (c Config, err error)

func (Config) Finalise

func (c Config) Finalise() error

type Database

type Database map[string]Script

hash to Script map

func LoadDatabase

func LoadDatabase(fn string) (d Database, err error)

load from file

func (Database) WriteDatabase

func (d Database) WriteDatabase(fn string) (err error)

type Finaliser

type Finaliser uint8
const (
	Finaliser_Nothing Finaliser = iota
	Finaliser_Reboot
	Finaliser_Shutdown
)

func (*Finaliser) UnmarshalText

func (f *Finaliser) UnmarshalText(text []byte) (err error)

type Script

type Script struct {
	Interpreter *string `toml:"interpreter"`
	URL         *string `toml:"url"`
	Body        *string `toml:"body"`

	RunningState ScriptRunningState `toml:"-" hash:"-"`
	Logs         []string           `toml:"-" hash:"-"`
	Error        string             `toml:"-" hash:"-"`
	RunAt        time.Time          `toml:"-" hash:"-"`
}

func (*Script) Run

func (s *Script) Run() (err error)

func (Script) Validate

func (s Script) Validate() error

type ScriptRunningState

type ScriptRunningState uint8
const (
	ScriptRunningState_NotStarted ScriptRunningState = iota
	ScriptRunningState_Started
	ScriptRunningState_Success
	ScriptRunningState_Failure
)

func (ScriptRunningState) String

func (s ScriptRunningState) String() string

Directories

Path Synopsis
bin
cmd

Jump to

Keyboard shortcuts

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