Skip to content

Commit

Permalink
[build][systemd] Mask disabled services by default (#4721)
Browse files Browse the repository at this point in the history
When building the SONiC image, used systemd to mask all services which are set to "disabled" in init_cfg.json.

This PR depends on sonic-net/sonic-utilities#944, otherwise `config load_minigraph will fail when trying to restart disabled services.
  • Loading branch information
jleveque authored and abdosi committed Jun 28, 2020
1 parent 0768bf7 commit 5df5015
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions files/build_scripts/mask_disabled_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python3

import json
import subprocess

INIT_CFG_FILE_PATH = '/etc/sonic/init_cfg.json'

with open(INIT_CFG_FILE_PATH) as init_cfg_file:
init_cfg = json.load(init_cfg_file)
if 'FEATURE' in init_cfg:
for feature_name, feature_props in init_cfg['FEATURE'].items():
if 'status' in feature_props and feature_props['status'] == 'disabled':
subprocess.run(['systemctl', 'mask', '{}.service'.format(feature_name)])
7 changes: 7 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set -x -e
CONFIGURED_ARCH=$([ -f .arch ] && cat .arch || echo amd64)

. functions.sh
BUILD_SCRIPTS_DIR=files/build_scripts
BUILD_TEMPLATES=files/build_templates
IMAGE_CONFIGS=files/image_config
SCRIPTS_DIR=files/scripts
Expand Down Expand Up @@ -504,3 +505,9 @@ sudo chown -R $FRR_USER_UID:$FRR_USER_GID $FILESYSTEM_ROOT/etc/sonic/frr
sudo chmod -R 640 $FILESYSTEM_ROOT/etc/sonic/frr/
sudo chmod 750 $FILESYSTEM_ROOT/etc/sonic/frr
{%- endif %}

# Mask services which are disabled by default
sudo cp $BUILD_SCRIPTS_DIR/mask_disabled_services.py $FILESYSTEM_ROOT/tmp/
sudo chmod a+x $FILESYSTEM_ROOT/tmp/mask_disabled_services.py
sudo LANG=C chroot $FILESYSTEM_ROOT /tmp/mask_disabled_services.py
sudo rm -rf $FILESYSTEM_ROOT/tmp/mask_disabled_services.py

0 comments on commit 5df5015

Please sign in to comment.