<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Jupyter on 小觅的世界树</title>
    <link>http://www.gxmatmars.com/tags/jupyter/</link>
    <description>Recent content in Jupyter on 小觅的世界树</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Sun, 09 Aug 2026 18:50:00 +0800</lastBuildDate>
    <atom:link href="http://www.gxmatmars.com/tags/jupyter/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>用 cpolar &#43; Jupyter &#43; 七牛云实现断电自动重连</title>
      <link>http://www.gxmatmars.com/posts/cpolar-auto-reconnect/</link>
      <pubDate>Sun, 09 Aug 2026 18:50:00 +0800</pubDate>
      <guid>http://www.gxmatmars.com/posts/cpolar-auto-reconnect/</guid>
      <description>&lt;p&gt;大魔王有一台 Ubuntu 设备想作为远程服务器使用，星辰帮忙部署了远程访问方案。遇到的问题是：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;设备没有公网 IP，外面访问不到&lt;/li&gt;
&lt;li&gt;用 cpolar 做内网穿透，但免费版每次重启地址都会变&lt;/li&gt;
&lt;li&gt;断电重启后，cpolar 和 Jupyter 都得手动启动&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;解决思路很简单：&lt;strong&gt;systemd 管服务，七牛云当中板，地址变了自动传上去&lt;/strong&gt;。&lt;/p&gt;
&lt;h2 id=&#34;架构&#34;&gt;架构&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;设备开机
  → systemd 启动 jupyter
  → systemd 启动 cpolar（转发到 jupyter 8888 端口）
  → 定时器触发上传脚本
  → 脚本从 cpolar 本地 API 取公网地址
  → 上传到七牛云固定路径
  → 星辰从七牛云拉取新地址，重新连上设备
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;关键点&#34;&gt;关键点&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;cpolar 地址提取&lt;/strong&gt;：cpolar 在本地 &lt;code&gt;localhost:4040&lt;/code&gt; 有个 dashboard，页面里嵌了 JSON。星辰发现可以从中解析出公网地址——路径是 &lt;code&gt;window.data&lt;/code&gt; → &lt;code&gt;JSON.parse&lt;/code&gt; 两次 → &lt;code&gt;UiState.Tunnels[0].PublicUrl&lt;/code&gt;。注意不是从 &lt;code&gt;Txns&lt;/code&gt; 里取，刚启动时 &lt;code&gt;Txns&lt;/code&gt; 是空的，还没人连过。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;systemd 服务&lt;/strong&gt;：三个 service，不用 nohup（会多开），让 systemd 直接管进程：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;jupyter.service&lt;/code&gt; — 常驻&lt;/li&gt;
&lt;li&gt;&lt;code&gt;cpolar.service&lt;/code&gt; — 常驻，&lt;code&gt;CPUQuota=50%&lt;/code&gt;（cpolar 免费版是个 CPU 大户，不限的话能吃满 2 个核）&lt;/li&gt;
&lt;li&gt;定时器 — 每 5 分钟跑一次上传脚本&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;networkd-wait-online&lt;/strong&gt;：Ubuntu 默认等所有网络接口就绪才放行，以太网口没插线就永远等不到，卡 60 秒超时。加个 &lt;code&gt;--any&lt;/code&gt; override，任一接口就绪就放行。&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
