DEV Community

Pawat Saengduan
Pawat Saengduan

Posted on • Edited on

1 3

เปิดใช้งาน ngrok เมื่อเปิดเครื่อง (Linux)

เปิดใช้งาน ngrok เมื่อเปิดเครื่อง
ตามนั้นแหละครับ... 🤨 มาเริ่มกันเลยดีกว่า!!

เราก็มาเตรียม Software กันดีกว่า:

  1. Linux OS ( มันต้องใช้อยู่แล้วแหละ )
  2. ngrok ( เพราะว่าวันนี้จะให้ ngrok ทำงาน )
  3. Text Editor เช่น Vim, VS Code, Nano, etc.. ( เอามาเขียนไฟล์ Services )

มาดูวิธีสร้าง Services กันดีกว่า!!!:

  1. เปิดมาก็สร้างไฟล์ก่อนเลย ใช้ Text Editor ตัวไหนก็ได้ Service code template Code:
[Unit]
Description=(Service Descriptions)
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=(Start Execution)

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

เปลี่ยน (Service Descriptions) และ (Start Execution)

  1. Service Descriptions → คำอธิบายของ Services
  2. Start Execution → คำสั่งที่ต้องการที่จะรัน

แล้ว Save ไปที่

/etc/systemd/system/(ชื่ออะไรก็ได ้แต่อย่าซ้ำกับที่มีอยู่แล้ว).service

ตัวอย่าง
Create a service file

sudo vi /etc/systemd/system/ngrok-auto.service
Enter fullscreen mode Exit fullscreen mode

Code

[Unit]
Description=ngrok auto-open
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=/opt/ngrok-linux64 --proto=tcp cnx 22

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode
  1. เปิดใช้งาน Service แล้วให้เปิดใช้งานเมื่อบูต เปิดใช้งาน Service: !Start Service

ให้เปิดทำงานเมื่อเครื่องบูต:
Enable Service to startup

ตัวอย่าง
Start service & Check the status
Enable the service

พอเรา Enable มัน มันก็จะ Ouput Symlink ออกมา
จบแล้วครับ สวัสดีคร้าบบ!!!

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay