Developer documentation

Subservices

Run a binary written in any language. ArozOS starts it, proxies it behind the same login and puts it on the desktop.

Deprecated

The subservice infrastructure is no longer maintained

Subservices still work as described on this page, but they get no new features and no fixes, and they may be removed in a future release. Do not start new projects on them. This page is kept for people who already run one. For new work, use one of these instead:

  • A WebApp: HTML and JavaScript in a folder, with server-side AGI scripts for files, databases and the rest of ArozOS.
  • A Container App: publish any web server, in Docker or anywhere else, through the ArozOS port and pin it to the desktop.

Overview

A program that ArozOS runs for you

A subservice is a separate program, usually a small web server, that ArozOS starts as a child process and reverse-proxies under its own address. It runs outside the core, so it can be written in Go, Rust, Python or anything else that can serve HTTP, and it can use native code that the sandboxed AGI JavaScript runtime cannot.
Once loaded, it registers as a normal module: it shows up on the desktop and in the start menu, and each user needs permission for it, just like a built-in WebApp.

Fun fact: the authenticated reverse proxy that was written for subservices is what Zoraxy, the standalone reverse proxy, grew out of.

Folder layout

Every subservice lives in its own folder below subservice/, next to the ArozOS binary. The executable is named after the folder, with the platform added.

subservice/
  demo/
    demo.exe              Windows
    demo_linux_amd64      Linux, x86-64
    demo_linux_arm64      Linux, ARM64
    demo_darwin_amd64     macOS, Intel
    moduleInfo.json       optional, see "Describing the module"
    web/                  anything the service serves

The names are <folder>.exe on Windows and <folder>_<GOOS>_<GOARCH> everywhere else. ArozOS starts the process inside the service folder, so relative paths such as ./web work.

What happens at startup

  • ArozOS looks for the executable of the current platform. A service without one is skipped.
  • It reads the module information from moduleInfo.json or, when there is none, runs <binary> -info, which must print the JSON object described below and exit.
  • It starts the binary again as a long-running server with the two flags below, and begins proxying to it.
-port is the next free port counting up from 12810. -rpt is the AGI gateway of this ArozOS, the address a subservice calls back (see below).
demo_linux_amd64 -port :12810 -rpt http://localhost:8080/api/ajgi/interface

At boot, a subservice whose module information cannot be read, or that asks for a reserved path, stops ArozOS from starting. When an admin starts a service later, the same problem only shows an error.

Describing the module

The module information is one JSON object. It is the same ModuleInfo that every WebApp registers with, so a subservice appears on the desktop like any other app.

{
  "Name": "Demo Subservice",
  "Desc": "A simple subservice showing how subservices work in ArozOS",
  "Group": "Development",
  "IconPath": "demo/icon.png",
  "Version": "0.0.1",
  "StartDir": "demo/home.html",
  "SupportFW": true,
  "LaunchFWDir": "demo/home.html",
  "SupportEmb": true,
  "LaunchEmb": "demo/embedded.html",
  "InitFWSize": [720, 480],
  "InitEmbSize": [720, 480],
  "SupportedExt": [".txt", ".md"]
}

The folder part of StartDir (here demo) becomes the proxy endpoint. It must not be empty or one of the reserved paths web, system, SystemAO, img, STDIN, STDOUT, STDERR, COM, ws, cluster and app.

Module fields

Name

Shown on the desktop. Access is granted by this name, so keep it unique.

Desc

A short description.

Group

Start menu category: Media, Office, Internet, Engineering, Development, System Tools or Utilities; anything else is listed under Other. Utilities and System Tools are open to every user, every other group needs a permission group grant.

IconPath

The icon, as a path the service serves, such as demo/icon.png.

Version

A version string such as 0.0.1.

StartDir

The page that opens in a full page window. Its folder is the proxy endpoint.

SupportFW, LaunchFWDir, InitFWSize

Open in a floating window: whether it is supported, the page to load and the starting size as [width, height].

SupportEmb, LaunchEmb, InitEmbSize

Embedded mode, which is what loads when a file is opened with the module. Same three settings.

SupportedExt

File extensions the module can open, such as [".txt", ".md"]. They let it become a default opener.

