services

package
v0.1.0-preview Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package services is the resource module for managing already-running services on a remote VM. Sibling to install (which CREATES) and deploy (which DEPLOYS).

Wraps three distinct server endpoints:

  • Container lifecycle: POST /api/v2/tenant/container/{start,stop,remove} (JSON body)
  • Container status: POST /api/v2/tenant/docker/container/status (JSON body)
  • Host actions: POST /api/v2/tenant/services/action (multipart form, whitelisted action keys)

Maps 1:1 to the `vxcli services` command surface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionResult

type ActionResult struct {
	Success bool                   `json:"success"`
	Action  string                 `json:"action"`
	Output  string                 `json:"output"`
	Message string                 `json:"message"`
	Error   string                 `json:"error,omitempty"`
	Raw     map[string]interface{} `json:"-"`
}

ActionResult is the JSON envelope every admin-action endpoint returns.

type Client

type Client struct {
	T              *transport.Transport
	NodeURL        string
	AuthedUsername string
}

Client is the entry point. Construct via the parent SDK client:

c.Services()

Methods are concurrency-safe via the shared Transport.

func (*Client) List

func (c *Client) List(ctx context.Context, ssh SSH) (*ActionResult, error)

List returns the docker ps -a output for the host. Wraps the list_docker_containers admin action.

func (*Client) Logs

func (c *Client) Logs(ctx context.Context, ssh SSH, unit string) (*ActionResult, error)

Logs tails journalctl logs for a systemd unit (NOT for a docker container). The server template runs `journalctl -u <unit> -n 50`, falling back to /var/log/<unit> if the unit isn't registered.

func (*Client) Remove

func (c *Client) Remove(ctx context.Context, ssh SSH, containerName string) (*LifecycleResult, error)

Remove (stop + delete) a container by name on the target VM. Destructive — wrap in your own confirmation prompt.

func (*Client) Restart

func (c *Client) Restart(ctx context.Context, ssh SSH, containerName string) (*LifecycleResult, error)

Restart is a convenience: Stop, then Start. The server has no native restart endpoint for containers; we chain.

func (*Client) Start

func (c *Client) Start(ctx context.Context, ssh SSH, containerName string) (*LifecycleResult, error)

Start a stopped container by name on the target VM.

func (*Client) Status

func (c *Client) Status(ctx context.Context, ssh SSH, name string) (*StatusResult, error)

Status inspects a single container by name (or all containers if name == ""). Endpoint: POST /api/v2/tenant/docker/container/status

func (*Client) Stop

func (c *Client) Stop(ctx context.Context, ssh SSH, containerName string) (*LifecycleResult, error)

Stop a running container by name on the target VM.

func (*Client) VM

func (c *Client) VM() *VMClient

VM exposes host-level operations under c.Services().VM().

type ContainerSummary

type ContainerSummary struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Image  string `json:"image"`
	Status string `json:"status"`
	Ports  string `json:"ports"`
}

ContainerSummary mirrors the docker ps summary the server returns.

type LifecycleResult

type LifecycleResult struct {
	Success     bool                   `json:"success,omitempty"`
	Message     string                 `json:"message,omitempty"`
	ContainerID string                 `json:"container_id,omitempty"`
	Removed     bool                   `json:"removed,omitempty"`
	Raw         map[string]interface{} `json:"-"`
}

LifecycleResult is the JSON envelope every /container/{action} endpoint returns. Most fields are optional; raw is preserved for debugging.

type SSH

type SSH struct {
	Host          string
	User          string
	KeyPairName   string
	WorkspaceUser string
	Organization  string
}

SSH is the common SSH target. Same shape as install.SSH / deploy.SSH — every method here accepts it. KeyPairName resolves against your workspace Vault on the tenant node.

type StatusResult

type StatusResult struct {
	Success    bool                   `json:"success"`
	Hostname   string                 `json:"hostname"`
	Total      int                    `json:"total"`
	Containers []ContainerSummary     `json:"containers"`
	Raw        map[string]interface{} `json:"-"`
}

StatusResult is the response shape of /docker/container/status.

type VMClient

type VMClient struct {
	T              *transport.Transport
	NodeURL        string
	AuthedUsername string
}

VMClient — host-level operations. Reachable via Client.VM().

func (*VMClient) Disk

func (vm *VMClient) Disk(ctx context.Context, ssh SSH) (*ActionResult, error)

Disk diagnostics — df -hT plus largest dirs.

func (*VMClient) DiskCleanup

func (vm *VMClient) DiskCleanup(ctx context.Context, ssh SSH) (*ActionResult, error)

DiskCleanup — apt autoremove + apt clean + journalctl vacuum.

func (*VMClient) DockerCleanup

func (vm *VMClient) DockerCleanup(ctx context.Context, ssh SSH) (*ActionResult, error)

DockerCleanup — docker system prune -af --volumes.

func (*VMClient) KillPort

func (vm *VMClient) KillPort(ctx context.Context, ssh SSH, port string) (*ActionResult, error)

KillPort — kill the process bound to <port> on the remote host.

func (*VMClient) ListContainers

func (vm *VMClient) ListContainers(ctx context.Context, ssh SSH) (*ActionResult, error)

ListContainers — docker ps -a (alias of Client.List for naming convenience).

func (*VMClient) ListServices

func (vm *VMClient) ListServices(ctx context.Context, ssh SSH) (*ActionResult, error)

ListServices — running systemd services.

func (*VMClient) Memory

func (vm *VMClient) Memory(ctx context.Context, ssh SSH) (*ActionResult, error)

Memory diagnostics — free -h plus /proc/meminfo head.

func (*VMClient) Reboot

func (vm *VMClient) Reboot(ctx context.Context, ssh SSH) (*ActionResult, error)

Reboot the remote host (sudo reboot). Destructive.

func (*VMClient) RestartDocker

func (vm *VMClient) RestartDocker(ctx context.Context, ssh SSH) (*ActionResult, error)

RestartDocker — sudo systemctl restart docker.

func (*VMClient) Shutdown

func (vm *VMClient) Shutdown(ctx context.Context, ssh SSH) (*ActionResult, error)

Shutdown the remote host (sudo shutdown -h +1). Destructive.

func (*VMClient) StopService

func (vm *VMClient) StopService(ctx context.Context, ssh SSH, unit string) (*ActionResult, error)

StopService — sudo systemctl stop <unit>.

Jump to

Keyboard shortcuts

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