MCPcopy Index your code
hub / github.com/codemodus/sigmon

github.com/codemodus/sigmon @v2.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.1 ↗ · + Follow
49 symbols 154 edges 10 files 14 documented · 29%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

sigmon

go get -u github.com/codemodus/sigmon

Package sigmon simplifies os.Signal handling.

The benefits of this over a more simplistic approach are eased signal bypassability, eased signal handling replaceability, the rectification of system signal quirks, and operating system portability (Windows will ignore USR1 and USR2 signals, and some testing is bypassed).

Usage

type HandlerFunc
type Signal
type SignalMonitor
    func New(fn HandlerFunc) *SignalMonitor
    func (m *SignalMonitor) Set(fn HandlerFunc)
    func (m *SignalMonitor) Start()
    func (m *SignalMonitor) Stop()
type State
    func (s *State) Signal() Signal

Setup

import (
    "github.com/codemodus/sigmon/v2"
)

func main() {
    sm := sigmon.New(nil)
    sm.Start()

    // Do things which cannot be affected by OS signals other than SIGKILL...

    sm.Set(handle)

    // Do things which can be affected by handled OS signals...

    sm.Stop()
    // OS signals will be handled normally.
}

HandlerFunc

func handle(s *sigmon.State) {
    switch s.Signal() {
    case sigmon.SIGHUP:
        // reload
    case sigmon.SIGINT, sigmon.SIGTERM:
        // stop
    case sigmon.SIGUSR1, sigmon.SIGUSR2:
        // more
    }
}

Setup Elaborated

func main() {
    sm := sigmon.New(nil)
    sm.Start()

    db := newDataBase(creds)
    db.Migrate()

    app := newWebApp(db)
    app.ListenAndServe()

    sm.Set(func(s *sigmon.State) {
        switch s.Signal() {
        case sigmon.SIGHUP:
            app.Restart()
        default:
            app.Shutdown()
        }
    })

    app.Wait()
}

HandlerFunc Using syscall Signal Constants

func handle(s *sigmon.State) {
    switch syscall.Signal(s.Signal()) {
    case syscall.SIGHUP:
        // reload
    default:
        // stop
    }
}

More Info

Windows Compatibility

sigmon will run on Windows systems without error. In order for this to be, notifications of USR1 and USR2 signals are not wired up as they are not supported whatsoever in Windows. All tests work on *nix systems, but are not run on Windows. It is up to the user to assess whether their application is receiving INT, TERM, and, HUP signals properly along with what that may mean for the design of the affected system.

Documentation

View the GoDoc

Benchmarks

N/A

Extension points exported contracts — how you extend this code

HandlerFunc (FuncType)
HandlerFunc is used to communicate system signal handling behavior.
sigmon.go

Core symbols most depended-on inside this repo

Stop
called by 17
sigmon.go
Start
called by 8
sigmon.go
Signal
called by 6
sigmon.go
Set
called by 6
sigmon.go
set
called by 5
registry.go
New
called by 4
sigmon.go
loadBuffer
called by 4
registry.go
buffer
called by 4
registry.go

Shape

Function 25
Method 16
Struct 6
FuncType 1
TypeAlias 1

Languages

Go100%

Modules by API surface

sigmon.go14 symbols
registry.go8 symbols
example_test.go8 symbols
sigmon_test.go5 symbols
junction.go5 symbols
junction_test.go4 symbols
registry_test.go3 symbols
junction_windows.go1 symbols
junction_unix.go1 symbols

For agents

$ claude mcp add sigmon \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page