Skip to content

Commit

Permalink
Add NGINX reload and restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Joey de Vries committed Nov 21, 2024
1 parent 83511a6 commit 02f667b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 1 addition & 3 deletions cmd/ginfier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ func createHandler(c *gin.Context) {
return
}

// Reload NGINX
// Note: This requires sudo privileges or proper system configuration
// TODO: Implement NGINX reload
nginx.Reload()

response := config.APIResponse{
Code: "OK",
Expand Down
22 changes: 22 additions & 0 deletions internal/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package nginx

import (
"errors"
"fmt"
"os"
"os/exec"
)

func GetPath() (string, error) {
Expand All @@ -15,3 +17,23 @@ func GetPath() (string, error) {
}
return "", errors.New("unsupported os release")
}

func Restart() error {
// Execute systemctl restart nginx
cmd := exec.Command("systemctl", "restart", "nginx")
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("failed to restart Nginx: %s - %w", output, err)
}

return nil
}

func Reload() error {
// Execute systemctl reload nginx
cmd := exec.Command("systemctl", "reload", "nginx")
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("failed to reload Nginx: %s - %w", output, err)
}

return nil
}

0 comments on commit 02f667b

Please sign in to comment.