OCIでCode Server動かしてiPadから接続してみる
で、手軽に建てられそう
README.mdのからスタック作ってみる
FreeTierで運用しているので、スタック作成時にVCNとBlockVolumeが作成できなかった。(それぞれ上限2個)
どちらも不要なので削除して、スタックを再度 applyして作成できた
Computeインスタンスのメニューで、PublicIPとユーザー名が表示されるのでSSHで接続する
~/.ssh/config にテキトーな設定を書いておく
ssh ubuntu@codeserver
PublicIPにブラウザでアクセスしたら、トラブルシュートにリダイレクトされた
この辺でステータス見れるので見てみる
# Check if code-server is running
systemctl status code-server@coder
# Check if journalctl is giving us logs, and if something failed
journalctl -u code-server@coder
ubuntuユーザーでログインして、coderユーザーにログインし直す
sudo su - coder
死んでる...
systemctl status code-server@coder
● code-server@coder.service - code-server
Loaded: loaded (/lib/systemd/system/code-server@.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2023-12-01 11:40:27 UTC; 29min ago
Process: 2034 ExecStart=/usr/bin/code-server (code=exited, status=1/FAILURE)
Main PID: 2034 (code=exited, status=1/FAILURE)
Dec 01 11:40:27 oci-code-server systemd[1]: code-server@coder.service: Scheduled restart job, restart counter is at 6.
Dec 01 11:40:27 oci-code-server systemd[1]: Stopped code-server.
Dec 01 11:40:27 oci-code-server systemd[1]: code-server@coder.service: Start request repeated too quickly.
Dec 01 11:40:27 oci-code-server systemd[1]: code-server@coder.service: Failed with result 'exit-code'.
Dec 01 11:40:27 oci-code-server systemd[1]: Failed to start code-server.
/home/coder/.config/code-server/config.yaml
で指定してる --linkオプションが認識されないっぽい
journalctl -u code-server@coder
-- Logs begin at Fri 2023-12-01 11:38:48 UTC, end at Fri 2023-12-01 12:10:28 UTC. --
Dec 01 11:40:17 oci-code-server systemd[1]: Starting code-server...
Dec 01 11:40:17 oci-code-server systemd[1]: Started code-server.
Dec 01 11:40:20 oci-code-server code-server[1898]: [2023-12-01T11:40:20.634Z] error error reading /home/coder/.config/code-server/config.yaml: Unknown option --li>
Dec 01 11:40:20 oci-code-server systemd[1]: code-server@coder.service: Main process exited, code=exited, status=1/FAILURE
Dec 01 11:40:20 oci-code-server systemd[1]: code-server@coder.service: Failed with result 'exit-code'.
Dec 01 11:40:20 oci-code-server systemd[1]: code-server@coder.service: Scheduled restart job, restart counter is at 1.
Dec 01 11:40:20 oci-code-server systemd[1]: Stopped code-server.
Dec 01 11:40:20 oci-code-server systemd[1]: Starting code-server...
Dec 01 11:40:20 oci-code-server systemd[1]: Started code-server.
Dec 01 11:40:22 oci-code-server code-server[1961]: [2023-12-01T11:40:22.005Z] error error reading /home/coder/.config/code-server/config.yaml: Unknown option --li>
Dec 01 11:40:22 oci-code-server systemd[1]: code-server@coder.service: Main process exited, code=exited, status=1/FAILURE
Dec 01 11:40:22 oci-code-server systemd[1]: code-server@coder.service: Failed with result 'exit-code'.
Dec 01 11:40:22 oci-code-server systemd[1]: code-server@coder.service: Scheduled restart job, restart counter is at 2.
Dec 01 11:40:22 oci-code-server systemd[1]: Stopped code-server.
Dec 01 11:40:22 oci-code-server systemd[1]: Starting code-server...
Dec 01 11:40:22 oci-code-server systemd[1]: Started code-server.
Dec 01 11:40:23 oci-code-server code-server[1979]: [2023-12-01T11:40:23.300Z] error error reading /home/coder/.config/code-server/config.yaml: Unknown option --li>
Dec 01 11:40:23 oci-code-server systemd[1]: code-server@coder.service: Main process exited, code=exited, status=1/FAILURE
Dec 01 11:40:23 oci-code-server systemd[1]: code-server@coder.service: Failed with result 'exit-code'.
Dec 01 11:40:23 oci-code-server systemd[1]: code-server@coder.service: Scheduled restart job, restart counter is at 3.
Dec 01 11:40:23 oci-code-server systemd[1]: Stopped code-server.
Dec 01 11:40:23 oci-code-server systemd[1]: Starting code-server...
Dec 01 11:40:23 oci-code-server systemd[1]: Started code-server.
Dec 01 11:40:24 oci-code-server code-server[1997]: [2023-12-01T11:40:24.507Z] error error reading /home/coder/.config/code-server/config.yaml: Unknown option --li>
Dec 01 11:40:24 oci-code-server systemd[1]: code-server@coder.service: Main process exited, code=exited, status=1/FAILURE
Dec 01 11:40:24 oci-code-server systemd[1]: code-server@coder.service: Failed with result 'exit-code'.
Dec 01 11:40:24 oci-code-server systemd[1]: code-server@coder.service: Scheduled restart job, restart counter is at 4.
Dec 01 11:40:24 oci-code-server systemd[1]: Stopped code-server.
Dec 01 11:40:24 oci-code-server systemd[1]: Starting code-server...
Dec 01 11:40:24 oci-code-server systemd[1]: Started code-server.
Dec 01 11:40:26 oci-code-server code-server[2015]: [2023-12-01T11:40:26.230Z] error error reading /home/coder/.config/code-server/config.yaml: Unknown option --li>
Dec 01 11:40:26 oci-code-server systemd[1]: code-server@coder.service: Main process exited, code=exited, status=1/FAILURE
Dec 01 11:40:26 oci-code-server systemd[1]: code-server@coder.service: Failed with result 'exit-code'.
Dec 01 11:40:26 oci-code-server systemd[1]: code-server@coder.service: Scheduled restart job, restart counter is at 5.
Dec 01 11:40:26 oci-code-server systemd[1]: Stopped code-server.
Dec 01 11:40:26 oci-code-server systemd[1]: Starting code-server...
Dec 01 11:40:26 oci-code-server systemd[1]: Started code-server.
Dec 01 11:40:27 oci-code-server code-server[2034]: [2023-12-01T11:40:27.697Z] error error reading /home/coder/.config/code-server/config.yaml: Unknown option --li>
Dec 01 11:40:27 oci-code-server systemd[1]: code-server@coder.service: Main process exited, code=exited, status=1/FAILURE
Dec 01 11:40:27 oci-code-server systemd[1]: code-server@coder.service: Failed with result 'exit-code'.
Dec 01 11:40:27 oci-code-server systemd[1]: code-server@coder.service: Scheduled restart job, restart counter is at 6.
Dec 01 11:40:27 oci-code-server systemd[1]: Stopped code-server.
Dec 01 11:40:27 oci-code-server systemd[1]: code-server@coder.service: Start request repeated too quickly.
Dec 01 11:40:27 oci-code-server systemd[1]: code-server@coder.service: Failed with result 'exit-code'.
Dec 01 11:40:27 oci-code-server systemd[1]: Failed to start code-server.
/home/coder/.config/code-server/config.yaml
見てみる
link: true
ここに書いてあった
Note: This feature is no longer recommended due to instability. Stay tuned for a revised version.
/home/coder/.config/code-server/config.yaml
の中身消して、/usr/bin/code-server
を実行してみる
coder@oci-code-server:~$ /usr/bin/code-server
[2023-12-01T12:28:16.356Z] info code-server 4.19.1 0c98611e6b43803a9d5dba222d7023b569abfb49
[2023-12-01T12:28:16.358Z] info Using user-data-dir /home/coder/.local/share/code-server
[2023-12-01T12:28:16.358Z] error Please pass in a password via the config file or environment variable ($PASSWORD or $HASHED_PASSWORD)
環境変数か、/home/coder/.config/code-server/config.yaml
にパスワードの設定が必要っぽい。
とりあえず/home/coder/.config/code-server/config.yaml
にパスワードっぽいものを設定してみる
password: hogehoge # 実際はもうちょっとまともなパスワードを入れる
この状態で再度 sudo systemctl restart code-server@coder.service
実行
今後はちゃんと起動できたっぽい!
coder@oci-code-server:~$ sudo systemctl status code-server@coder
● code-server@coder.service - code-server
Loaded: loaded (/lib/systemd/system/code-server@.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-12-01 12:32:20 UTC; 7min ago
Main PID: 10476 (node)
Tasks: 22 (limit: 1050)
Memory: 52.7M
CGroup: /system.slice/system-code\x2dserver.slice/code-server@coder.service
├─10476 /usr/lib/code-server/lib/node /usr/lib/code-server
└─10494 /usr/lib/code-server/lib/node /usr/lib/code-server/out/node/entry
Dec 01 12:32:20 oci-code-server systemd[1]: Starting code-server...
Dec 01 12:32:20 oci-code-server systemd[1]: Started code-server.
Dec 01 12:32:22 oci-code-server code-server[10476]: [2023-12-01T12:32:22.256Z] info code-server 4.19.1 0c98611e6b43803a9d5dba222d7023b569abfb49
Dec 01 12:32:22 oci-code-server code-server[10476]: [2023-12-01T12:32:22.257Z] info Using user-data-dir /home/coder/.local/share/code-server
Dec 01 12:32:22 oci-code-server code-server[10476]: [2023-12-01T12:32:22.354Z] info Using config file /home/coder/.config/code-server/config.yaml
Dec 01 12:32:22 oci-code-server code-server[10476]: [2023-12-01T12:32:22.354Z] info HTTP server listening on http://127.0.0.1:8080/
Dec 01 12:32:22 oci-code-server code-server[10476]: [2023-12-01T12:32:22.354Z] info - Authentication is enabled
Dec 01 12:32:22 oci-code-server code-server[10476]: [2023-12-01T12:32:22.355Z] info - Using password from /home/coder/.config/code-server/config.yaml
Dec 01 12:32:22 oci-code-server code-server[10476]: [2023-12-01T12:32:22.355Z] info - Not serving HTTPS
Dec 01 12:32:22 oci-code-server code-server[10476]: [2023-12-01T12:32:22.355Z] info Session server listening on /home/coder/.local/share/code-server/code-server-ipc.sock
ただこの状態だと外部からアクセスできないので好きな方法選んで公開設定が必要。
最終的に iPadから接続したいので、SSH Portforwadingは使えない(はず)
Let's Encrypt + (CaddyかNginx)を使う必要があるが、触ったことないCaddyでやってみる
1. インスタンスへHTTP, HTTPS通信が許可されているか確認
先ほど作ったNSGは80ポートしか開いてないので、HTTPS用に443ポート開けておく
ついでに22ポートが自宅からしか繋がらないように ingressルールを追加しておく
Ubuntu上の iptablesで443ポートがデフォルトでは開いていないので、/etc/iptables/rules.v4
に追加する
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
coder@oci-code-server:~$ sudo su - root
root@oci-code-server:~# sudo iptables-restore < /etc/iptables/rules.v4
2. Google Domainにレコード登録
テキトーな名前で登録した
3. Caddyのインストール
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
最後のインストールコマンドでコケた
Setting up caddy (2.7.5) ...#########################................................................................................................................................................]
Created symlink /etc/systemd/system/multi-user.target.wants/caddy.service → /lib/systemd/system/caddy.service........................................................................................]
Job for caddy.service failed because the control process exited with error code.#############################################........................................................................]
See "systemctl status caddy.service" and "journalctl -xe" for details.
Processing triggers for man-db (2.9.1-1) ...
ステータス見てみると、設定ファイルに記載された 80ポートのリッスンしようとしたがすでに使われているっぽい
coder@oci-code-server:~$ systemctl status caddy.service
● caddy.service - Caddy
Loaded: loaded (/lib/systemd/system/caddy.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2023-12-01 14:48:48 UTC; 5min ago
Docs: https://caddyserver.com/docs/
Main PID: 15740 (code=exited, status=1/FAILURE)
Status: "loading new config: http app module: start: listening on :80: listen tcp :80: bind: address already in use"
coder@oci-code-server:~$ sudo lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
gomon 1691 snap_daemon 13u IPv4 115607 0t0 TCP oci-code-server.vscsub.vcnmodule.oraclevcn.com:34480->169.254.169.254:http (ESTABLISHED)
gomon 1691 snap_daemon 14u IPv4 115608 0t0 TCP oci-code-server.vscsub.vcnmodule.oraclevcn.com:34484->169.254.169.254:http (ESTABLISHED)
python3 1940 root 3u IPv4 32664 0t0 TCP *:http (LISTEN)
python3 1940 root 4u IPv4 72805 0t0 TCP oci-code-server.vscsub.vcnmodule.oraclevcn.com:http->90.151.171.108:16057 (ESTABLISHED)
python3が80ポートを使っているっぽい、PublicIPに初回アクセスした時READMEにリダイレクトされたので何かしらPythonが80ポートで動いてそう。
coder@oci-code-server:~$ systemctl status | grep 80
│ │ └─28262 grep --color=auto 80
│ └─28101 /usr/bin/python3 /usr/bin/coder-cloud-redirect.py 80
coder@oci-code-server:~$ sudo systemctl stop coder-cloud-redirect.service
coder@oci-code-server:~$ sudo systemctl status coder-cloud-redirect.service
● coder-cloud-redirect.service - coder-cloud-redirect
Loaded: loaded (/etc/systemd/system/coder-cloud-redirect.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Fri 2023-12-01 15:21:23 UTC; 5s ago
Process: 28101 ExecStart=/usr/bin/python3 /usr/bin/coder-cloud-redirect.py 80 (code=killed, signal=TERM)
Main PID: 28101 (code=killed, signal=TERM)
Dec 01 15:15:58 oci-code-server systemd[1]: Started coder-cloud-redirect.
Dec 01 15:21:23 oci-code-server systemd[1]: Stopping coder-cloud-redirect...
Dec 01 15:21:23 oci-code-server systemd[1]: coder-cloud-redirect.service: Succeeded.
Dec 01 15:21:23 oci-code-server systemd[1]: Stopped coder-cloud-redirect.
止めたので、改めて caddyをリロード&再起動してみる。
coder@oci-code-server:~$ sudo systemctl reload-or-restart caddy.service
coder@oci-code-server:~$ sudo systemctl status caddy.service
● caddy.service - Caddy
Loaded: loaded (/lib/systemd/system/caddy.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-12-01 15:22:34 UTC; 10s ago
Docs: https://caddyserver.com/docs/
Main PID: 28338 (caddy)
Tasks: 8 (limit: 1050)
Memory: 12.5M
CGroup: /system.slice/caddy.service
└─28338 /usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
...
登録したDNS名でアクセスしてみる
パスワード入力して送信、エディタが表示された。一旦動くようになったので使ってみる