Documentation ¶
Index ¶
- Constants
- func GetAllUnitNames(u []Unit) []string
- func GetEnabledTimersDir(unitdir string) string
- func GetUnitNameFromFilename(filename string) string
- func ListFilesFromDirWithExtension(dir string, extension string) ([]string, error)
- func ListFilesFromDirsWithExtension(dirs []string, extension string) ([]string, error)
- func NextUnit(all []int, def int) (int, bool)
- func NextUnitAfter(all []int, after int) int
- func NextUnitWithoutDefault(all []int) int
- func ParseChainedNumbers(chained string) ([]int, error)
- func ParseSingleSplittedTimeSpan(digits int, unit string) (int, error)
- func ParseSystemdBool(text string) (bool, error)
- func ParseTimeSpan(text string) (time.Duration, error)
- func ParseWeekday(weekday string) (time.Weekday, error)
- func ParseWeekdays(weekdays string) ([]time.Weekday, error)
- type CalendarEvent
- type IniFile
- type IniKeyPair
- type Paths
- type Service
- type Timer
- func (timer Timer) Disable()
- func (timer Timer) Enable(unitDir string) error
- func (timer Timer) GetEnabled() (bool, error)
- func (timer Timer) GetLastRun() (time.Time, error)
- func (timer Timer) NextSince(since time.Time) (time.Time, error)
- func (timer *Timer) SetLastRun(t time.Time) error
- func (timer Timer) TriggerTimeOfBootSec() (time.Time, error)
- type Unit
- type UnitInfo
Constants ¶
const ( SystemdMicrosecond = 1 SystemdMillisecond = 1000 SystemdSecond = 1000000 SystemdMinute = 60000000 SystemdHour = 3600000000 SystemdDay = 86400000000 SystemdWeek = 604800000000 SystemdMonth = 2629800000000 SystemdYear = 31557600000000 )
Constants of systemd.time(7)#PARSING TIME SPANS time units.
Variables ¶
This section is empty.
Functions ¶
func GetAllUnitNames ¶
Gets all unit names from a slice of units.
func GetEnabledTimersDir ¶
Returns the directory where to look for unit files that are enabled in the specified unit directory.
Returns the unit dir with the sub directory "/timers.target.wants".
func GetUnitNameFromFilename ¶
Gets the unit name from a filename of .timer- and .service-files.
func ListFilesFromDirWithExtension ¶
Lists all files in the specific directory with a specific extension.
func ListFilesFromDirsWithExtension ¶
Lists all files in the specific directories with a specific extension.
func NextUnit ¶
Gives the next number of a slice of numbers (All) after a number (Default)
If no numbers are preferred (All empty) Default is returned ¶
Returned is the next number, and weather the next unit will be overfloused, because the next number is smaller than the Default
Used to find the next number of a unit.
func NextUnitAfter ¶
Gives the next number of a slice of numbers (All) after a number (After) If no numbers are preferred (All empty) After + 1 is returned Used to overflow a number.
func NextUnitWithoutDefault ¶
Gives the next number of a slice of numbers (All) without a default number
Used if the next number is known to overflow and therefore doesn't need a default.
func ParseChainedNumbers ¶
Returns real numbers from systemd's number chaining, like "1,3,5", "1..3", "1,3..5" or "*", to []int{1, 3, 5}, []int{1, 2, 3, []int{1, 3, 4, 5}, []int{} respectively.
func ParseSingleSplittedTimeSpan ¶
Parses a single time span unit into a time.Duration defined by systemd.time(7)#PARSING TIME SPANS.
func ParseSystemdBool ¶
Parses a boolean string into a boolean defined by systemd.syntax(7)#INTRODUCTION.
func ParseTimeSpan ¶
Parses a time span string into a time.Duration defined by systemd.time(7)#PARSING TIME SPANS.
func ParseWeekday ¶
Returns time.Weekday from systemd's weekdays definition.
Types ¶
type CalendarEvent ¶
type CalendarEvent struct { // The locations (timezone) in which the times of this object (below) are defined Location time.Location // Weekdays that the event should occur Weekdays []time.Weekday // Years that the event should occur Years []int // Months that the event should occur Months []time.Month // Days of the month, that the event should occur Days []int // Hours of the day, that the event should occur Hours []int // Minutes of the hour, that the event should occur Minutes []int // Seconds of the minute, that the event should occur Seconds []int // TODO: what is that? Empty bool }
Calendar event specified by systemd.time(7)#CALENDAR EVENTS
Calendar events may be used to refer to one or more points in time in a single expression.
Empty array means all values aka. no preference.
func NewCalendarEvent ¶
func NewCalendarEvent(calendar string) (CalendarEvent, error)
NewCalendarEvent creates a new CalendarEvent from a calendar string.
func (CalendarEvent) NextWithoutWeekdays ¶
func (event CalendarEvent) NextWithoutWeekdays(now time.Time) time.Time
NextWithoutWeekdays returns the next time of the event without considering weekdays
First it sets the units without considering other units Then if a overflow is found, it overflows the next unit and resets the previous units.
func (CalendarEvent) Normalize ¶
func (event CalendarEvent) Normalize() string
Normalize returns the calendar event in a normalized format.
type IniFile ¶
type IniFile struct { // All sections of the INI file. Sections map[string][]IniKeyPair }
Content of a systemd INI configuration file (like .service or .timer files).
func NewIniFile ¶
Reads a systemd INI configuration file and returns an IniFile object.
func (IniFile) GetValue ¶
Returns the value of a key in a section of an INI file, or a default value if the key is not found.
systemd's configuration format supports multiple values for a single key. If you need all values of a key, use GetValues() instead.
Often, multiple settings form a list, and setting to an empty value "resets", which means that previous assignments are ignored. If the key has multiple values, only the last value is returned.
func (IniFile) GetValues ¶
Returns the value(s) of a key in a section of an INI file, or a default value(s) if the key is not found.
systemd's configuration format supports multiple values for a single key, so this function returns a slice of strings. If the key only supports a single value, use GetValue() instead.
type IniKeyPair ¶
type IniKeyPair struct { // The key of the key-value pair. Key string // The value of the key-value pair. Value string }
A single key-value pair of an INI file.
type Paths ¶
type Paths struct { // Directory where to store stamp files // Stamps are used to store the last time a timer was executed StampDir string // Directories where to look for unit files (.service, .timer) UnitDirs []string }
Configuration where to look for unit directories and stamp files.
func NewSystemPaths ¶
func NewSystemPaths() Paths
Creates a new Paths object with default values for starting in system-mode.
func (*Paths) AddSystemSystemdPaths ¶
func (paths *Paths) AddSystemSystemdPaths()
Adds the default systemd unit directories in system-mode.
func (Paths) GetEnabledTimersDirs ¶
Returns all directories where to look for unit files that are enabled.
Returns each unit dir with the sub directory "/timers.target.wants".
type Service ¶
type Service struct { // "Unit" section of the service. UnitInfo // Path to the .service file. Path string // The name of the unit. // This is the name of the file without the extension. UnitName string // Options of the service: // Defined in systemd.service(5)#OPTIONS. Type string ExecStart []string }
A systemd.service(5) definition.
func NewService ¶
Loads a systemd service file and returns a Service struct.
type Timer ¶
type Timer struct { // "Unit" section of a .timer file. UnitInfo // Path to the .timer file. Path string // The filename of the file Filename string // The name of the unit. // This is the name of the file without the extension. Name string // Paths configured by the application Paths Paths // The unit directory where the file is located Dir string // The next time the timer will run Next time.Time // Weather this timer is enable to start on daemon startup. Enabled bool // Options of the timer: // Defined in systemd.timer(5)#OPTIONS. OnBootSec time.Duration OnCalendar CalendarEvent AccuracySec time.Duration RandomizedDelaySec time.Duration Persistent bool UnitName string }
A systemd.timer(5) definition.
func GetEnabledTimers ¶
Gets all enabled timers in Paths.
func NewTimer ¶
Loads a systemd timer file and returns a Timer struct. From systemd.timer(5)#OPTIONS.
func (Timer) Disable ¶
func (timer Timer) Disable()
Disables a timer from starting on daemon startup, by deleting every symlink in every enabled timers directories of Paths.
func (Timer) Enable ¶
Enables a timer to start on daemon startup, by creating a symlink in the enabled timers directory (either on unitDir or if unitDir is "", then the Unit dir of the timer).
func (Timer) GetEnabled ¶
Returns weather this timer is enabled to start on daemon startup.
func (Timer) GetLastRun ¶
Provides the time of the last run of a timer.
func (*Timer) SetLastRun ¶
Sets the time of the last run of a timer.
type Unit ¶
A systemd unit with a timer and a service.
Note that there may be multiple Unit structs for a single systemd unit, because each Unit object always holds a single Timer'.
func GetUnits ¶
Gets all units with timers in Paths.
It checks all .timer files in the unit directories, and then finds the corresponding .service file.
func GetUnitsFromTimers ¶
Gets for each timer their specific Unit (with .service files).
func GetUnitsWithEnabledTimers ¶
Gets all units in Paths, that have a timer enabled.
type UnitInfo ¶
type UnitInfo struct {
Description string
}
"Unit" section of a systemd files (.timer, .service). From systemd.unit(5)#[UNIT] SECTION OPTIONS.
func NewUnitInfo ¶
Creates a UnitInfo struct from an IniFile. From systemd.unit(5)#[UNIT] SECTION OPTIONS.