우분투 D-Bus 완전 정복: gdbus 실전 예제로 배우는 IPC 제어

개요

리눅스 데스크톱 및 시스템 서비스 간 통신 표준인 D-Bus를 터미널에서 직접 탐색하고 제어할 수 있는 gdbus 명령어 활용법을 소개합니다. 패키지 설치부터 시스템 버스 조회, 속성 읽기 및 실제 메서드 호출까지 단계별 실습을 통해 D-Bus의 핵심 원리를 완벽하게 마스터할 수 있습니다.

1. gdbus 도구 확인 및 환경 준비

gdbus 도구 실습을 위해 D-Bus 시스템 및 GLib 유틸리티 패키지를 설치합니다.

apt-get update -qq && apt-get install -y libglib2.0-bin dbus

설치된 gdbus 바이너리의 실행 파일 경로가 시스템에 정상적으로 등록되어 있는지 which 명령어로 확인합니다.

which gdbus

gdbus 명령어는 D-Bus 메시지 버스 시스템을 제어하고 객체 및 인터페이스를 검사하거나 메서드를 호출하는 도구입니다.
⚙️ [주요 옵션]

introspect : 대상 D-Bus 객체의 인터페이스, 메서드, 시그널, 속성 정보를 상세하게 조회합니다.
call : 특정 D-Bus 객체의 메서드를 호출하고 반환 결과를 출력합니다.
emit : 지정한 객체 경로와 인터페이스에 D-Bus 시그널을 발행합니다.
monitor : D-Bus 버스에서 전달되는 메시지 및 이벤트를 실시간으로 모니터링합니다.
wait : 특정 D-Bus 서비스나 이름이 버스에 등록될 때까지 대기합니다.
--system : 시스템 버스(--system)를 대상으로 작업을 수행합니다.
--session : 사용자 세션 버스(--session)를 대상으로 작업을 수행합니다.
--dest : 대상 서비스의 D-Bus 버스 이름(웰노운 이름 또는 고유 이름)을 지정합니다.
--object-path : 작업을 수행할 D-Bus 객체의 경로를 지정합니다.
--recurse : introspect 수행 시 하위 객체 경로까지 재귀적으로 탐색합니다.

gdbus –help

2. 시스템 버스(System Bus) 서비스 탐색 및 객체 인스펙션

gdbus introspect 명령어를 사용하여 시스템 버스(--system)의 핵심 서비스인 org.freedesktop.systemd1 서비스가 제공하는 최상위 객체 경로(/org/freedesktop/systemd1)의 구조를 조회합니다.
--recurse=false 옵션을 지정하여 하위 노드를 재귀 탐색하지 않고 현재 객체에 등록된 인터페이스, 메서드, 시그널, 프로퍼티 목록만 간결하게 확인합니다.

gdbus introspect –system –dest org.freedesktop.systemd1 –object-path /org/freedesktop/systemd1 –recurse=false

호스트네임 관리 서비스인 org.freedesktop.hostname1을 대상으로 introspect 명령을 실행하여 해당 객체(/org/freedesktop/hostname1)의 상세 구조를 인스펙션합니다.
이 명령을 통해 시스템의 호스트 이름, 머신 ID, 운영체제 정보 등을 조회하거나 변경할 수 있는 인터페이스와 속성 명세를 파악할 수 있습니다.

gdbus introspect –system –dest org.freedesktop.hostname1 –object-path /org/freedesktop/hostname1

3. 서비스 프로퍼티 및 상태 정보 읽기 (get/dump)

gdbus dump 명령어를 사용하여 시스템 버스(--system)에 등록된 org.freedesktop.hostname1 서비스의 모든 객체 트리와 인터페이스, 프로퍼티 상태 값을 한 번에 덤프하여 확인합니다.
이 명령을 통해 대상 서비스가 보유한 전체 프로퍼티의 현재 설정값을 일괄적으로 파악할 수 있습니다.

gdbus dump –system –dest org.freedesktop.hostname1

gdbus call 명령어를 사용하여 표준 D-Bus 인터페이스인 org.freedesktop.DBus.Properties.Get 메서드를 호출합니다.
org.freedesktop.hostname1 인터페이스에서 시스템의 정식 운영체제 명칭을 담고 있는 OperatingSystemPrettyName 프로퍼티 값을 단독으로 조회합니다.

gdbus call –system –dest org.freedesktop.hostname1 –object-path /org/freedesktop/hostname1 –method org.freedesktop.DBus.Properties.Get org.freedesktop.hostname1 OperatingSystemPrettyName

동일하게 gdbus call 명령어로 org.freedesktop.DBus.Properties.Get 메서드를 실행하여 호스트네임 서비스의 커널 속성을 조회합니다.
인터페이스 내의 KernelName 프로퍼티를 지정하여 현재 구동 중인 시스템의 커널 이름(예: Linux)을 직접 확인합니다.

gdbus call –system –dest org.freedesktop.hostname1 –object-path /org/freedesktop/hostname1 –method org.freedesktop.DBus.Properties.Get org.freedesktop.hostname1 KernelName

4. 실전 메서드 호출: systemd 서비스 상태 조회 및 D-Bus 제어

gdbus call 명령어를 사용하여 org.freedesktop.systemd1 서비스의 Manager 인터페이스에 정의된 GetUnit 메서드를 호출합니다.
인자로 cron.service를 전달하여 해당 유닛을 관리하는 전용 D-Bus 객체 경로(/org/freedesktop/systemd1/unit/cron_2eservice)를 획득합니다.

gdbus call –system –dest org.freedesktop.systemd1 –object-path /org/freedesktop/systemd1 –method org.freedesktop.systemd1.Manager.GetUnit ‘cron.service’

D-Bus 자체 데몬 서비스인 org.freedesktop.DBus의 최상위 객체를 대상으로 ListNames 메서드를 호출합니다.
현재 시스템 버스에 등록되어 통신 중인 모든 고유 이름(Unique Name) 및 웰노운 이름(Well-known Name) 목록을 배열 형태로 조회합니다.

gdbus call –system –dest org.freedesktop.DBus –object-path /org/freedesktop/DBus –method org.freedesktop.DBus.ListNames

지금까지 우분투 환경에서 D-Bus의 기본 개념과 함께 gdbus 실전 예제를 통해 IPC를 제어하는 방법을 살펴보았습니다.
오늘 익힌 명령줄 통신 방식을 바탕으로 다양한 시스템 서비스 제어 및 자동화 스크립트 작성에 유용하게 활용해 보시기 바랍니다.