Skip to content

Commit 02476a5

Browse files
committed
add restart service endpoint
1 parent cfb6140 commit 02476a5

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

docs/manual/api.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,22 @@ it means it can act like an access node to user private networks
153153

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

156-
### Reboot
156+
### Reboot Node
157157

158158
| command |body| return|
159159
|---|---|---|
160160
| `zos.admin.reboot` | - | - |
161161

162162
Stops all services then reboot the node
163163

164+
### Restart Service
165+
166+
| command |body| return|
167+
|---|---|---|
168+
| `zos.admin.reboot` | string | - |
169+
170+
Restarts a service running on the node
171+
164172
### List Physical Interfaces
165173

166174
| command |body| return|

pkg/zos_api/admin.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ import (
88
"github.com/threefoldtech/zos/pkg/zinit"
99
)
1010

11+
func (g *ZosAPI) adminRestartHandler(ctx context.Context, payload []byte) (interface{}, error) {
12+
var service string
13+
if err := json.Unmarshal(payload, &service); err != nil {
14+
return nil, fmt.Errorf("failed to decode input, expecting string: %w", err)
15+
}
16+
17+
zinit := zinit.Default()
18+
19+
if err := zinit.Stop(service); err != nil {
20+
return nil, err
21+
}
22+
23+
return nil, zinit.Start(service)
24+
}
25+
1126
func (g *ZosAPI) adminRebootHandler(ctx context.Context, payload []byte) (interface{}, error) {
1227
zinit := zinit.Default()
1328

pkg/zos_api/routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func (g *ZosAPI) SetupRoutes(router *peer.Router) {
4646
admin := root.SubRoute("admin")
4747
admin.Use(g.authorized)
4848
admin.WithHandler("reboot", g.adminRebootHandler)
49+
admin.WithHandler("restart", g.adminRestartHandler)
4950
admin.WithHandler("interfaces", g.adminInterfacesHandler)
5051
admin.WithHandler("set_public_nic", g.adminSetPublicNICHandler)
5152
admin.WithHandler("get_public_nic", g.adminGetPublicNICHandler)

0 commit comments

Comments
 (0)