Logo

Personal Ops Runbook

Personal runbook covering infrastructure operations for Cloud, Kubernetes, OpenStack, and Ceph environments. Includes deployment and teardown procedures, node management, cluster monitoring setup, and incident response workflows compiled from day-to-day operational work. Intended strictly for personal reference — configurations and scripts are environment-specific and not guaranteed to work as-is elsewhere.

Lỗi Unit service is masked trong Linux


Lỗi "Unit telegraf.service is masked" xảy ra khi dịch vụ telegraf đã bị masked, nghĩa là nó đã bị vô hiệu hóa hoàn toàn (không thể khởi động, khởi động lại, hay dừng). Điều này thường được thực hiện bằng cách liên kết file .service của dịch vụ tới /dev/null, ngăn hệ thống sử dụng dịch vụ.

image

Khi bạn chạy các lệnh systemctl để tương tác với dịch vụ sẽ nhận được thông báo Unit telegraf.service is masked.

Ví dụ lệnh bật dịch vụ.

root@lab:~# systemctl start telegraf
Failed to start telegraf.service: Unit telegraf.service is masked.

Hoặc lệnh khởi động lại dịch vụ.

root@lab:~# systemctl restart telegraf
Failed to restart telegraf.service: Unit telegraf.service is masked.

Nguyên nhân

Dịch vụ bị masked thủ công:

Có thể ai đó đã chạy lệnh dưới để vô hiệu hóa dịch vụ này.

systemctl mask telegraf

Hệ thống quản lý dịch vụ (như Ansible hoặc SaltStack):

Một công cụ tự động đã mask dịch vụ trong quá trình triển khai hoặc cấu hình.

Do cấu hình hoặc xung đột:

Dịch vụ bị masked tự động bởi hệ thống vì một lý do nào đó, chẳng hạn như lỗi trong file cấu hình.

Giải pháp

Kiểm tra trạng thái của dịch vụ.

Chạy lệnh systemctl status telegraf.service để xác nhận dịch vụ đã bị masked:

root@lab:~# systemctl status telegraf
× telegraf.service
     Loaded: masked (Reason: Unit telegraf.service is masked.)
     Active: failed (Result: exit-code) since Wed 2024-12-04 15:13:45 +07; 5min ago
   Main PID: 1281518 (code=exited, status=1/FAILURE)
        CPU: 209ms

Dec 04 15:13:45 lab systemd[1]: telegraf.service: Scheduled restart job, restart counter is at 5.
Dec 04 15:13:45 lab systemd[1]: Stopped The plugin-driven server agent for reporting metrics into InfluxDB.
Dec 04 15:13:45 lab systemd[1]: telegraf.service: Start request repeated too quickly.
Dec 04 15:13:45 lab systemd[1]: telegraf.service: Failed with result 'exit-code'.
Dec 04 15:13:45 lab systemd[1]: Failed to start The plugin-driven server agent for reporting metrics into InfluxDB.

Bạn sẽ thấy dòng Reason: Unit telegraf.service is masked.

Unmask dịch vụ.

root@lab:~# systemctl unmask telegraf.service
Removed /etc/systemd/system/telegraf.service.

Khởi động lại dịch vụ.

Sau khi unmask, khởi động lại dịch vụ:

sudo systemctl restart telegraf

Kiểm tra dịch vụ sau khi khởi động.

Đảm bảo dịch vụ hoạt động bình thường:

systemctl status telegraf.service