Skip to content

Commit d4e52b8

Browse files
committed
Revamp role-config
- Move role-config service and script in to role/ directory - role-config now writes or deletes files to/from /etc/sonic/role/ directory - Services which are role-dependent use 'ConditionPathExists=' to determine whether or not to start
1 parent ecc4729 commit d4e52b8

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

files/build_templates/dhcp_relay.service.j2

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Description=DHCP relay container
33
Requires=docker.service
44
After=role-config.service
55
After=interfaces-config.service
6+
ConditionPathExists=/etc/sonic/role/dhcp_relay
67

78
[Service]
89
User={{ sonicadmin_user }}

files/build_templates/sonic_debian_extension.j2

+5-3
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ sudo cp $IMAGE_CONFIGS/platform/platform-init.service $FILESYSTEM_ROOT/etc/syst
130130
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable platform-init.service
131131
sudo cp $IMAGE_CONFIGS/platform/platform-init.sh $FILESYSTEM_ROOT/usr/bin/
132132

133-
# Copy role-config script and service unit file, enable service
134-
sudo cp $IMAGE_CONFIGS/platform/role-config.service $FILESYSTEM_ROOT/etc/systemd/system/
133+
# Copy role-config script and service unit file, enable service and create dir to
134+
# house files that will be used to conditionally start services based on device role
135+
sudo cp $IMAGE_CONFIGS/role/role-config.service $FILESYSTEM_ROOT/etc/systemd/system/
135136
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable role-config.service
136-
sudo cp $IMAGE_CONFIGS/platform/role-config.sh $FILESYSTEM_ROOT/usr/bin/
137+
sudo cp $IMAGE_CONFIGS/role/role-config.sh $FILESYSTEM_ROOT/usr/bin/
138+
sudo mkdir -p $FILESYSTEM_ROOT/etc/sonic/role/
137139

138140
# Copy sudoers configuration file
139141
sudo cp $IMAGE_CONFIGS/sudoers/sudoers $FILESYSTEM_ROOT/etc/

files/build_templates/teamd.service.j2

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Description=TEAMD container
33
Requires=database.service
44
After=role-config.service
55
After=database.service
6+
ConditionPathExists=/etc/sonic/role/teamd
67

78
[Service]
89
User={{ sonicadmin_user }}

files/image_config/platform/role-config.sh renamed to files/image_config/role/role-config.sh

+10-8
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,27 @@
77
#
88

99
# Disable DHCP relay service if device does not require it
10+
DHCP_RELAY_SERVICE_START_FILE=/etc/sonic/role/dhcp_relay
1011
DEVICE_ROLE=`sonic-cfggen -m /etc/sonic/minigraph.xml -v "minigraph_devices[minigraph_hostname]['type']"`
1112

1213
if [ $DEVICE_ROLE == "ToRRouter" ]; then
13-
echo "Device requires DHCP relay. Enabling DHCP relay service..."
14-
systemctl enable dhcp_relay.service
14+
echo "Device requires DHCP relay service. Ensuring start file exists..."
15+
touch $DHCP_RELAY_SERVICE_START_FILE
1516
else
16-
echo "Device does not require DHCP relay. Disabling DHCP relay service..."
17-
systemctl disable dhcp_relay.service
17+
echo "Device does not require DHCP relay service. Deleting start file..."
18+
rm -f $DHCP_RELAY_SERVICE_START_FILE
1819
fi
1920

2021

2122
# Disable teamd service if device does not require it
23+
TEAMD_SERVICE_START_FILE=/etc/sonic/role/teamd
2224
NUM_PORTCHANNELS=`sonic-cfggen -m /etc/sonic/minigraph.xml -v "minigraph_portchannels.keys() | count"`
2325

2426
if [ $NUM_PORTCHANNELS -gt 0 ]; then
25-
echo "Device requires teamd. Enabling teamd service..."
26-
systemctl enable teamd.service
27+
echo "Device requires teamd service. Ensuring start file exists..."
28+
touch $TEAMD_SERVICE_START_FILE
2729
else
28-
echo "Device does not require teamd. Disabling teamd service..."
29-
systemctl disable teamd.service
30+
echo "Device does not require teamd service. Deleting start file..."
31+
rm -f $TEAMD_SERVICE_START_FILE
3032
fi
3133

0 commit comments

Comments
 (0)