Skip to content

Commit 9d7387a

Browse files
authoredApr 26, 2022
[sonic-host-services]: Fix import and invalid path (#10660)
Why I did it Can not start sonic-hostservice How I did it Install python3-dbus and systemd-python, and replace invalid path How to verify it Start the service with below commands: sudo systemctl start sonic-hostservice sudo systemctl status sonic-hostservice Signed-off-by: Gang Lv ganglv@microsoft.com
1 parent a06f549 commit 9d7387a

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed
 

‎files/build_templates/sonic_debian_extension.j2

+4-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ sudo cp -f $IMAGE_CONFIGS/bash/bash.bashrc $FILESYSTEM_ROOT/etc/
233233
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install libcairo2-dev libdbus-1-dev libgirepository1.0-dev libsystemd-dev pkg-config
234234

235235
# Mark runtime dependencies as manually installed to avoid them being auto-removed while uninstalling build dependencies
236-
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-mark manual gir1.2-glib-2.0 libdbus-1-3 libgirepository-1.0-1 libsystemd0
236+
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-mark manual gir1.2-glib-2.0 libdbus-1-3 libgirepository-1.0-1 libsystemd0 python3-dbus
237+
238+
# Install systemd-python for SONiC host services
239+
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install systemd-python
237240

238241
# Install SONiC host services package
239242
SONIC_HOST_SERVICES_PY3_WHEEL_NAME=$(basename {{sonic_host_services_py3_wheel_path}})

‎src/sonic-host-services/scripts/sonic-host-server

+12-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ import dbus.mainloop.glib
1313

1414
from gi.repository import GObject
1515

16-
def register_modules():
16+
def find_module_path():
17+
"""Find path for host_moduels"""
18+
try:
19+
from host_modules import host_service
20+
return os.path.dirname(host_service.__file__)
21+
except ImportError as e:
22+
return None
23+
24+
def register_modules(mod_path):
1725
"""Register all host modules"""
18-
mod_path = '/usr/local/lib/python3.7/dist-packages/host_modules'
1926
sys.path.append(mod_path)
2027
for mod_file in glob.glob(os.path.join(mod_path, '*.py')):
2128
if os.path.isfile(mod_file) and not mod_file.endswith('__init__.py'):
@@ -62,7 +69,9 @@ class SignalManager(object):
6269
loop.quit()
6370

6471
sigmgr = SignalManager()
65-
register_modules()
72+
mod_path = find_module_path()
73+
if mod_path is not None:
74+
register_modules(mod_path)
6675

6776
# Only run if we actually have some handlers
6877
if handlers:

‎src/sonic-host-services/setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
],
2525
install_requires = [
2626
'dbus-python',
27+
'systemd-python',
2728
'Jinja2>=2.10',
2829
'PyGObject',
2930
'sonic-py-common'

0 commit comments

Comments
 (0)
Please sign in to comment.