Add support for platform topology configuration service (#12066)
* Add support for platform topology configuration service This service invokes the platform plugin for platform specific topology configuration. The path for platform plugin script is: /usr/share/sonic/device/$PLATFORM/plugins/config-topology.sh If the platform plugin is not available, this service does nothing. Signed-off-by: anamehra <anamehra@cisco.com>
This commit is contained in:
parent
85b978a1ca
commit
26af468a99
@ -2,6 +2,8 @@
|
||||
Description=Config initialization and migration service
|
||||
After=rc-local.service
|
||||
After=database.service
|
||||
After=config-topology.service
|
||||
Requires=config-topology.service
|
||||
Requires=database.service
|
||||
{% if sonic_asic_platform == 'mellanox' -%}
|
||||
Requires=hw-management.service
|
||||
|
@ -566,6 +566,11 @@ echo "topology.service" | sudo tee -a $GENERATED_SERVICE_FILE
|
||||
sudo cp $IMAGE_CONFIGS/topology/topology.sh $FILESYSTEM_ROOT/usr/bin
|
||||
{%- endif %}
|
||||
|
||||
# Copy platform topology configuration scripts
|
||||
sudo cp $IMAGE_CONFIGS/config-topology/config-topology.service $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
|
||||
echo "config-topology.service" | sudo tee -a $GENERATED_SERVICE_FILE
|
||||
sudo cp $IMAGE_CONFIGS/config-topology/config-topology.sh $FILESYSTEM_ROOT/usr/bin
|
||||
|
||||
# Copy updategraph script and service file
|
||||
j2 files/build_templates/updategraph.service.j2 | sudo tee $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM/updategraph.service
|
||||
sudo cp $IMAGE_CONFIGS/updategraph/updategraph $FILESYSTEM_ROOT/usr/bin/
|
||||
|
18
files/image_config/config-topology/config-topology.service
Normal file
18
files/image_config/config-topology/config-topology.service
Normal file
@ -0,0 +1,18 @@
|
||||
[Unit]
|
||||
Description=Platform topology configuration service
|
||||
After=database.service
|
||||
After=database-chassis.service
|
||||
Requires=database.service
|
||||
Requires=database-chassis.service
|
||||
Before=config-setup.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=root
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/bin/config-topology.sh start
|
||||
ExecStop=/usr/bin/config-topology.sh stop
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
34
files/image_config/config-topology/config-topology.sh
Executable file
34
files/image_config/config-topology/config-topology.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
# This script is invoked by config-topology.service.
|
||||
# This script invokes platform plugin script if present
|
||||
# which could be used for platform specific topology configuration
|
||||
#
|
||||
start() {
|
||||
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
|
||||
#Path to platform topology script
|
||||
TOPOLOGY_SCRIPT="/usr/share/sonic/device/$PLATFORM/plugins/config-topology.sh"
|
||||
#if topology script file not present, do nothing and return 0
|
||||
[ ! -f $TOPOLOGY_SCRIPT ] && exit 0
|
||||
$TOPOLOGY_SCRIPT start
|
||||
}
|
||||
|
||||
stop() {
|
||||
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
|
||||
#Path to platform topology script
|
||||
TOPOLOGY_SCRIPT="/usr/share/sonic/device/$PLATFORM/plugins/config-topology.sh"
|
||||
#if topology script file not present, do nothing and return 0
|
||||
[ ! -f $TOPOLOGY_SCRIPT ] && exit 0
|
||||
$TOPOLOGY_SCRIPT stop
|
||||
}
|
||||
|
||||
# read SONiC immutable variables
|
||||
[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment
|
||||
|
||||
case "$1" in
|
||||
start|stop)
|
||||
$1
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop}"
|
||||
;;
|
||||
esac
|
@ -104,7 +104,23 @@ static int get_target_lines(char* unit_file, char* target_lines[]) {
|
||||
static bool is_multi_instance_service(char *service_name){
|
||||
int i;
|
||||
for(i=0; i < num_multi_inst; i++){
|
||||
if (strstr(service_name, multi_instance_services[i]) != NULL) {
|
||||
/*
|
||||
* The service name may contain @.service or .service. Remove these
|
||||
* postfixes and extract service name. Compare service name for absolute
|
||||
* match in multi_instance_services[].
|
||||
* This is to prevent services like database-chassis and systemd-timesyncd marked
|
||||
* as multi instance services as they contain strings 'database' and 'syncd' respectively
|
||||
* which are multi instance services in multi_instance_services[].
|
||||
*/
|
||||
char *saveptr;
|
||||
char *token = strtok_r(service_name, "@", &saveptr);
|
||||
if (token) {
|
||||
if (strstr(token, ".service") != NULL) {
|
||||
/* If we are here, service_name did not have '@' delimiter but contains '.service' */
|
||||
token = strtok_r(service_name, ".", &saveptr);
|
||||
}
|
||||
}
|
||||
if (strncmp(service_name, multi_instance_services[i], strlen(service_name)) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user