แก้ไข Ghost-CLI ค้างตอนสั่ง Ghost Start หรือ Restart

แก้ไข Ghost-CLI ค้างตอนสั่ง Ghost Start หรือ Restart

บล็อกผมแห่งนี้ทำงานบน Ghost blogging platform ซึ่งโดยติดตั้งอยู่บน Digital ocean ซึ่งปกติถ้า ghost มีการอัพเดทเวอร์ชั่น ผมก็จะทำการ ssh เข้าไปที่ server แล้วสั่ง ghost update เอาเองตลอด ซึ่งมันก็อัพเดทได้เองสะดวกดี

ปัญหาของ ghost-cli ค้าง

ผมจะทำการอัพเดทเวอร์ชั่น Ghost ล่าสุดโดยใช้ ghost-cli คือ ghost update แต่มันดันไปค้างตอนช่วงสั่ง ghost restart แบบค้างไปเลย ผมก็เลยทำการกด control+c เพื่อให้หลุดจากคำสั่ง แล้วก็มาลองสั่ง ghost stop ก็ค้าง แล้วก็ยกเลิกคำสั่ง มาสั่ง ghost start ก็ค้างอีก ซึ่งมันทำให้เว็บผมเข้าไม่ได้เลย

☴ Starting Ghost...

ผมเลยนึกทบทวนว่าเคยทำอะไรไว้บ้างวะก่อนหน้า แล้วก็นั่งไล่ดูทีละส่วนดังนี้

ดู port ของ ghost ว่าถูกไหม

ไปที่ไฟล์ /var/www/ghost/config.production.json ว่ามันตั้งค่า port ถูกหรือป่าว

{
  "url": "https://MY_DOMAIN.com/",
  "server": {
    "port": 2368,
    "host": "127.0.0.1"
  },
.
.
.
}

แล้วก็ดูว่า nginx config (/var/www/ghost/system/files/MY_DOMAIN.com-ssl.conf) นั้นมีค่า port ถูกต้องไหม

server {
    listen 80;
    listen [::]:80;

    server_name MY_DOMAIN.com;
    root /var/www/ghost/system/nginx-root;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2369;

    }
.
.
.
}

แล้วก็ลองสั่ง ghost ให้มันตั้งค่า port

ghost config set server.port 2369

ตั้งค่า path node ให้ถูก

จำได้ว่าเคยเข้ามาอัพเดท Node ให้เป็นเวอร์ชั่น 12 อยู่ซึ่งการอัพเดท node ในครั้งนั้นทำให้คำสั่ง node มันจะถูกเปลี่ยนจาก /usr/bin/node มา /usr/local/bin/node โดยใครอยากรู้ว่ามันอยู่ไหนลองใช้คำสั่ง

which node
/usr/local/bin/node

จากนั้นมาเข้าไปดูไฟล์ /var/www/ghost/system/files/ghost_DOMAIN-com.service เพื่อดูว่า node path ถูกหรือไม่

ExecStart=/usr/bin/node /usr/bin/ghost run

สั่งเกตุว่า /usr/bin/node ยังผิดอยู่ เพราะเราอัพเดท node ไปแล้วมันจะไปอยู่ที่ /usr/local/bin/node ก็ทำการแก้ไขซะ

ExecStart=/usr/local/bin/node /usr/bin/ghost run

เมื่อแก้ไขแล้วก็สั่งให้มัน reload ใหม่ sudo systemctl daemon-reload แล้วลองสั่ง ghost restart ใหม่ดูก็จะสามารถใช้งานได้แล้ว


สรุปปัญหา

ใน Case ของผมนั้นปัญหามาจากมันเรียก node path ไม่ถูกต้อง เพียงแค่เข้าไปแก้ไขไฟล์ ghost_DOMAIN-com.service เป็น node path ที่ถูกต้องก็เรียบร้อยแล้ว :)

Arnon Kijlerdphon

Arnon Kijlerdphon

Choosing to live a plant-based lifestyle for the animals, my health, and the future of our planet.
Bangkok, Thailand