mirror of
https://github.com/rclone/rclone
synced 2024-11-23 00:06:55 +01:00
vendor: add github.com/okzk/sdnotify
This commit is contained in:
parent
6cc968b085
commit
0bfa29cbcf
8
Gopkg.lock
generated
8
Gopkg.lock
generated
@ -150,6 +150,12 @@
|
|||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "4ed959e0540971545eddb8c75514973d670cf739"
|
revision = "4ed959e0540971545eddb8c75514973d670cf739"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/okzk/sdnotify"
|
||||||
|
packages = ["."]
|
||||||
|
revision = "ed8ca104421a21947710335006107540e3ecb335"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/patrickmn/go-cache"
|
name = "github.com/patrickmn/go-cache"
|
||||||
@ -297,6 +303,6 @@
|
|||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "63cb991f1167ff9f656f36bf3bb59831cde5402d70729a5709088ae73388c69e"
|
inputs-digest = "f53d8d2a21862f225ba86e4575a68ce73db8957959ca507e5eded837c5dbcf73"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
@ -144,3 +144,7 @@
|
|||||||
[[constraint]]
|
[[constraint]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/patrickmn/go-cache"
|
name = "github.com/patrickmn/go-cache"
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/okzk/sdnotify"
|
||||||
|
21
vendor/github.com/okzk/sdnotify/LICENSE
generated
vendored
Normal file
21
vendor/github.com/okzk/sdnotify/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 okzk
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
15
vendor/github.com/okzk/sdnotify/README.md
generated
vendored
Normal file
15
vendor/github.com/okzk/sdnotify/README.md
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# sdnotify
|
||||||
|
|
||||||
|
sd_notify utility for golang.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
go get github.com/okzk/sdnotify
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
see [sample/main.go](sample/main.go)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
8
vendor/github.com/okzk/sdnotify/notify.go
generated
vendored
Normal file
8
vendor/github.com/okzk/sdnotify/notify.go
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// +build !linux
|
||||||
|
|
||||||
|
package sdnotify
|
||||||
|
|
||||||
|
func SdNotify(state string) error {
|
||||||
|
// do nothing
|
||||||
|
return nil
|
||||||
|
}
|
22
vendor/github.com/okzk/sdnotify/notify_linux.go
generated
vendored
Normal file
22
vendor/github.com/okzk/sdnotify/notify_linux.go
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package sdnotify
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SdNotify(state string) error {
|
||||||
|
name := os.Getenv("NOTIFY_SOCKET")
|
||||||
|
if name == "" {
|
||||||
|
return SdNotifyNoSocket
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := net.DialUnix("unixgram", nil, &net.UnixAddr{Name: name, Net: "unixgram"})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
_, err = conn.Write([]byte(state))
|
||||||
|
return err
|
||||||
|
}
|
47
vendor/github.com/okzk/sdnotify/sample/main.go
generated
vendored
Normal file
47
vendor/github.com/okzk/sdnotify/sample/main.go
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/okzk/sdnotify"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func reload() {
|
||||||
|
// Tells the service manager that the service is reloading its configuration.
|
||||||
|
sdnotify.SdNotifyReloading()
|
||||||
|
|
||||||
|
log.Println("reloading...")
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
log.Println("reloaded.")
|
||||||
|
|
||||||
|
// The service must also send a "READY" notification when it completed reloading its configuration.
|
||||||
|
sdnotify.SdNotifyReady()
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
log.Println("starting...")
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
log.Println("started.")
|
||||||
|
|
||||||
|
// Tells the service manager that service startup is finished.
|
||||||
|
sdnotify.SdNotifyReady()
|
||||||
|
|
||||||
|
sigCh := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
||||||
|
for sig := range sigCh {
|
||||||
|
if sig == syscall.SIGHUP {
|
||||||
|
reload()
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tells the service manager that the service is beginning its shutdown.
|
||||||
|
sdnotify.SdNotifyStopping()
|
||||||
|
|
||||||
|
log.Println("existing...")
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
11
vendor/github.com/okzk/sdnotify/sample/sample.service
generated
vendored
Normal file
11
vendor/github.com/okzk/sdnotify/sample/sample.service
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=sample
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=notify
|
||||||
|
ExecStart=/path/to/sample
|
||||||
|
ExecStop=/bin/kill -SIGTERM $MAINPID
|
||||||
|
ExecReload=/bin/kill -SIGHUP $MAINPID
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy = multi-user.target
|
21
vendor/github.com/okzk/sdnotify/util.go
generated
vendored
Normal file
21
vendor/github.com/okzk/sdnotify/util.go
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package sdnotify
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var SdNotifyNoSocket = errors.New("No socket")
|
||||||
|
|
||||||
|
func SdNotifyReady() error {
|
||||||
|
return SdNotify("READY=1")
|
||||||
|
}
|
||||||
|
|
||||||
|
func SdNotifyStopping() error {
|
||||||
|
return SdNotify("STOPPING=1")
|
||||||
|
}
|
||||||
|
|
||||||
|
func SdNotifyReloading() error {
|
||||||
|
return SdNotify("RELOADING=1")
|
||||||
|
}
|
||||||
|
|
||||||
|
func SdNotifyStatus(status string) error {
|
||||||
|
return SdNotify("STATUS=" + status)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user