2019-03-22 04:49:35 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Generate supervisord config file and the start.sh scripts
|
|
|
|
mkdir -p /etc/supervisor/conf.d/
|
|
|
|
|
2020-07-28 02:23:21 -05:00
|
|
|
SENSORS_CONF_FILE="/usr/share/sonic/platform/sensors.conf"
|
|
|
|
FANCONTROL_CONF_FILE="/usr/share/sonic/platform/fancontrol"
|
2020-12-28 12:19:24 -06:00
|
|
|
|
|
|
|
SUPERVISOR_CONF_TEMPLATE="/usr/share/sonic/templates/docker-pmon.supervisord.conf.j2"
|
|
|
|
SUPERVISOR_CONF_FILE="/etc/supervisor/conf.d/supervisord.conf"
|
|
|
|
PMON_DAEMON_CONTROL_FILE="/usr/share/sonic/platform/pmon_daemon_control.json"
|
2020-12-15 18:28:58 -06:00
|
|
|
MODULAR_CHASSISDB_CONF_FILE="/usr/share/sonic/platform/chassisdb.conf"
|
2020-05-15 20:00:47 -05:00
|
|
|
|
|
|
|
HAVE_SENSORS_CONF=0
|
|
|
|
HAVE_FANCONTROL_CONF=0
|
2020-12-15 18:28:58 -06:00
|
|
|
IS_MODULAR_CHASSIS=0
|
2020-12-28 12:19:24 -06:00
|
|
|
# Default use python2 version
|
|
|
|
SONIC_PLATFORM_API_PYTHON_VERSION=2
|
2020-05-15 20:00:47 -05:00
|
|
|
|
2020-12-28 12:19:24 -06:00
|
|
|
declare -r EXIT_SUCCESS="0"
|
|
|
|
|
|
|
|
if [ "${RUNTIME_OWNER}" == "" ]; then
|
|
|
|
RUNTIME_OWNER="kube"
|
2020-05-15 20:00:47 -05:00
|
|
|
fi
|
|
|
|
|
2020-12-28 12:19:24 -06:00
|
|
|
CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py"
|
|
|
|
if test -f ${CTR_SCRIPT}
|
|
|
|
then
|
|
|
|
${CTR_SCRIPT} -f pmon -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION}
|
2020-05-15 20:00:47 -05:00
|
|
|
fi
|
|
|
|
|
2020-12-28 12:19:24 -06:00
|
|
|
mkdir -p /var/sonic
|
|
|
|
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status
|
|
|
|
|
|
|
|
# If this platform has synchronization script, run it
|
|
|
|
if [ -e /usr/share/sonic/platform/platform_wait ]; then
|
|
|
|
/usr/share/sonic/platform/platform_wait
|
|
|
|
EXIT_CODE="$?"
|
|
|
|
if [ "${EXIT_CODE}" != "${EXIT_SUCCESS}" ]; then
|
|
|
|
exit "${EXIT_CODE}"
|
|
|
|
fi
|
2020-12-15 18:28:58 -06:00
|
|
|
fi
|
|
|
|
|
2020-12-28 12:19:24 -06:00
|
|
|
# If the Python 2 sonic-platform package is not installed, try to install it
|
|
|
|
python2 -c "import sonic_platform" > /dev/null 2>&1 || pip2 show sonic-platform > /dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
SONIC_PLATFORM_WHEEL="/usr/share/sonic/platform/sonic_platform-1.0-py2-none-any.whl"
|
|
|
|
echo "sonic-platform package not installed, attempting to install..."
|
|
|
|
if [ -e ${SONIC_PLATFORM_WHEEL} ]; then
|
|
|
|
pip2 install ${SONIC_PLATFORM_WHEEL}
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Successfully installed ${SONIC_PLATFORM_WHEEL}"
|
|
|
|
else
|
|
|
|
echo "Error: Failed to install ${SONIC_PLATFORM_WHEEL}"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Error: Unable to locate ${SONIC_PLATFORM_WHEEL}"
|
|
|
|
fi
|
|
|
|
fi
|
2020-05-15 20:00:47 -05:00
|
|
|
|
2020-12-28 12:19:24 -06:00
|
|
|
# If the Python 3 sonic-platform package is not installed, try to install it
|
|
|
|
python3 -c "import sonic_platform" > /dev/null 2>&1 || pip3 show sonic-platform > /dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
SONIC_PLATFORM_WHEEL="/usr/share/sonic/platform/sonic_platform-1.0-py3-none-any.whl"
|
|
|
|
echo "sonic-platform package not installed, attempting to install..."
|
|
|
|
if [ -e ${SONIC_PLATFORM_WHEEL} ]; then
|
|
|
|
pip3 install ${SONIC_PLATFORM_WHEEL}
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Successfully installed ${SONIC_PLATFORM_WHEEL}"
|
|
|
|
SONIC_PLATFORM_API_PYTHON_VERSION=3
|
|
|
|
else
|
|
|
|
echo "Error: Failed to install ${SONIC_PLATFORM_WHEEL}"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Error: Unable to locate ${SONIC_PLATFORM_WHEEL}"
|
|
|
|
fi
|
2019-03-22 04:49:35 -05:00
|
|
|
else
|
2020-12-28 12:19:24 -06:00
|
|
|
SONIC_PLATFORM_API_PYTHON_VERSION=3
|
2019-03-22 04:49:35 -05:00
|
|
|
fi
|
|
|
|
|
2021-05-06 12:13:26 -05:00
|
|
|
{% if CONFIGURED_PLATFORM == "mellanox" %}
|
|
|
|
SENSORS_CONF_PATH_GETTER="/usr/share/sonic/platform/get_sensors_conf_path"
|
|
|
|
if [ -e $SENSORS_CONF_PATH_GETTER ]; then
|
|
|
|
SENSORS_CONF_FILE=$($SENSORS_CONF_PATH_GETTER 2>&1)
|
|
|
|
fi
|
|
|
|
{% endif %}
|
|
|
|
|
2020-12-28 12:19:24 -06:00
|
|
|
if [ -e $SENSORS_CONF_FILE ]; then
|
|
|
|
HAVE_SENSORS_CONF=1
|
2020-05-15 20:00:47 -05:00
|
|
|
mkdir -p /etc/sensors.d
|
2021-05-06 12:13:26 -05:00
|
|
|
/bin/cp -f $SENSORS_CONF_FILE /etc/sensors.d/sensors.conf
|
2020-05-15 20:00:47 -05:00
|
|
|
fi
|
|
|
|
|
2020-12-28 12:19:24 -06:00
|
|
|
if [ -e $FANCONTROL_CONF_FILE ]; then
|
|
|
|
HAVE_FANCONTROL_CONF=1
|
2020-05-15 20:00:47 -05:00
|
|
|
rm -f /var/run/fancontrol.pid
|
2020-07-28 02:23:21 -05:00
|
|
|
/bin/cp -f $FANCONTROL_CONF_FILE /etc/
|
2020-05-15 20:00:47 -05:00
|
|
|
fi
|
|
|
|
|
2020-12-28 12:19:24 -06:00
|
|
|
if [ -e $MODULAR_CHASSISDB_CONF_FILE ]; then
|
|
|
|
IS_MODULAR_CHASSIS=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
confvar="{\"HAVE_SENSORS_CONF\":$HAVE_SENSORS_CONF, \"HAVE_FANCONTROL_CONF\":$HAVE_FANCONTROL_CONF, \"API_VERSION\":$SONIC_PLATFORM_API_PYTHON_VERSION, \"IS_MODULAR_CHASSIS\":$IS_MODULAR_CHASSIS}"
|
|
|
|
|
|
|
|
if [ -e $PMON_DAEMON_CONTROL_FILE ];
|
|
|
|
then
|
2022-01-25 13:10:25 -06:00
|
|
|
sonic-cfggen -d -j $PMON_DAEMON_CONTROL_FILE -a "$confvar" -t $SUPERVISOR_CONF_TEMPLATE > $SUPERVISOR_CONF_FILE
|
2020-12-28 12:19:24 -06:00
|
|
|
else
|
2022-01-25 13:10:25 -06:00
|
|
|
sonic-cfggen -d -a "$confvar" -t $SUPERVISOR_CONF_TEMPLATE > $SUPERVISOR_CONF_FILE
|
2020-12-28 12:19:24 -06:00
|
|
|
fi
|
|
|
|
|
2020-11-22 23:18:44 -06:00
|
|
|
exec /usr/local/bin/supervisord
|