3
Service:OpenCode
Jeffery edited this page 2026-06-17 01:16:31 +00:00

簡介

下載 OpenCode

curl -fsSL https://opencode.ai/install | bash

建立 OpenCode 服務

設定使用者名稱與密碼

echo "export OPENCODE_SERVER_USERNAME='jiantw83'" >> ~/.bashrc
echo "export OPENCODE_SERVER_PASSWORD='*%QOSYn3Rcc&r*xuWn&q'" >> ~/.bashrc

以 systemd 管理服務,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。

nano /etc/systemd/system/opencode.service

服務檔內容如下:

[Unit]
Description=OpenCode

[Service]
Environment=HOME=/root
Type=simple
WorkingDirectory=/root
ExecStart=/root/.opencode/bin/opencode serve --hostname 0.0.0.0 --mdns true --mdns-domain opencode.jsc.idv.me
Restart=always
User=root

[Install]
WantedBy=multi-user.target

啟動服務

重新載入 systemd 設定、設為開機自動啟動、啟動服務並檢視狀態。

systemctl daemon-reload && systemctl enable opencode.service && systemctl start opencode.service && systemctl status opencode.service