index.html 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <!doctype html>
  2. <!-- Generated by scripts/sitegen. Edit the files there and run `go run .`; changes made here are overwritten. -->
  3. <html lang="zh-Hans" data-theme="light" class="accent-makers">
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
  7. <title>子服务(已弃用)— ArozOS</title>
  8. <meta name="description" content="ArozOS 子服务的运行方式:以任何语言编写的可执行文件,由 ArozOS 启动、反向代理并放上桌面。子服务架构已弃用,不再维护。">
  9. <link rel="canonical" href="https://os.aroz.org/zh-cn/subservice/">
  10. <link rel="alternate" hreflang="en" href="https://os.aroz.org/subservice/" data-href="../../subservice/">
  11. <link rel="alternate" hreflang="zh-Hant" href="https://os.aroz.org/zh-tw/subservice/" data-href="../../zh-tw/subservice/">
  12. <link rel="alternate" hreflang="zh-Hans" href="https://os.aroz.org/zh-cn/subservice/" data-href="./">
  13. <link rel="alternate" hreflang="ja" href="https://os.aroz.org/ja/subservice/" data-href="../../ja/subservice/">
  14. <link rel="alternate" hreflang="x-default" href="https://os.aroz.org/subservice/">
  15. <script>
  16. (function () {
  17. var d = document.documentElement, s = null, l = null;
  18. d.className += " js";
  19. try { s = localStorage.getItem("aroz-theme"); l = localStorage.getItem("aroz-lang"); } catch (e) {}
  20. var p = s === "light" || s === "dark" ? s : "auto";
  21. d.setAttribute("data-theme-pref", p);
  22. d.setAttribute("data-theme", p === "auto" ? (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light") : p);
  23. if (l || d.lang !== "en" || /bot|crawl|spider/i.test(navigator.userAgent)) return;
  24. var want = "", list = navigator.languages || [navigator.language || ""];
  25. for (var i = 0; i < list.length && !want; i++) {
  26. var c = (list[i] || "").toLowerCase();
  27. if (c.indexOf("zh") === 0) want = /hant|tw|hk|mo/.test(c) ? "zh-Hant" : "zh-Hans";
  28. else if (c.indexOf("ja") === 0) want = "ja";
  29. else if (c.indexOf("en") === 0) want = "en";
  30. }
  31. try { localStorage.setItem("aroz-lang", want || "en"); } catch (e) { return; }
  32. if (!want || want === "en") return;
  33. var alt = document.querySelector('link[rel="alternate"][hreflang="' + want + '"]');
  34. if (alt) location.replace(alt.getAttribute("data-href") + location.hash);
  35. })();
  36. </script>
  37. <meta name="color-scheme" content="light dark">
  38. <meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)">
  39. <meta name="theme-color" content="#000000" media="(prefers-color-scheme: dark)">
  40. <meta property="og:type" content="website">
  41. <meta property="og:site_name" content="ArozOS">
  42. <meta property="og:title" content="子服务(已弃用)— ArozOS">
  43. <meta property="og:description" content="ArozOS 子服务的运行方式:以任何语言编写的可执行文件,由 ArozOS 启动、反向代理并放上桌面。子服务架构已弃用,不再维护。">
  44. <meta property="og:url" content="https://os.aroz.org/zh-cn/subservice/">
  45. <meta property="og:image" content="https://os.aroz.org/img/og.png">
  46. <meta property="og:locale" content="zh_CN">
  47. <meta name="twitter:card" content="summary_large_image">
  48. <link rel="icon" href="../../img/favicon.png">
  49. <link rel="apple-touch-icon" href="../../img/apple-touch-icon.png">
  50. <link rel="stylesheet" href="../../assets/site.css?v=0b27a21e">
  51. <script src="../../assets/site.js?v=0b27a21e" defer></script>
  52. </head>
  53. <body>
  54. <a class="skip" href="#main">跳至主要内容</a>
  55. <header class="nav" id="nav">
  56. <div class="nav-in">
  57. <a class="brand" href="../" aria-label="ArozOS"><svg class="logo" viewBox="0 0 256 256" aria-hidden="true"><rect class="logo-bg" width="256" height="256" rx="58"/><path class="logo-fg" d="M70 58h116l-58 70zM128 128l58 70H70z"/></svg><span>ArozOS</span></a>
  58. <nav class="nav-links" aria-label="主菜单">
  59. <a href="../desktop.html">桌面</a>
  60. <a href="../media.html">影音</a>
  61. <a href="../office.html">办公</a>
  62. <a href="../ai.html">AI</a>
  63. <a href="../makers.html">创客</a>
  64. <a href="../storage.html">存储</a>
  65. <a href="../server.html">服务器</a>
  66. </nav>
  67. <div class="nav-tools">
  68. <div class="pop" data-pop>
  69. <button type="button" class="icon-btn" aria-haspopup="menu" aria-expanded="false" aria-label="语言" title="语言"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.5 2.7 3.8 5.7 3.8 9s-1.3 6.3-3.8 9c-2.5-2.7-3.8-5.7-3.8-9S9.5 5.7 12 3z"/></svg></button>
  70. <div class="pop-menu" role="menu"><a role="menuitemradio" href="../../subservice/" hreflang="en" lang="en" data-lang="en" aria-checked="false">English</a><a role="menuitemradio" href="../../zh-tw/subservice/" hreflang="zh-Hant" lang="zh-Hant" data-lang="zh-Hant" aria-checked="false">繁體中文</a><a role="menuitemradio" href="./" hreflang="zh-Hans" lang="zh-Hans" data-lang="zh-Hans" aria-checked="true">简体中文</a><a role="menuitemradio" href="../../ja/subservice/" hreflang="ja" lang="ja" data-lang="ja" aria-checked="false">日本語</a></div>
  71. </div>
  72. <div class="pop" data-pop>
  73. <button type="button" class="icon-btn theme-btn" aria-haspopup="menu" aria-expanded="false" aria-label="外观" title="外观"><span class="ti-light"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2.5v2M12 19.5v2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M2.5 12h2M19.5 12h2M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4"/></svg></span><span class="ti-dark"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20.5 14.5A8.5 8.5 0 0 1 9.5 3.5a8.5 8.5 0 1 0 11 11z"/></svg></span><span class="ti-auto"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8.5"/><path d="M12 3.5a8.5 8.5 0 0 1 0 17z" fill="currentColor"/></svg></span></button>
  74. <div class="pop-menu" role="menu"><button type="button" role="menuitemradio" data-theme-set="light" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2.5v2M12 19.5v2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M2.5 12h2M19.5 12h2M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4"/></svg><span>浅色</span></button><button type="button" role="menuitemradio" data-theme-set="dark" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20.5 14.5A8.5 8.5 0 0 1 9.5 3.5a8.5 8.5 0 1 0 11 11z"/></svg><span>深色</span></button><button type="button" role="menuitemradio" data-theme-set="auto" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8.5"/><path d="M12 3.5a8.5 8.5 0 0 1 0 17z" fill="currentColor"/></svg><span>自动</span></button></div>
  75. </div>
  76. <a class="btn primary sm nav-dl" href="../download.html">下载</a>
  77. <button type="button" class="icon-btn menu-btn" aria-expanded="false" aria-controls="sheet" aria-label="菜单"><span class="mi-open"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 9h16M4 15h16"/></svg></span><span class="mi-close"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M6 6l12 12M18 6L6 18"/></svg></span></button>
  78. </div>
  79. </div>
  80. <div class="sheet" id="sheet">
  81. <nav class="sheet-links" aria-label="主菜单">
  82. <a href="../">概览</a>
  83. <a href="../desktop.html">桌面</a>
  84. <a href="../media.html">影音</a>
  85. <a href="../office.html">办公</a>
  86. <a href="../ai.html">AI</a>
  87. <a href="../makers.html">创客</a>
  88. <a href="../storage.html">存储</a>
  89. <a href="../server.html">服务器</a>
  90. <a href="../download.html">下载</a>
  91. </nav>
  92. <div class="sheet-ctl">
  93. <p class="ctl-label">语言</p>
  94. <div class="seg lang-seg" role="menu"><a role="menuitemradio" href="../../subservice/" hreflang="en" lang="en" data-lang="en" aria-checked="false">English</a><a role="menuitemradio" href="../../zh-tw/subservice/" hreflang="zh-Hant" lang="zh-Hant" data-lang="zh-Hant" aria-checked="false">繁體中文</a><a role="menuitemradio" href="./" hreflang="zh-Hans" lang="zh-Hans" data-lang="zh-Hans" aria-checked="true">简体中文</a><a role="menuitemradio" href="../../ja/subservice/" hreflang="ja" lang="ja" data-lang="ja" aria-checked="false">日本語</a></div>
  95. <p class="ctl-label">外观</p>
  96. <div class="seg" role="menu"><button type="button" role="menuitemradio" data-theme-set="light" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2.5v2M12 19.5v2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M2.5 12h2M19.5 12h2M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4"/></svg><span>浅色</span></button><button type="button" role="menuitemradio" data-theme-set="dark" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20.5 14.5A8.5 8.5 0 0 1 9.5 3.5a8.5 8.5 0 1 0 11 11z"/></svg><span>深色</span></button><button type="button" role="menuitemradio" data-theme-set="auto" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8.5"/><path d="M12 3.5a8.5 8.5 0 0 1 0 17z" fill="currentColor"/></svg><span>自动</span></button></div>
  97. </div>
  98. </div>
  99. </header>
  100. <main id="main">
  101. <section class="hero">
  102. <div class="wrap hero-head">
  103. <p class="eyebrow rv">开发者文档</p>
  104. <h1 class="hero-title rv" style="--d:1"><span class="grad">子服务</span></h1>
  105. <p class="hero-sub rv" style="--d:2">用任何语言编写的可执行文件,由 ArozOS 启动、以同一套登录反向代理,并放上桌面。</p>
  106. </div>
  107. </section>
  108. <section class="notice-sec">
  109. <div class="wrap narrow">
  110. <div class="notice rv" role="note">
  111. <div class="notice-ic"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M10.3 4.2L2.8 17.5A2 2 0 0 0 4.5 20.5h15a2 2 0 0 0 1.7-3L13.7 4.2a2 2 0 0 0-3.4 0z"/><path d="M12 9.5v4.2"/><path d="M12 17h.01"/></svg></div>
  112. <div class="notice-body">
  113. <p class="notice-tag">已弃用</p>
  114. <h2>子服务架构不再维护</h2>
  115. <p>子服务仍可按本页所述运行,但不会再有新功能或修复,并可能在今后的版本中移除。请勿以子服务开始新项目;本页仅为已在使用的人保留。新的开发请改用以下方式:</p>
  116. <ul><li><strong>WebApp</strong>:文件夹内的 HTML 与 JavaScript,搭配服务器端 AGI 脚本访问文件、数据库与 ArozOS 的其他功能。</li><li><strong>Container App</strong>:把 Docker 或其他地方运行的任何网页服务器,通过 ArozOS 的端口发布并固定到桌面。</li></ul>
  117. <div class="btns"><a class="btn primary" href="../makers.html"><span>WebApp 与 AGI</span></a><a class="btn secondary" href="../server.html"><span>Container Apps</span></a></div>
  118. </div>
  119. </div>
  120. </div>
  121. </section>
  122. <section class="doc-sec" id="overview">
  123. <div class="wrap narrow">
  124. <div class="doc-head rv">
  125. <p class="eyebrow">概览</p>
  126. <h2 class="doc-title">由 ArozOS 为你运行的程序</h2>
  127. </div>
  128. <div class="doc-item rv">
  129. <div class="doc-text">子服务是一个独立的程序,通常是小型网页服务器。ArozOS 会把它当作子进程启动,并在自己的地址下做反向代理。它在内核之外运行,因此可以用 Go、Rust、Python 或任何能提供 HTTP 的语言编写,也能使用沙盒化的 AGI JavaScript 运行环境做不到的原生代码。</div>
  130. </div>
  131. <div class="doc-item rv">
  132. <div class="doc-text">加载后,它会注册为普通模块:出现在桌面与开始菜单,每位用户都需要获得权限,与内置的 WebApp 相同。</div>
  133. <p class="note"><strong>小知识:</strong>为子服务而写的、带身份验证的反向代理,后来长成了独立的反向代理 <a href="https://zoraxy.aroz.org">Zoraxy</a>。</p>
  134. </div>
  135. </div>
  136. </section>
  137. <section class="doc-sec" id="layout">
  138. <div class="wrap narrow">
  139. <div class="doc-head rv">
  140. <h2 class="doc-title">文件夹结构</h2>
  141. <p class="lead">每个子服务都放在 ArozOS 可执行文件旁 <code>subservice/</code> 之下自己的文件夹中。可执行文件以文件夹命名,并加上平台名称。</p>
  142. </div>
  143. <div class="doc-item rv">
  144. <div class="cmd"><pre><code>subservice/
  145. demo/
  146. demo.exe Windows
  147. demo_linux_amd64 Linux, x86-64
  148. demo_linux_arm64 Linux, ARM64
  149. demo_darwin_amd64 macOS, Intel
  150. moduleInfo.json optional, see &#34;Describing the module&#34;
  151. web/ anything the service serves</code></pre><button type="button" class="copy" data-copy aria-label="复制" title="复制"><span class="c-copy"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M5.5 15H5a1.5 1.5 0 0 1-1.5-1.5V5A1.5 1.5 0 0 1 5 3.5h8.5A1.5 1.5 0 0 1 15 5v.5"/></svg></span><span class="c-done"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span></button></div>
  152. <p class="note">Windows 上为 <code>&lt;文件夹&gt;.exe</code>,其他平台为 <code>&lt;文件夹&gt;_&lt;GOOS&gt;_&lt;GOARCH&gt;</code>。ArozOS 在该服务的文件夹内启动进程,因此 <code>./web</code> 这类相对路径可以直接使用。</p>
  153. </div>
  154. </div>
  155. </section>
  156. <section class="doc-sec" id="startup">
  157. <div class="wrap narrow">
  158. <div class="doc-head rv">
  159. <h2 class="doc-title">启动时会发生什么</h2>
  160. </div>
  161. <div class="doc-item rv">
  162. <ul class="doc-list"><li>ArozOS 查找当前平台的可执行文件;没有的服务会被跳过。</li><li>从 <code>moduleInfo.json</code> 读取模块信息;若没有该文件,则运行 <code>&lt;可执行文件&gt; -info</code>,它必须打印出下方所述的 JSON 对象后退出。</li><li>再次以下列两个参数启动该可执行文件,作为持续运行的服务器,并开始对它做代理。</li></ul>
  163. </div>
  164. <div class="doc-item rv">
  165. <div class="doc-text"><code>-port</code> 是从 <code>12810</code> 起算的下一个可用端口。<code>-rpt</code> 是这个 ArozOS 的 AGI 网关,子服务通过它回调 ArozOS(见下文)。</div>
  166. <div class="cmd"><pre><code>demo_linux_amd64 -port :12810 -rpt http://localhost:8080/api/ajgi/interface</code></pre><button type="button" class="copy" data-copy aria-label="复制" title="复制"><span class="c-copy"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M5.5 15H5a1.5 1.5 0 0 1-1.5-1.5V5A1.5 1.5 0 0 1 5 3.5h8.5A1.5 1.5 0 0 1 15 5v.5"/></svg></span><span class="c-done"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span></button></div>
  167. <p class="note">开机时,若某个子服务的模块信息无法读取,或请求使用保留路径,ArozOS 将无法启动。管理员之后再手动启动服务时,同样的问题只会显示错误。</p>
  168. </div>
  169. </div>
  170. </section>
  171. <section class="doc-sec" id="module-info">
  172. <div class="wrap narrow">
  173. <div class="doc-head rv">
  174. <h2 class="doc-title">描述模块</h2>
  175. <p class="lead">模块信息是一个 JSON 对象,与每个 WebApp 注册时使用的 <code>ModuleInfo</code> 相同,因此子服务会像其他应用一样出现在桌面上。</p>
  176. </div>
  177. <div class="doc-item rv">
  178. <div class="cmd"><pre><code>{
  179. &#34;Name&#34;: &#34;Demo Subservice&#34;,
  180. &#34;Desc&#34;: &#34;A simple subservice showing how subservices work in ArozOS&#34;,
  181. &#34;Group&#34;: &#34;Development&#34;,
  182. &#34;IconPath&#34;: &#34;demo/icon.png&#34;,
  183. &#34;Version&#34;: &#34;0.0.1&#34;,
  184. &#34;StartDir&#34;: &#34;demo/home.html&#34;,
  185. &#34;SupportFW&#34;: true,
  186. &#34;LaunchFWDir&#34;: &#34;demo/home.html&#34;,
  187. &#34;SupportEmb&#34;: true,
  188. &#34;LaunchEmb&#34;: &#34;demo/embedded.html&#34;,
  189. &#34;InitFWSize&#34;: [720, 480],
  190. &#34;InitEmbSize&#34;: [720, 480],
  191. &#34;SupportedExt&#34;: [&#34;.txt&#34;, &#34;.md&#34;]
  192. }</code></pre><button type="button" class="copy" data-copy aria-label="复制" title="复制"><span class="c-copy"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M5.5 15H5a1.5 1.5 0 0 1-1.5-1.5V5A1.5 1.5 0 0 1 5 3.5h8.5A1.5 1.5 0 0 1 15 5v.5"/></svg></span><span class="c-done"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span></button></div>
  193. <p class="note"><code>StartDir</code> 的文件夹部分(此处为 <code>demo</code>)就是代理端点。它不可为空,也不可是保留路径 <code>web</code>、<code>system</code>、<code>SystemAO</code>、<code>img</code>、<code>STDIN</code>、<code>STDOUT</code>、<code>STDERR</code>、<code>COM</code>、<code>ws</code>、<code>cluster</code> 与 <code>app</code>。</p>
  194. </div>
  195. </div>
  196. </section>
  197. <section class="specs-sec tone-alt">
  198. <div class="wrap narrow">
  199. <div class="sec-head rv">
  200. <h2 class="title">模块字段</h2>
  201. </div>
  202. <dl class="specs"><div class="spec rv">
  203. <dt>Name</dt>
  204. <dd><p>显示在桌面上。权限依此名称授予,请确保它不重复。</p></dd>
  205. </div><div class="spec rv">
  206. <dt>Desc</dt>
  207. <dd><p>简短说明。</p></dd>
  208. </div><div class="spec rv">
  209. <dt>Group</dt>
  210. <dd><p>开始菜单分类:<code>Media</code>、<code>Office</code>、<code>Internet</code>、<code>Engineering</code>、<code>Development</code>、<code>System Tools</code> 或 <code>Utilities</code>;其他值会列在“其他”。<code>Utilities</code> 与 <code>System Tools</code> 对所有用户开放,其他分类需由权限组授权。</p></dd>
  211. </div><div class="spec rv">
  212. <dt>IconPath</dt>
  213. <dd><p>图标,为服务所提供的路径,例如 <code>demo/icon.png</code>。</p></dd>
  214. </div><div class="spec rv">
  215. <dt>Version</dt>
  216. <dd><p>版本字符串,例如 <code>0.0.1</code>。</p></dd>
  217. </div><div class="spec rv">
  218. <dt>StartDir</dt>
  219. <dd><p>以整页窗口打开的页面。其文件夹即为代理端点。</p></dd>
  220. </div><div class="spec rv">
  221. <dt>SupportFW, LaunchFWDir, InitFWSize</dt>
  222. <dd><p>以浮动窗口打开:是否支持、要加载的页面,以及起始大小 <code>[宽, 高]</code>。</p></dd>
  223. </div><div class="spec rv">
  224. <dt>SupportEmb, LaunchEmb, InitEmbSize</dt>
  225. <dd><p>嵌入模式,也就是以此模块打开文件时加载的模式。设置项相同。</p></dd>
  226. </div><div class="spec rv">
  227. <dt>SupportedExt</dt>
  228. <dd><p>模块可打开的扩展名,例如 <code>[".txt", ".md"]</code>,让它能成为默认打开程序。</p></dd>
  229. </div></dl>
  230. </div>
  231. </section>
  232. <section class="doc-sec" id="proxy">
  233. <div class="wrap narrow">
  234. <div class="doc-head rv">
  235. <h2 class="doc-title">请求如何送达服务</h2>
  236. </div>
  237. <div class="doc-item rv">
  238. <ul class="doc-list"><li>只有已登录且拥有该模块权限的用户能通过,其他人会收到 404。</li><li>代理端点文件夹会从路径中移除:<code>/demo/api/list?a=1</code> 送达服务时是 <code>/api/list?a=1</code>,<code>/demo/</code> 则是 <code>/</code>。因此页面应使用相对链接,或以端点文件夹开头的链接;指向 <code>/api/list</code> 的链接会打到 ArozOS 本身。</li><li>ArozOS 会加上三个请求头:<code>aouser</code>(用户名)、<code>aotoken</code>(该用户的令牌)与 <code>X-Forwarded-Host</code>(浏览器使用的主机)。</li><li>WebSocket 连接同样会被代理,这类请求还会带有 <code>A-Upgrade: websocket</code>。</li><li>若服务停止响应,ArozOS 会记录下来、终止该进程,并在 10 秒后重新启动。</li></ul>
  239. <p class="note">这些请求头的可信度取决于端口。若服务监听所有网络接口,任何连得到该端口的人都能自行发送 <code>aouser</code>,因此请绑定到 <code>127.0.0.1</code>,或从外部封锁 <code>12810</code> 起的端口。</p>
  240. </div>
  241. </div>
  242. </section>
  243. <section class="doc-sec" id="agi">
  244. <div class="wrap narrow">
  245. <div class="doc-head rv">
  246. <h2 class="doc-title">回调 ArozOS</h2>
  247. <p class="lead">子服务通过 AGI 网关(即 <code>-rpt</code> 收到的地址)使用 ArozOS 的功能。以 POST 发送用户的令牌与一段脚本,脚本会以该用户的权限在 AGI 运行环境中执行,并将 <code>sendJSONResp</code> 发出的内容作为响应。</p>
  248. </div>
  249. <div class="doc-item rv">
  250. <div class="cmd"><pre><code>func listDesktop(w http.ResponseWriter, r *http.Request) {
  251. token := r.Header.Get(&#34;aotoken&#34;)
  252. script := `
  253. requirelib(&#34;filelib&#34;);
  254. var list = filelib.glob(&#34;user:/Desktop/*&#34;);
  255. sendJSONResp(JSON.stringify(list));
  256. `
  257. // rpt is the value of the -rpt flag
  258. resp, err := http.PostForm(rpt, url.Values{
  259. &#34;token&#34;: {token},
  260. &#34;script&#34;: {script},
  261. })
  262. if err != nil {
  263. http.Error(w, err.Error(), http.StatusBadGateway)
  264. return
  265. }
  266. defer resp.Body.Close()
  267. w.Header().Set(&#34;Content-Type&#34;, &#34;application/json&#34;)
  268. io.Copy(w, resp.Body)
  269. }</code></pre><button type="button" class="copy" data-copy aria-label="复制" title="复制"><span class="c-copy"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M5.5 15H5a1.5 1.5 0 0 1-1.5-1.5V5A1.5 1.5 0 0 1 5 3.5h8.5A1.5 1.5 0 0 1 15 5v.5"/></svg></span><span class="c-done"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span></button></div>
  270. <p class="note">表单字段为 <code>token</code>(请求中的 <code>aotoken</code> 请求头)与 <code>script</code>。仅凭响应的状态码无法确定脚本是否成功,请检查它返回的内容。</p>
  271. </div>
  272. </div>
  273. </section>
  274. <section class="doc-sec" id="example">
  275. <div class="wrap narrow">
  276. <div class="doc-head rv">
  277. <h2 class="doc-title">最精简的服务</h2>
  278. <p class="lead">这个 Go 程序会响应 <code>-info</code>、提供 <code>web/</code> 文件夹的内容,并有一个向已登录用户问好的 API。</p>
  279. </div>
  280. <div class="doc-item rv">
  281. <div class="doc-text">完整的示例包含网页、AGI 调用、图标,以及各平台的构建脚本,放在示例仓库中。</div>
  282. <div class="cmd"><pre><code>package main
  283. import (
  284. &#34;encoding/json&#34;
  285. &#34;flag&#34;
  286. &#34;fmt&#34;
  287. &#34;log&#34;
  288. &#34;net/http&#34;
  289. )
  290. func main() {
  291. info := flag.Bool(&#34;info&#34;, false, &#34;print the module information and exit&#34;)
  292. port := flag.String(&#34;port&#34;, &#34;:8000&#34;, &#34;listen address chosen by ArozOS&#34;)
  293. flag.String(&#34;rpt&#34;, &#34;&#34;, &#34;AGI gateway of ArozOS&#34;)
  294. flag.Parse()
  295. if *info {
  296. b, _ := json.Marshal(map[string]any{
  297. &#34;Name&#34;: &#34;Demo Subservice&#34;,
  298. &#34;Desc&#34;: &#34;A simple subservice&#34;,
  299. &#34;Group&#34;: &#34;Development&#34;,
  300. &#34;IconPath&#34;: &#34;demo/icon.png&#34;,
  301. &#34;Version&#34;: &#34;0.0.1&#34;,
  302. &#34;StartDir&#34;: &#34;demo/home.html&#34;,
  303. &#34;SupportFW&#34;: true,
  304. &#34;LaunchFWDir&#34;: &#34;demo/home.html&#34;,
  305. &#34;InitFWSize&#34;: []int{720, 480},
  306. })
  307. fmt.Println(string(b))
  308. return
  309. }
  310. http.HandleFunc(&#34;/whoami&#34;, func(w http.ResponseWriter, r *http.Request) {
  311. fmt.Fprintln(w, &#34;Hello&#34;, r.Header.Get(&#34;aouser&#34;))
  312. })
  313. http.Handle(&#34;/&#34;, http.FileServer(http.Dir(&#34;./web&#34;)))
  314. log.Println(&#34;demo listening on&#34;, *port)
  315. log.Fatal(http.ListenAndServe(*port, nil))
  316. }</code></pre><button type="button" class="copy" data-copy aria-label="复制" title="复制"><span class="c-copy"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M5.5 15H5a1.5 1.5 0 0 1-1.5-1.5V5A1.5 1.5 0 0 1 5 3.5h8.5A1.5 1.5 0 0 1 15 5v.5"/></svg></span><span class="c-done"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></span></button></div>
  317. <div class="btns"><a class="btn secondary" href="https://github.com/aroz-online/ArozOS-Subservice-Example" target="_blank" rel="noopener"><svg class="i" viewBox="0 0 16 16" aria-hidden="true" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg><span>子服务示例</span></a></div>
  318. </div>
  319. </div>
  320. </section>
  321. <section class="specs-sec tone-alt" id="marker-files">
  322. <div class="wrap narrow">
  323. <div class="sec-head rv">
  324. <h2 class="title">标记文件</h2>
  325. <p class="lead">放在服务文件夹中的空文件会改变它的启动方式,每次服务启动时都会读取。</p>
  326. </div>
  327. <dl class="specs"><div class="spec rv">
  328. <dt>.disabled</dt>
  329. <dd><p>开机时跳过此服务。管理员停止服务时 ArozOS 会自行写入此文件,再次启动服务时则会移除。</p></dd>
  330. </div><div class="spec rv">
  331. <dt>.noproxy</dt>
  332. <dd><p>兼容模式。程序不带参数启动,也不建立代理,适用于并非为 ArozOS 而写的软件。</p></dd>
  333. </div><div class="spec rv">
  334. <dt>.startscript</dt>
  335. <dd><p>改为启动服务文件夹中的 <code>start.sh</code>(Windows 为 <code>start.bat</code>),而不是可执行文件,例如用来包装需要更多参数的程序。脚本会像可执行文件一样收到 <code>-port</code> 与 <code>-rpt</code>。</p></dd>
  336. </div><div class="spec rv">
  337. <dt>.intport</dt>
  338. <dd><p>以 <code>12810</code> 而非 <code>:12810</code> 传递端口,适用于不接受前置冒号的程序。</p></dd>
  339. </div><div class="spec rv">
  340. <dt>moduleInfo.json</dt>
  341. <dd><p>以文件提供的模块信息。存在时,ArozOS 不会以 <code>-info</code> 运行该可执行文件。</p></dd>
  342. </div></dl>
  343. </div>
  344. </section>
  345. <section class="doc-sec" id="runtime">
  346. <div class="wrap narrow">
  347. <div class="doc-head rv">
  348. <h2 class="doc-title">管理服务</h2>
  349. <p class="lead">管理员可在系统设置中启动与停止服务,该页面使用以下端点:</p>
  350. </div>
  351. <div class="doc-item rv">
  352. <ul class="doc-list"><li><code>/system/subservice/list</code> 列出运行中与已停用的服务。</li><li><code>/system/subservice/kill</code> 停止服务。仅限管理员,表单字段 <code>serviceDir</code> 为其文件夹名称。</li><li><code>/system/subservice/start</code> 启动服务。仅限管理员,字段相同。</li></ul>
  353. <p class="note">以 <code>-disable_subservice</code> 启动 ArozOS 即可完全关闭此功能。</p>
  354. </div>
  355. </div>
  356. </section>
  357. <section class="cta">
  358. <div class="wrap narrow rv">
  359. <div class="cta-logo"><svg class="logo" viewBox="0 0 256 256" aria-hidden="true"><rect class="logo-bg" width="256" height="256" rx="58"/><path class="logo-fg" d="M70 58h116l-58 70zM128 128l58 70H70z"/></svg></div>
  360. <h2 class="title">已经在使用子服务?</h2>
  361. <p class="lead">示例仓库是了解子服务如何构建的最佳参考。请记住,此架构已不再维护。</p>
  362. <div class="btns center"><a class="btn primary" href="https://github.com/aroz-online/ArozOS-Subservice-Example" target="_blank" rel="noopener"><svg class="i" viewBox="0 0 16 16" aria-hidden="true" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg><span>子服务示例</span></a><a class="btn secondary" href="../makers.html"><span>改为开发 WebApp</span></a></div>
  363. </div>
  364. </section>
  365. </main>
  366. <footer class="foot">
  367. <div class="wrap">
  368. <div class="foot-top">
  369. <div class="foot-brand">
  370. <a class="brand" href="../" aria-label="ArozOS"><svg class="logo" viewBox="0 0 256 256" aria-hidden="true"><rect class="logo-bg" width="256" height="256" rx="58"/><path class="logo-fg" d="M70 58h116l-58 70zM128 128l58 70H70z"/></svg><span>ArozOS</span></a>
  371. <p>为你自己的服务器而生的网页桌面。</p>
  372. </div>
  373. <div class="foot-col">
  374. <h2>探索</h2>
  375. <ul><li><a href="../desktop.html">桌面</a></li><li><a href="../media.html">影音</a></li><li><a href="../office.html">办公</a></li><li><a href="../ai.html">AI</a></li><li><a href="../makers.html">创客</a></li><li><a href="../storage.html">存储</a></li><li><a href="../server.html">服务器</a></li><li><a href="../download.html">下载</a></li></ul>
  376. </div>
  377. <div class="foot-col">
  378. <h2>开发者</h2>
  379. <ul><li><a href="https://aroz-online.github.io/ArozOS-Developers/" target="_blank" rel="noopener">AGI 开发文档</a></li><li><a href="https://github.com/aroz-online/WebApp-and-Subservice-Index" target="_blank" rel="noopener">WebApp 与子服务</a></li><li><a href="./">子服务(已弃用)</a></li><li><a href="https://github.com/aroz-online/ArozOS-Subservice-Example" target="_blank" rel="noopener">子服务示例</a></li><li><a href="../../ArozOS-Cluster-Whitepaper.pdf">集群白皮书</a></li><li><a href="https://github.com/aroz-online/launcher" target="_blank" rel="noopener">ArozOS Launcher</a></li></ul>
  380. </div>
  381. <div class="foot-col">
  382. <h2>社区</h2>
  383. <ul><li><a href="https://github.com/tobychui/arozos" target="_blank" rel="noopener">源代码</a></li><li><a href="https://github.com/tobychui/arozos/releases" target="_blank" rel="noopener">发行版本</a></li><li><a href="https://github.com/tobychui/arozos/issues" target="_blank" rel="noopener">报告问题</a></li><li><a href="https://t.me/ArOZBeta" target="_blank" rel="noopener">Telegram</a></li><li><a href="mailto:toby@imuslab.com">电子邮件</a></li></ul>
  384. </div>
  385. <div class="foot-col">
  386. <h2>相关项目</h2>
  387. <ul><li><a href="https://zoraxy.aroz.org" target="_blank" rel="noopener">Zoraxy</a></li><li><a href="https://github.com/tobychui/imusutm" target="_blank" rel="noopener">imusutm</a></li><li><a href="https://github.com/tobychui/SlicerA" target="_blank" rel="noopener">Slicer A</a></li><li><a href="https://github.com/SysAdmin74/ArozOS-Docker" target="_blank" rel="noopener">ArozOS Docker(社区)</a></li><li><a href="https://imuslab.com" target="_blank" rel="noopener">imuslab</a></li></ul>
  388. </div>
  389. </div>
  390. <div class="foot-bottom">
  391. <p>版权所有 © 2016–<span data-year>2026</span> Toby Chui feat. imuslab. 香港制造。 以 <a href="https://github.com/tobychui/arozos/blob/master/LICENSE">GPLv3</a> 许可开源。</p>
  392. <div class="foot-ctl">
  393. <div class="seg sm" role="menu" aria-label="外观"><button type="button" role="menuitemradio" data-theme-set="light" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2.5v2M12 19.5v2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M2.5 12h2M19.5 12h2M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4"/></svg><span>浅色</span></button><button type="button" role="menuitemradio" data-theme-set="dark" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20.5 14.5A8.5 8.5 0 0 1 9.5 3.5a8.5 8.5 0 1 0 11 11z"/></svg><span>深色</span></button><button type="button" role="menuitemradio" data-theme-set="auto" aria-checked="false"><svg class="i" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8.5"/><path d="M12 3.5a8.5 8.5 0 0 1 0 17z" fill="currentColor"/></svg><span>自动</span></button></div>
  394. <div class="foot-langs" role="menu" aria-label="语言"><a role="menuitemradio" href="../../subservice/" hreflang="en" lang="en" data-lang="en" aria-checked="false">English</a><a role="menuitemradio" href="../../zh-tw/subservice/" hreflang="zh-Hant" lang="zh-Hant" data-lang="zh-Hant" aria-checked="false">繁體中文</a><a role="menuitemradio" href="./" hreflang="zh-Hans" lang="zh-Hans" data-lang="zh-Hans" aria-checked="true">简体中文</a><a role="menuitemradio" href="../../ja/subservice/" hreflang="ja" lang="ja" data-lang="ja" aria-checked="false">日本語</a></div>
  395. </div>
  396. </div>
  397. </div>
  398. </footer>
  399. </body>
  400. </html>