Skip to content

Commit

Permalink
pkg: rename handle_signal to graceful_shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Login <batazor@evrone.com>
  • Loading branch information
batazor committed Jul 2, 2023
1 parent efc99a3 commit 794357e
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 53 deletions.
20 changes: 20 additions & 0 deletions internal/pkg/graceful_shutdown/graceful_shutdown.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package graceful_shutdown

import (
"os"
"os/signal"
"syscall"
)

func GracefulShutdown() os.Signal {
shutdownSignals := make(chan os.Signal, 1)

signal.Notify(
shutdownSignals,
syscall.SIGINT,
syscall.SIGQUIT,
syscall.SIGTERM,
)

return <-shutdownSignals
}
18 changes: 0 additions & 18 deletions internal/pkg/handle_signal/handle_signal.go

This file was deleted.

4 changes: 2 additions & 2 deletions internal/services/api-gateway/gateways/cloudevents/cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
_ "github.com/shortlink-org/shortlink/internal/pkg/i18n"
api_di "github.com/shortlink-org/shortlink/internal/services/api-gateway/gateways/cloudevents/di"
)
Expand All @@ -33,7 +33,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

cleanup()

Expand Down
4 changes: 2 additions & 2 deletions internal/services/api-gateway/gateways/graphql/cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
_ "github.com/shortlink-org/shortlink/internal/pkg/i18n"
api_di "github.com/shortlink-org/shortlink/internal/services/api-gateway/gateways/graphql/di"
)
Expand All @@ -33,7 +33,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

cleanup()

Expand Down
4 changes: 2 additions & 2 deletions internal/services/api-gateway/gateways/grpc-web/cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
_ "github.com/shortlink-org/shortlink/internal/pkg/i18n"
api_di "github.com/shortlink-org/shortlink/internal/services/api-gateway/gateways/grpc-web/di"
)
Expand All @@ -33,7 +33,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

cleanup()

Expand Down
4 changes: 2 additions & 2 deletions internal/services/api-gateway/gateways/http-chi/cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
_ "github.com/shortlink-org/shortlink/internal/pkg/i18n"
api_di "github.com/shortlink-org/shortlink/internal/services/api-gateway/gateways/http-chi/di"
)
Expand All @@ -33,7 +33,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

cleanup()

Expand Down
4 changes: 2 additions & 2 deletions internal/services/api-gateway/gateways/ws/cmd/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
api_di "github.com/shortlink-org/shortlink/internal/services/api-gateway/gateways/ws/di"
)

Expand All @@ -23,7 +23,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

cleanup()

Expand Down
4 changes: 2 additions & 2 deletions internal/services/auth/cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
auth_di "github.com/shortlink-org/shortlink/internal/services/auth/di"
)

Expand All @@ -30,7 +30,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

cleanup()

Expand Down
7 changes: 4 additions & 3 deletions internal/services/bff-web/cmd/bff_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ package main
import (
"os"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
bff_web_di "github.com/shortlink-org/shortlink/internal/services/bff-web/di"
"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
bff_web_di "github.com/shortlink-org/shortlink/internal/services/bff-web/di"
)

func main() {
Expand All @@ -29,7 +30,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

cleanup()

Expand Down
4 changes: 2 additions & 2 deletions internal/services/billing/cmd/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
billing_di "github.com/shortlink-org/shortlink/internal/services/billing/di"
)

Expand All @@ -30,7 +30,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

cleanup()

Expand Down
7 changes: 4 additions & 3 deletions internal/services/csi/cmd/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"log"
"os"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
csi_di "github.com/shortlink-org/shortlink/internal/services/csi/di"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
csi_di "github.com/shortlink-org/shortlink/internal/services/csi/di"

csi_driver "github.com/shortlink-org/shortlink/internal/services/csi"
)

Expand Down Expand Up @@ -74,7 +75,7 @@ func main() {
s.Log.Info("success run CSI plugin")

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

// Stop the service gracefully.
cleanup()
Expand Down
7 changes: 4 additions & 3 deletions internal/services/link/cmd/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ package main
import (
"os"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
link_di "github.com/shortlink-org/shortlink/internal/services/link/di"
"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
link_di "github.com/shortlink-org/shortlink/internal/services/link/di"
)

func main() {
Expand All @@ -29,7 +30,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

cleanup()

Expand Down
7 changes: 4 additions & 3 deletions internal/services/logger/cmd/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ package main
import (
"os"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
logger_di "github.com/shortlink-org/shortlink/internal/services/logger/di"
"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
logger_di "github.com/shortlink-org/shortlink/internal/services/logger/di"
)

func main() {
Expand All @@ -29,7 +30,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

cleanup()

Expand Down
7 changes: 4 additions & 3 deletions internal/services/metadata/cmd/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ package main
import (
"os"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
metadata_di "github.com/shortlink-org/shortlink/internal/services/metadata/di"
"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
metadata_di "github.com/shortlink-org/shortlink/internal/services/metadata/di"
)

func main() {
Expand All @@ -29,7 +30,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

// Stop the service gracefully.
cleanup()
Expand Down
7 changes: 4 additions & 3 deletions internal/services/notify/cmd/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ package main
import (
"os"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
notify_di "github.com/shortlink-org/shortlink/internal/services/notify/di"
"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
notify_di "github.com/shortlink-org/shortlink/internal/services/notify/di"
)

func main() {
Expand All @@ -27,7 +28,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

// Stop the service gracefully.
cleanup()
Expand Down
7 changes: 4 additions & 3 deletions internal/services/wallet/cmd/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ package main
import (
"os"

"github.com/shortlink-org/shortlink/internal/pkg/handle_signal"
wallet_di "github.com/shortlink-org/shortlink/internal/services/wallet/di"
"github.com/spf13/viper"

"github.com/shortlink-org/shortlink/internal/pkg/graceful_shutdown"
wallet_di "github.com/shortlink-org/shortlink/internal/services/wallet/di"
)

func main() {
Expand All @@ -29,7 +30,7 @@ func main() {
}()

// Handle SIGINT, SIGQUIT and SIGTERM.
handle_signal.WaitExitSignal()
graceful_shutdown.GracefulShutdown()

cleanup()

Expand Down

0 comments on commit 794357e

Please sign in to comment.