How requests reach the service

  • Only signed in users who have permission for the module get through. Everyone else receives a 404.
  • The endpoint folder is removed from the path: /demo/api/list?a=1 reaches the service as /api/list?a=1 and /demo/ as /. Pages should therefore use relative links, or links that begin with the endpoint folder: a link to /api/list would hit ArozOS itself.
  • ArozOS adds three request headers: aouser (the user name), aotoken (a token for that user) and X-Forwarded-Host (the host the browser used).
  • WebSocket connections are proxied as well. Those requests also carry A-Upgrade: websocket.
  • If the service stops answering, ArozOS logs it, kills the process and starts it again after 10 seconds.

The headers are only as trustworthy as the port. A service that listens on all interfaces lets anyone who can reach the port send aouser themselves, so bind to 127.0.0.1 or block the ports from 12810 upward from outside.

Calling back into ArozOS

A subservice reaches ArozOS functions through the AGI gateway, the address it received in -rpt. POST the user's token and a script. The script runs in the AGI runtime with that user's permissions, and whatever it sends with sendJSONResp is the response body.

func listDesktop(w http.ResponseWriter, r *http.Request) {
	token := r.Header.Get("aotoken")
	script := `
		requirelib("filelib");
		var list = filelib.glob("user:/Desktop/*");
		sendJSONResp(JSON.stringify(list));
	`
	// rpt is the value of the -rpt flag
	resp, err := http.PostForm(rpt, url.Values{
		"token":  {token},
		"script": {script},
	})
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadGateway)
		return
	}
	defer resp.Body.Close()
	w.Header().Set("Content-Type", "application/json")
	io.Copy(w, resp.Body)
}

The form fields are token (the aotoken header of the request) and script. The status code of the reply is not enough to know the script worked, so check what it returned.

A minimal service

This Go program answers -info, serves a web/ folder and has one API that greets the signed in user.

The complete example, with a web page, an AGI call, an icon and build scripts for every platform, is in the example repository.
package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"log"
	"net/http"
)

func main() {
	info := flag.Bool("info", false, "print the module information and exit")
	port := flag.String("port", ":8000", "listen address chosen by ArozOS")
	flag.String("rpt", "", "AGI gateway of ArozOS")
	flag.Parse()

	if *info {
		b, _ := json.Marshal(map[string]any{
			"Name":        "Demo Subservice",
			"Desc":        "A simple subservice",
			"Group":       "Development",
			"IconPath":    "demo/icon.png",
			"Version":     "0.0.1",
			"StartDir":    "demo/home.html",
			"SupportFW":   true,
			"LaunchFWDir": "demo/home.html",
			"InitFWSize":  []int{720, 480},
		})
		fmt.Println(string(b))
		return
	}

	http.HandleFunc("/whoami", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, "Hello", r.Header.Get("aouser"))
	})
	http.Handle("/", http.FileServer(http.Dir("./web")))
	log.Println("demo listening on", *port)
	log.Fatal(http.ListenAndServe(*port, nil))
}

Marker files

Empty files placed in the service folder change how it is started. They are read each time the service starts.

.disabled

Skip this service at boot. ArozOS writes it itself when an admin stops the service, and removes it when the service is started again.

.noproxy

Compatibility mode. The program is started without arguments and no proxy is set up, for software that was not written for ArozOS.

.startscript

Start start.sh (start.bat on Windows) from the service folder instead of the binary, for example to wrap a program that needs more arguments. The script receives -port and -rpt like a binary would.

.intport

Pass the port as 12810 instead of :12810, for programs that do not accept a leading colon.

moduleInfo.json

The module information as a file. When it exists, ArozOS does not run the binary with -info.

Managing services

Admins start and stop services from System Settings, which uses these endpoints:

  • /system/subservice/list lists the running and the disabled services.
  • /system/subservice/kill stops a service. Admin only, with the form field serviceDir set to its folder name.
  • /system/subservice/start starts one. Admin only, same field.

Start ArozOS with -disable_subservice to turn the whole feature off.

Already running a subservice?

The example repository is the best reference for how one is built. Keep in mind that the infrastructure is no longer maintained.