Skip to content

Commit

Permalink
add restart service endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Dec 22, 2024
1 parent 2ee7e4a commit 030081c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docs/manual/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,22 @@ it means it can act like an access node to user private networks

The next set of commands are ONLY possible to be called by the `farmer` only.

### Reboot
### Reboot Node

| command |body| return|
|---|---|---|
| `zos.admin.reboot` | - | - |

Stops all services then reboot the node

### Restart Service

| command |body| return|
|---|---|---|
| `zos.admin.reboot` | string | - |

Restarts a service running on the node

### List Physical Interfaces

| command |body| return|
Expand Down
15 changes: 15 additions & 0 deletions pkg/zos_api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ import (
"github.com/threefoldtech/zos/pkg/zinit"
)

func (g *ZosAPI) adminRestartHandler(ctx context.Context, payload []byte) (interface{}, error) {
var service string
if err := json.Unmarshal(payload, &service); err != nil {
return nil, fmt.Errorf("failed to decode input, expecting string: %w", err)
}

zinit := zinit.Default()

if err := zinit.Stop(service); err != nil {
return nil, err
}

return nil, zinit.Start(service)
}

func (g *ZosAPI) adminRebootHandler(ctx context.Context, payload []byte) (interface{}, error) {
zinit := zinit.Default()

Expand Down
1 change: 1 addition & 0 deletions pkg/zos_api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (g *ZosAPI) SetupRoutes(router *peer.Router) {
admin := root.SubRoute("admin")
admin.Use(g.authorized)
admin.WithHandler("reboot", g.adminRebootHandler)
admin.WithHandler("restart", g.adminRestartHandler)
admin.WithHandler("interfaces", g.adminInterfacesHandler)
admin.WithHandler("set_public_nic", g.adminSetPublicNICHandler)
admin.WithHandler("get_public_nic", g.adminGetPublicNICHandler)
Expand Down

0 comments on commit 030081c

Please sign in to comment.