daemon

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

background.go provides RunBackground, which re-spawns the current binary as a detached background process running "start --foreground". The parent returns immediately with the child's PID. Platform-specific process detachment (new session on Unix, DETACHED_PROCESS on Windows) is handled by setSysProcAttr defined in background_unix.go / background_windows.go.

Package daemon implements the main OpenCron daemon that orchestrates cron job scheduling, file system watching for hot-reload, and the Telegram bot. The Daemon struct wraps robfig/cron with SkipIfStillRunning to prevent overlapping job execution, manages job registration and atomic hot-reload, maintains a PID file for single-instance enforcement, opens the SQLite database, and handles graceful shutdown on SIGINT/SIGTERM.

service.go provides a system service wrapper using kardianos/service for running the OpenCron daemon as a Windows Service or systemd unit. It implements the service.Interface (Start/Stop) and exposes InstallService and UninstallService functions for managing the service lifecycle.

watcher.go implements a file system watcher using fsnotify for hot-reloading job configurations. It monitors the schedules directory for Write, Create, and Remove events on YAML files, debounces changes for 500ms, and triggers Daemon.Reload to re-register all jobs atomically. Stop uses sync.Once to prevent double-close panics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstallService

func InstallService() error

InstallService installs OpenCron as a system service.

func Run

func Run() error

Run starts the daemon in the foreground.

func RunBackground

func RunBackground() (int, error)

RunBackground re-launches the current binary with "start --foreground" as a detached child process and returns its PID. The caller should exit or return so the terminal is freed; the child continues running independently.

func UninstallService

func UninstallService() error

UninstallService removes the system service.

Types

type Daemon

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

Daemon manages the cron job lifecycle.

func (*Daemon) Reload

func (d *Daemon) Reload()

Reload reloads all job configurations.

type Watcher

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

Watcher watches the schedules directory for changes and triggers hot-reload.

func NewWatcher

func NewWatcher(dir string, d *Daemon) (*Watcher, error)

NewWatcher creates a file watcher for the schedules directory.

func (*Watcher) Start

func (w *Watcher) Start()

Start begins watching for file changes with debouncing.

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop stops the file watcher. Safe to call multiple times.

Jump to

Keyboard shortcuts

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