Unit File คืออะไร

แชร์ความรู้ Linux Ubuntu Web Server บทความ การ config server Linux FreeBSD Apache
การติดตั้ง XAMPP Mysql PHP ใครต้องการแชร์ความรู้เรื่องต่างๆ เหล่านี้ให้ ท่านหรืออื่น โพสที่หมวดนี้ได้

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
jirawoot
PHP VIP Members
PHP VIP Members
โพสต์: 3129
ลงทะเบียนเมื่อ: 17/06/2019 10:30 am

Unit File คืออะไร

โพสต์ที่ยังไม่ได้อ่าน โดย jirawoot »

Unit File คืออะไร
Unit file หรือเรียกอีกอย่างว่า systemd เป็นตัวสำหรับจัดการตัว service ของระบบปฏิบัติการ linux ซึ่งสามารถสั่งปิดและเปิดด้วย คำสั่ง command line หรือ terminal สามารถตรวจสอบสถานะของ service ได้ unit file มีหลายประเภทด้วยกันดังนี้ .service, .socket, .device, .mount, .automount และ .path เป็นต้น ไฟล์จะเก็บไว้ในไดเรกทอรี /lib/systemd/system
เราสามารถสร้าง unit file ได้โดยมีรูปแบบการสร้างดังนี้

โค้ด: เลือกทั้งหมด

[Section]
Directive1=value
Directive2=value

. . .
ตัวอย่าง

โค้ด: เลือกทั้งหมด

[Unit]
Description=Dummy Service
After=multi-user.target
[email protected]

[Service]
Type=simple
ExecStart=/usr/bin/python3 /usr/bin/dummy_service.py
StandardInput=tty-force

[Install]
WantedBy=multi-user.target
วิธีการตรวจสอบสถานะของ service ได้โดยคำสั่ง

โค้ด: เลือกทั้งหมด

sudo systemctl status [ ชื่อ service ]
และดู service ทั้งหมดได้ด้วยคำสั่ง

โค้ด: เลือกทั้งหมด

service --status-all
ผลที่ได้
รูปภาพ
ตัวอย่างการตรวจสอบสถานะ
รูปภาพ

สามารถ start | stop | restart ตัว service ได้ด้วยคำสั่งดังนี้
คำสั่ง start

โค้ด: เลือกทั้งหมด

sudo systemctl start [ ชื่อตัว service ]
คำสั่ง stop

โค้ด: เลือกทั้งหมด

sudo systemctl stop [ ชื่อตัว service ]
คำสั่ง restart

โค้ด: เลือกทั้งหมด

sudo systemctl restart [ ชื่อตัว service ]

อ้างอิง
https://m.do.co/c/1f99f054a010
https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files
https://linuxconfig.org/how-to-create-systemd-service-unit-in-linux
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 48