graceful

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2022 License: Apache-2.0, MIT Imports: 9 Imported by: 0

Documentation

Overview

graceful package shutdown or reboot current process gracefully.

Copyright 2022 AndeyaLee. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const MinShutdownTimeout = 15 * time.Second

MinShutdownTimeout the default time-out period for the process shutdown.

Variables

This section is empty.

Functions

func AddInherited

func AddInherited(procFiles []*os.File, envs []*Env)

AddInherited adds the files and envs to be inherited by the new process. NOTE:

Only for reboot!
Windows system are not supported!

func GraceSignal

func GraceSignal()

GraceSignal open graceful shutdown or reboot signal.

func Reboot

func Reboot(timeout ...time.Duration)

Reboot all the frame process gracefully. NOTE: Windows system are not supported!

func SetLog

func SetLog(logger Logger)

SetLog resets logger. NOTE:

the logger is best to implement LoggerWithFlusher interface

func SetShutdown

func SetShutdown(timeout time.Duration, firstSweepFunc, beforeExitingFunc func() error)

SetShutdown sets the function which is called after the process shutdown, and the time-out period for the process shutdown. If 0<=timeout<5s, automatically use 'MinShutdownTimeout'(5s). If timeout<0, indefinite period. 'firstSweepFunc' is first executed. 'beforeExitingFunc' is executed before process exiting.

func Shutdown

func Shutdown(timeout ...time.Duration)

Shutdown closes all the frame process gracefully. Parameter timeout is used to reset time-out period for the process shutdown.

Types

type Env

type Env struct {
	K string
	V string
}

Env environment variable

type Logger

type Logger interface {
	// Infof logs a message using INFO as log level.
	Infof(format string, v ...interface{})
	// Errorf logs a message using ERROR as log level.
	Errorf(format string, v ...interface{})
}

Logger logger interface

type LoggerWithFlusher

type LoggerWithFlusher interface {
	Logger
	// Flush writes any buffered log to the underlying io.Writer.
	Flush() error
}

LoggerWithFlusher logger interface with flusher

Directories

Path Synopsis
Package inherit_net provides a family of Listen functions that either open a fresh connection or provide an inherited connection from when the process was started.
Package inherit_net provides a family of Listen functions that either open a fresh connection or provide an inherited connection from when the process was started.

Jump to

Keyboard shortcuts

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