-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #464 from essentialkaos/develop
Version 12.121.0
- Loading branch information
Showing
13 changed files
with
180 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
* + hash | ||
* + httputil | ||
* - initsystem | ||
* ! initsystem/sdnotify | ||
* + jsonutil | ||
* + knf | ||
* + knf/united | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package sdnotify | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
// // | ||
// Copyright (c) 2024 ESSENTIAL KAOS // | ||
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // | ||
// // | ||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
func ExampleConnect() { | ||
err := Connect() | ||
|
||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
Status("Loading data %d%%", 50) | ||
Ready() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Package sdnotify provides methods for sending notifications to systemd | ||
package sdnotify | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
// // | ||
// Copyright (c) 2024 ESSENTIAL KAOS // | ||
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // | ||
// // | ||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
) | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
var ( | ||
ErrNoSocket = fmt.Errorf("NOTIFY_SOCKET is empty") | ||
ErrNotConnected = fmt.Errorf("Not connected to socket") | ||
) | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
var conn net.Conn | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
// Connect connects systemd to socket | ||
func Connect() error { | ||
var err error | ||
|
||
socket := os.Getenv("NOTIFY_SOCKET") | ||
|
||
if err != nil { | ||
return ErrNoSocket | ||
} | ||
|
||
conn, err = net.Dial("unixgram", socket) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Can't connect to socket: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Notify sends provided message to systemd | ||
func Notify(msg string) error { | ||
if conn == nil { | ||
return ErrNotConnected | ||
} | ||
|
||
_, err := fmt.Fprint(conn, msg) | ||
|
||
return err | ||
} | ||
|
||
// Ready sends READY message to systemd | ||
func Ready() error { | ||
return Notify("READY=1") | ||
} | ||
|
||
// Reloading sends RELOADING message to systemd | ||
func Reloading() error { | ||
return Notify("RELOADING=1") | ||
} | ||
|
||
// Stopping sends STOPPING message to systemd | ||
func Stopping() error { | ||
return Notify("STOPPING=1") | ||
} | ||
|
||
// MainPID sends MAINPID message with PID to systemd | ||
func MainPID(pid int) error { | ||
return Notify(fmt.Sprintf("MAINPID=%d", pid)) | ||
} | ||
|
||
// ExtendTimeout sends EXTEND_TIMEOUT_USEC message to systemd | ||
func ExtendTimeout(sec float64) error { | ||
usec := uint(sec * 1_000_000) | ||
return Notify(fmt.Sprintf("EXTEND_TIMEOUT_USEC=%d", usec)) | ||
} | ||
|
||
// Status sends status message to systemd | ||
func Status(format string, a ...any) error { | ||
return Notify(fmt.Sprintf(format, a...)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//go:build windows || darwin | ||
// +build windows darwin | ||
|
||
// Package sdnotify provides methods for sending notifications to systemd | ||
package sdnotify | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
// // | ||
// Copyright (c) 2024 ESSENTIAL KAOS // | ||
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // | ||
// // | ||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
// ////////////////////////////////////////////////////////////////////////////////// // | ||
|
||
// ❗ Connect connects systemd to socket | ||
func Connect() error { | ||
panic("UNSUPPORTED") | ||
} | ||
|
||
// ❗ Notify sends provided message to systemd | ||
func Notify(msg string) error { | ||
panic("UNSUPPORTED") | ||
} | ||
|
||
// ❗ Ready sends READY message to systemd | ||
func Ready() error { | ||
panic("UNSUPPORTED") | ||
} | ||
|
||
// ❗ Reloading sends RELOADING message to systemd | ||
func Reloading() error { | ||
panic("UNSUPPORTED") | ||
} | ||
|
||
// ❗ Stopping sends STOPPING message to systemd | ||
func Stopping() error { | ||
panic("UNSUPPORTED") | ||
} | ||
|
||
// ❗ MainPID sends MAINPID message with PID to systemd | ||
func MainPID(pid int) error { | ||
panic("UNSUPPORTED") | ||
} | ||
|
||
// ❗ ExtendTimeout sends EXTEND_TIMEOUT_USEC message to systemd | ||
func ExtendTimeout(sec float64) error { | ||
panic("UNSUPPORTED") | ||
} | ||
|
||
// ❗ Status sends status message to systemd | ||
func Status(format string, a ...any) error { | ||
panic("UNSUPPORTED") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters