DEV Community

Pawat Saengduan
Pawat Saengduan

Posted on • Updated on

เปิดใช้งาน 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

เปลี่ยน (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

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
  1. เปิดใช้งาน Service แล้วให้เปิดใช้งานเมื่อบูต เปิดใช้งาน Service: !Start Service

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

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

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

Oldest comments (0)