在 Ubuntu 服务器上通过 systemctl 服务启动 ngrok

在 Ubuntu 服务器上通过 systemctl 服务启动 ngrok

我正在运行 Ubuntu Server 22.04.1 并尝试在启动时使用 systemd 运行 ngrok 以创建 ssh 隧道。

当前状态:

  • /etc/systemd/system/BWS_ngrok.service 下的 BWS_ngrok.service
  • /home/ubuntu/server/bwsv4/ngrok.yml 下的 ngrok.yml
  • ngrok路径:/snap/bin/ngrok(根据which ngrok

/etc/systemd/system/BWS_ngrok.service:

[Unit]
Description=Start Ngrok at boot
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
ExecStart=/snap/bin/ngrok start --config /home/ubuntu/server/bwsv4/ngrok.yml

[Install]
WantedBy=multi-user.target

/home/ubuntu/server/bwsv4/ngrok.yml:

authtoken: <Ngrok-Authtoken>
tunnels:
  ssh:
    proto: tcp
    addr: 22

我在控制台中做了什么:

ubuntu@ubuntu:/etc/systemd/system$ sudo systemctl daemon-reload
ubuntu@ubuntu:/etc/systemd/system$ sudo systemctl restart BWS_ngrok.service
ubuntu@ubuntu:/etc/systemd/system$ sudo systemctl status 

输出sudo systemctl status BWS_ngrok.service

BWS_ngrok.service
× BWS_ngrok.service - Start Ngrok at boot
     Loaded: loaded (/etc/systemd/system/BWS_ngrok.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2022-09-13 19:27:11 UTC; 2s ago
    Process: 4734 ExecStart=/snap/bin/ngrok start --config /home/ubuntu/server/bwsv4/ngrok.yml (code=exited, status=1/FAILURE)
   Main PID: 4734 (code=exited, status=1/FAILURE)
        CPU: 239ms

Sep 13 19:27:11 ubuntu systemd[1]: Started Start Ngrok at boot.
Sep 13 19:27:11 ubuntu systemd[1]: BWS_ngrok.service: Main process exited, code=exited, status=1/FAILURE
Sep 13 19:27:11 ubuntu systemd[1]: BWS_ngrok.service: Failed with result 'exit-code'.

到目前为止我已经尝试过:

  • .service文件中:(ExecStart=/snap/bin/ngrok tcp 22之前添加了 Ngrok-Authtoken ngrok config add-authtoken <Ngrok-Authtoken>
  • 使用 检查 ngrok 配置文件的位置ngrok config check,这给了我Valid configuration file at /home/ubuntu/snap/ngrok/85/.config/ngrok/ngrok.yml,所以我在此文件中添加了以下内容:
authtoken: <Ngrok-Authtoken>
tunnels:
  ssh:
    proto: tcp
    addr: 22

如果我尝试打印 Journalctl 日志,正如埃德加·马加隆所说,我会得到以下信息:

Nov 19 16:05:34 bws systemd[1]: Started Start Ngrok at boot.
░░ Subject: A start job for unit BWS_ngrok.service has finished successfully
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit BWS_ngrok.service has finished successfully.
░░
░░ The job identifier is 29439.
Nov 19 16:05:34 bws systemd[1]: BWS_ngrok.service: Main process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ An ExecStart= process belonging to unit BWS_ngrok.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
Nov 19 16:05:34 bws systemd[1]: BWS_ngrok.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ The unit BWS_ngrok.service has entered the 'failed' state with result 'exit-code'.

这与 systemctl status 输出相同,因此没有其他信息......

但我仍然没有设法让 Ngrok 在启动时启动。

相关内容