ระบบ Linux

ตารางเปรียบเทียบการใช้งาน SysVinit กับ Systemd

Systemd components หลังจากที่ RHEL ได้ออก version 7 มาทำให้ผู้ใช้งานต่างต้องปรับตัวกับการเปลี่ยนระบบ service manager กันใหม่ จากระบบก่อนๆ ที่ใช้ SysVinit มาเป็น Systemd ซึ่งมีข้อดีมากกว่าการใช้ SysVinit หลายข้อ เช่นการทำงานแบบ parallel การทำ handling mount point หรือ support cgroups เป็นต้น จากการที่คำสั่งการทำงานได้มีการเปลี่ยนเแปลงเกือยทั้งหมด ดังนั้นผมจึงนำตารางเปรียบเทียบคำสั่งระหว่าง SysVinit กับ Systemd เพื่อให้ผู้ที่ใช้งานสามารถนำไปเปรียบเทียบกับคำสั่งที่เคยใช้งานอยู่ก่อนหน้านี้ *** ชื่อ service ที่ยกตัวอย่างในตารางนี้ชื่อ abc ครับ

Service Command

Sysvinit CommandSystemd Command
Start service (ไม่ได้เกี่ยวกับการตั้ง start ตอน boot ใหม่)service abc startsystemctl start abc
Stop service (ไม่ได้เกี่ยวกับการตั้ง stop ตอน boot ใหม่)service abc stopsystemctl stop abc
Restart serviceservice abc restartsystemctl restart abc
reload config โดยไม่กระทบต่อการทำงาน (ถ้า support)service abc reloadsystemctl reload abc
Restarts service ถ้าหาก service นั้นทำงานอยู่service abc condrestartsystemctl condrestart abc
ตรวจสอบสถานะการทำงานของ Serviceservice abc statussystemctl status abc
ตรวจสอบ list ของ service ที่มีในระบบ (สามารถสั่ง stop หรือ start ได้)ls /etc/rc.d/init.d/systemctl หรือ systemctl list-unit-files —type=servicels /lib/systemd/system/*.service /etc/systemd/system/*.service
กำหนดให้ service on เมื่อระบบได้ boot ขึ้นมาใหม่chkconfig abc onsystemctl enable abc
กำหนดให้ service off เมื่อระบบได้ boot ขึ้นมาใหม่chkconfig abc offsystemctl disable abc
ตรวจสอบการตั้งค่า service on หรือ off เมื่อมี boot ระบบขึ้นมาใหม่ใน environment ปัจจุบันchkconfig abcsystemctl is-enabled abc
แสดงตาราง services ในแต่ละ runlevels ว่าถูกตั้งค่าเป็น on หรือ offchkconfig —listsystemctl list-unit-files —type=service หรือ ls /etc/systemd/system/*.wants/
แสดง list runlevels ของ service ว่าตั้งค่าเป็น on หรือ offchkconfig abc —listls /etc/systemd/system/*.wants/abc.service
เพิ่ม service file เข้าไปใหม่ หรือแก้ไข configuration ต่างๆchkconfig abc —addsystemctl daemon-reload

system log

SysvinitSystemd
ตรวจสอบ system logtail /var/log/messages หรือ tail /var/log/syslogjournalctl -f

Runlevels

SysvinitSystemd
System halt0runlevel0.target หรือ poweroff.target
Single user mode1, s, singlerunlevel1.target หรือ rescue.target
Multi user2runlevel2.target หรือ multi-user.target
Multi user with Network3runlevel3.target หรือ multi-user.target
Experimental4runlevel4.target หรือ multi-user.target
Multi user with network and graphic5runlevel5.target หรือ graphic.target
Reboot6runlevel6.target หรือ reboot.target
Emergency shellemergencyemergency.target
เปลี่ยน runlevel/target เป็นแบบ multi usertelinit 3systemctl isolate multi-user.target หรือ systemctl isolate runlevel3.target
ตั้งค่าให้เป็น multi user runlevel/target สำหรับ boot ครั้งต่อไปsed s/^id:*:initdefault:/id:3:initdefault:/ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
ตรวจสอบ runlevel ปัจจุบันrunlevelsystemctl get-default
เปลี่ยน current runlevelsed s/^id:*:initdefault:/id:3:initdefault:/systemctl set-default multi-user.target

Machine state

SysvinitSystemd
system halthaltsystemctl halt
ปิดเครื่อง (power off)poweroffsystemctl poweroff
Rebootrebootsystemctl reboot
Suspend systempm-suspendsystemctl suspend
Hibernatepm-hibernatesystemctl hibernate

Systemd new commands

Systemd
รัน systemd command จาก remote hostsystemctl abc.service start -H user@remotehost
Check boot timesystemd-analyze หรือ systemd-analyze time
Kill ทุก process ที่มีความสัมพันธืกับ servicesystemctl kill abc
ตรวจสอบ event log ของวันนี้journalctl —since=today
จัดการ hostnamehostnamectl
จัดการ date/time (รวมถึง timezone)timedatectl
EOF.← กลับไปอ่านบทความอื่น