Commit 5d8aeed8 authored by Adam Wujek's avatar Adam Wujek 💬

rootfs: forward output from early boot scripts to the kernel log

Forward messages from scripts running before syslog is available
to the kernel log. Before these messages were printed only to the
console.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 4ec37a4d
...@@ -9,6 +9,13 @@ ...@@ -9,6 +9,13 @@
dotconfig=/wr/etc/dot-config dotconfig=/wr/etc/dot-config
tmpconfig=/tmp/dot-config tmpconfig=/tmp/dot-config
tmpdir=/tmp tmpdir=/tmp
log_output=/dev/kmsg
set -o pipefail # The return value of a pipeline is the status of
# the last command to exit with a non-zero status,
# or zero if no command exited with a non-zero status
# Needed for return value ($?) of xxx in "xxx | tee yyy"
rm -f "$tmpdir"/dot-config_source rm -f "$tmpdir"/dot-config_source
...@@ -16,17 +23,17 @@ if [ -f $dotconfig ]; then ...@@ -16,17 +23,17 @@ if [ -f $dotconfig ]; then
# source dot-config # source dot-config
. $dotconfig . $dotconfig
ret_source=$? ret_source=$?
/wr/bin/wrs_checkcfg $dotconfig /wr/etc/Kconfig /wr/bin/wrs_checkcfg $dotconfig /wr/etc/Kconfig 2>&1| tee $log_output
ret_check=$? ret_check=$?
if [ $ret_source != 0 ] || [ $ret_check != 0 ]; then if [ $ret_source != 0 ] || [ $ret_check != 0 ]; then
# errors in local dot-config # errors in local dot-config
echo "check_error" > "$tmpdir"/dot-config_status echo "check_error" > "$tmpdir"/dot-config_status
echo "Errors found in local dot-config!!!" >& 2 echo "Errors found in local dot-config!!!" | tee $log_output >& 2
else else
echo "config_ok" > "$tmpdir"/dot-config_status echo "config_ok" > "$tmpdir"/dot-config_status
fi fi
else else
echo "No /wr/etc/dot-config to use" >& 2 echo "No /wr/etc/dot-config to use" | tee $log_output >& 2
echo "no_config" > "$tmpdir"/dot-config_source echo "no_config" > "$tmpdir"/dot-config_source
echo "config_error" > "$tmpdir"/dot-config_status echo "config_error" > "$tmpdir"/dot-config_status
fi fi
...@@ -67,10 +74,10 @@ if [ "$CONFIG_DOTCONF_SOURCE_REMOTE" = "y" ] || [ "$CONFIG_DOTCONF_SOURCE_TRY_DH ...@@ -67,10 +74,10 @@ if [ "$CONFIG_DOTCONF_SOURCE_REMOTE" = "y" ] || [ "$CONFIG_DOTCONF_SOURCE_TRY_DH
if [ -f "$tmpdir"/dot-config_source_url ]; then if [ -f "$tmpdir"/dot-config_source_url ]; then
# replace CONFIG_DOTCONF_URL with one gotten from dhcp # replace CONFIG_DOTCONF_URL with one gotten from dhcp
CONFIG_DOTCONF_URL=`cat "$tmpdir"/dot-config_source_url` CONFIG_DOTCONF_URL=`cat "$tmpdir"/dot-config_source_url`
echo "Got dot-config's URL ("$CONFIG_DOTCONF_URL") via DHCP" >& 2 echo "Got dot-config's URL ("$CONFIG_DOTCONF_URL") via DHCP" | tee $log_output >& 2
else else
echo "dhcp_error" > "$tmpdir"/dot-config_status echo "dhcp_error" > "$tmpdir"/dot-config_status
echo "Unable to get dot-config's URL via DHCP, using old dot-config" >& 2 echo "Unable to get dot-config's URL via DHCP, using old dot-config" | tee $log_output >& 2
# apply old dot-config # apply old dot-config
/wr/bin/apply_dot-config /wr/bin/apply_dot-config
exit exit
...@@ -105,33 +112,33 @@ if [ "$CONFIG_DOTCONF_SOURCE_REMOTE" = "y" ] || [ "$CONFIG_DOTCONF_SOURCE_TRY_DH ...@@ -105,33 +112,33 @@ if [ "$CONFIG_DOTCONF_SOURCE_REMOTE" = "y" ] || [ "$CONFIG_DOTCONF_SOURCE_TRY_DH
tftp -g -r "$filename" -l $tmpconfig $host tftp -g -r "$filename" -l $tmpconfig $host
;; ;;
*) *)
echo "Invalid URL for dot-config: \"$URL\"" >& 2 echo "Invalid URL for dot-config: \"$URL\"" | tee $log_output >& 2
;; ;;
esac esac
if [ -f $tmpconfig ]; then if [ -f $tmpconfig ]; then
# If it exists, it is not empty or too small and the checker is happy # If it exists, it is not empty or too small and the checker is happy
# then try to source it in another shell to verify syntax # then try to source it in another shell to verify syntax
if [ $(cat $tmpconfig | wc -c) -gt 200 ] && if [ $(cat $tmpconfig | wc -c) -gt 200 ] &&
/wr/bin/wrs_checkcfg $tmpconfig /wr/etc/Kconfig && /wr/bin/wrs_checkcfg $tmpconfig /wr/etc/Kconfig 2>&1| tee $log_output &&
/bin/sh -c ". $tmpconfig"; then /bin/sh -c ". $tmpconfig"; then
echo "Using newly-downloaded dot-config from $URL" >& 2 echo "Using newly-downloaded dot-config from $URL" | tee $log_output >& 2
# copy it in place to use the new file (unless it is identical) # copy it in place to use the new file (unless it is identical)
cmp -s $tmpconfig $dotconfig || cp $tmpconfig $dotconfig cmp -s $tmpconfig $dotconfig || cp $tmpconfig $dotconfig
# info for SNMP that downloading was successful and checker is happy # info for SNMP that downloading was successful and checker is happy
echo "config_ok" > "$tmpdir"/dot-config_status echo "config_ok" > "$tmpdir"/dot-config_status
else else
echo "check_error" > "$tmpdir"/dot-config_status echo "check_error" > "$tmpdir"/dot-config_status
echo "Errors found in downloaded dot-config \"$URL\", using old" >& 2 echo "Errors found in downloaded dot-config \"$URL\", using old" | tee $log_output >& 2
fi fi
else else
echo "download_error" > "$tmpdir"/dot-config_status echo "download_error" > "$tmpdir"/dot-config_status
echo "Download error for dot-config \"$URL\", using old" >& 2 echo "Download error for dot-config \"$URL\", using old" | tee $log_output >& 2
fi fi
elif [ "$CONFIG_DOTCONF_SOURCE_LOCAL" = "y" ]; then elif [ "$CONFIG_DOTCONF_SOURCE_LOCAL" = "y" ]; then
echo "local" > "$tmpdir"/dot-config_source echo "local" > "$tmpdir"/dot-config_source
echo "Using local dot-config" >& 2 echo "Using local dot-config" | tee $log_output >& 2
else else
echo "Unknown dot-config source. Using local dot-config" >& 2 echo "Unknown dot-config source. Using local dot-config" | tee $log_output >& 2
fi fi
# Finally, apply what we have, be it old or new # Finally, apply what we have, be it old or new
......
...@@ -13,6 +13,7 @@ if [ -n "$WRS_VERBOSE" ]; then ...@@ -13,6 +13,7 @@ if [ -n "$WRS_VERBOSE" ]; then
set -x set -x
fi fi
log_output=/dev/kmsg
# This kernel has no hwinfo partition (strange...) # This kernel has no hwinfo partition (strange...)
if ! grep -q hwinfo /proc/mtd; then if ! grep -q hwinfo /proc/mtd; then
...@@ -23,7 +24,7 @@ fi ...@@ -23,7 +24,7 @@ fi
if ! [ -f /wr/bin/sdb-read ]; then if ! [ -f /wr/bin/sdb-read ]; then
# If for some reason sdb-read is not available, don't touch hwinfo # If for some reason sdb-read is not available, don't touch hwinfo
echo "/wr/bin/sdb-read not available!" echo "Error: /wr/bin/sdb-read not available!" | tee $log_output
# save script result for snmp # save script result for snmp
echo "hwinfo_error" > /tmp/hwinfo_read_status echo "hwinfo_error" > /tmp/hwinfo_read_status
exit 0; exit 0;
...@@ -41,6 +42,7 @@ echo "Creating SDB filesystem in /dev/mtd5" ...@@ -41,6 +42,7 @@ echo "Creating SDB filesystem in /dev/mtd5"
# So, we must create an sdb file, we need the template # So, we must create an sdb file, we need the template
cp /wr/etc/sdb-for-dataflash.bin /tmp cp /wr/etc/sdb-for-dataflash.bin /tmp
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echo "Error: /wr/etc/sdb-for-dataflash.bin not found!" | tee $log_output
echo "hwinfo_error" > /tmp/hwinfo_read_status echo "hwinfo_error" > /tmp/hwinfo_read_status
exit 1 exit 1
fi fi
...@@ -74,5 +76,5 @@ echo "hwinfo_ok" > /tmp/hwinfo_read_status ...@@ -74,5 +76,5 @@ echo "hwinfo_ok" > /tmp/hwinfo_read_status
# reboot if hw info was updated # reboot if hw info was updated
# Please note that reboot will take pleace after switch finishes booting # Please note that reboot will take pleace after switch finishes booting
echo -e "\n\nOrdering reboot after hwinfo update!!!\n\n" echo -e "\n\nOrdering reboot after hwinfo update!!!\n\n" | tee $log_output
reboot reboot
...@@ -5,12 +5,13 @@ ...@@ -5,12 +5,13 @@
dotconfig=/wr/etc/dot-config dotconfig=/wr/etc/dot-config
int_file=/etc/network/interfaces int_file=/etc/network/interfaces
log_output=/dev/kmsg
# no matter what we do keep lo up # no matter what we do keep lo up
ifup lo &> /dev/null ifup lo &> /dev/null
if grep -q '/ nfs' /proc/mounts; then if grep -q '/ nfs' /proc/mounts; then
echo "Running via NFS: leaving eth0 config alone" echo "Running via NFS: leaving eth0 config alone" | tee $log_output
exit 0 exit 0
fi fi
...@@ -60,21 +61,21 @@ fi ...@@ -60,21 +61,21 @@ fi
if [ "$CONFIG_HOSTNAME_STATIC" = "y" ]; then if [ "$CONFIG_HOSTNAME_STATIC" = "y" ]; then
if [ -z "$CONFIG_HOSTNAME_STRING" ]; then if [ -z "$CONFIG_HOSTNAME_STRING" ]; then
echo "empty CONFIG_HOSTNAME_STRING! use wrs" echo "empty CONFIG_HOSTNAME_STRING! use wrs" | tee $log_output
CONFIG_HOSTNAME_STRING="wrs" CONFIG_HOSTNAME_STRING="wrs"
fi fi
/bin/hostname "$CONFIG_HOSTNAME_STRING" /bin/hostname "$CONFIG_HOSTNAME_STRING"
echo "$CONFIG_HOSTNAME_STRING" > /etc/hostname echo "$CONFIG_HOSTNAME_STRING" | tee $log_output > /etc/hostname
elif [ "$CONFIG_HOSTNAME_DHCP" = "y" ]; then elif [ "$CONFIG_HOSTNAME_DHCP" = "y" ]; then
DHCP_OPT_EXTRA="-O hostname -s /wr/bin/dhcp_extra_opt.sh" DHCP_OPT_EXTRA="-O hostname -s /wr/bin/dhcp_extra_opt.sh"
fi fi
if [ "$CONFIG_ETH0_DHCP_ONCE" = "y" ]; then if [ "$CONFIG_ETH0_DHCP_ONCE" = "y" ]; then
echo "Try DHCP to get IP" echo "Try DHCP to get IP" | tee $log_output
# try dhcp, if fail use static IP # try dhcp, if fail use static IP
udhcpc -i eth0 -n $DHCP_OPT_EXTRA udhcpc -i eth0 -n $DHCP_OPT_EXTRA | tee $log_output
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to obtain IP address via DHCP, set static IP" echo "Failed to obtain IP address via DHCP, set static IP" | tee $log_output
CONFIG_ETH0_STATIC="y" CONFIG_ETH0_STATIC="y"
else else
exit exit
...@@ -83,7 +84,7 @@ fi ...@@ -83,7 +84,7 @@ fi
if [ "$CONFIG_ETH0_STATIC" = "y" ]; then if [ "$CONFIG_ETH0_STATIC" = "y" ]; then
# ifup to use static parameters from /etc/netwrok/interfaces # ifup to use static parameters from /etc/netwrok/interfaces
echo "Using static IP" echo "Using static IP" | tee $log_output
ifup eth0 ifup eth0
exit exit
fi fi
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# #
MONIT=/usr/bin/monit MONIT=/usr/bin/monit
dotconfig=/wr/etc/dot-config dotconfig=/wr/etc/dot-config
log_output=/dev/kmsg
start_counter() { start_counter() {
# increase boot counter # increase boot counter
...@@ -23,11 +24,11 @@ start() { ...@@ -23,11 +24,11 @@ start() {
if [ -f "$dotconfig" ]; then if [ -f "$dotconfig" ]; then
. "$dotconfig" . "$dotconfig"
else else
echo "$0 unable to source dot-config ($dotconfig)!" echo "$0 unable to source dot-config ($dotconfig)!" | tee $log_output
fi fi
if [ "$CONFIG_LDAP_ENABLE" != "y" ]; then if [ "$CONFIG_LDAP_ENABLE" != "y" ]; then
echo "LDAP not enabled in dot-config" echo "LDAP not enabled in dot-config" | tee $log_output
# Unmonitor web server (nslcd), ignore all printouts # Unmonitor web server (nslcd), ignore all printouts
# from monit. # from monit.
# Run in background since monit may wait for a timeout. # Run in background since monit may wait for a timeout.
...@@ -36,7 +37,7 @@ start() { ...@@ -36,7 +37,7 @@ start() {
fi fi
if [ -z "$CONFIG_LDAP_SERVER" ]; then if [ -z "$CONFIG_LDAP_SERVER" ]; then
echo "Failed! LDAP server not defined" echo "Failed! LDAP server not defined" | tee $log_output
exit 0 exit 0
fi fi
# fill LDAP server address # fill LDAP server address
...@@ -44,7 +45,7 @@ start() { ...@@ -44,7 +45,7 @@ start() {
sed -i "s,^uri CONFIG_LDAP_SERVER_ADDRESS,uri $CONFIG_LDAP_SERVER,g" /etc/nslcd.conf sed -i "s,^uri CONFIG_LDAP_SERVER_ADDRESS,uri $CONFIG_LDAP_SERVER,g" /etc/nslcd.conf
if [ -z "$CONFIG_LDAP_SEARCH_BASE" ]; then if [ -z "$CONFIG_LDAP_SEARCH_BASE" ]; then
echo "Failed! LDAP search base not defined" echo "Failed! LDAP search base not defined" | tee $log_output
exit 0 exit 0
fi fi
# fill LDAP search base # fill LDAP search base
...@@ -55,12 +56,12 @@ start() { ...@@ -55,12 +56,12 @@ start() {
sed -i "s/CONFIG_LDAP_FILTER//g" /etc/nslcd.conf sed -i "s/CONFIG_LDAP_FILTER//g" /etc/nslcd.conf
elif [ "$CONFIG_LDAP_FILTER_EGROUP" = "y" ]; then elif [ "$CONFIG_LDAP_FILTER_EGROUP" = "y" ]; then
if [ -z "$CONFIG_LDAP_FILTER_EGROUP_STR" ]; then if [ -z "$CONFIG_LDAP_FILTER_EGROUP_STR" ]; then
echo -n "Warning: CONFIG_LDAP_FILTER_EGROUP_STR empty! " echo -n "Warning: CONFIG_LDAP_FILTER_EGROUP_STR empty! " | tee $log_output
fi fi
sed -i "s/CONFIG_LDAP_FILTER/(memberOf=CN=$CONFIG_LDAP_FILTER_EGROUP_STR,OU=e-groups,OU=Workgroups,$CONFIG_LDAP_SEARCH_BASE)/g" /etc/nslcd.conf sed -i "s/CONFIG_LDAP_FILTER/(memberOf=CN=$CONFIG_LDAP_FILTER_EGROUP_STR,OU=e-groups,OU=Workgroups,$CONFIG_LDAP_SEARCH_BASE)/g" /etc/nslcd.conf
elif [ "$CONFIG_LDAP_FILTER_CUSTOM" = "y" ]; then elif [ "$CONFIG_LDAP_FILTER_CUSTOM" = "y" ]; then
if [ -z "$CONFIG_LDAP_FILTER_CUSTOM_STR" ]; then if [ -z "$CONFIG_LDAP_FILTER_CUSTOM_STR" ]; then
echo -n "Warning: CONFIG_LDAP_FILTER_CUSTOM_STR empty! " echo -n "Warning: CONFIG_LDAP_FILTER_CUSTOM_STR empty! " | tee $log_output
fi fi
sed -i "s/CONFIG_LDAP_FILTER/$CONFIG_LDAP_FILTER_CUSTOM_STR/g" /etc/nslcd.conf sed -i "s/CONFIG_LDAP_FILTER/$CONFIG_LDAP_FILTER_CUSTOM_STR/g" /etc/nslcd.conf
fi fi
...@@ -74,7 +75,7 @@ start() { ...@@ -74,7 +75,7 @@ start() {
cp -a /usr/etc/pam.d/sshd /etc/pam.d/sshd cp -a /usr/etc/pam.d/sshd /etc/pam.d/sshd
if [ "$CONFIG_AUTH_KRB5" = "y" ]; then if [ "$CONFIG_AUTH_KRB5" = "y" ]; then
if [ -z "$CONFIG_AUTH_KRB5_SERVER" ]; then if [ -z "$CONFIG_AUTH_KRB5_SERVER" ]; then
echo "Failed! CONFIG_AUTH_KRB5_SERVER empty!" echo "Failed! CONFIG_AUTH_KRB5_SERVER empty!" | tee $log_output
exit 0 exit 0
fi fi
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
# When called with "local_config" parameter, files with information about # When called with "local_config" parameter, files with information about
# dotconfig source are removed (used by SNMP) # dotconfig source are removed (used by SNMP)
log_output=/dev/kmsg
# We create a temporary file in /tmp, store all files in ramdisk # We create a temporary file in /tmp, store all files in ramdisk
tmpdir=/tmp tmpdir=/tmp
...@@ -37,7 +39,7 @@ if [ "$1" == "local_config" ]; then ...@@ -37,7 +39,7 @@ if [ "$1" == "local_config" ]; then
echo "config_ok" > "$tmpdir"/dot-config_status echo "config_ok" > "$tmpdir"/dot-config_status
fi fi
else else
echo "No /wr/etc/dot-config to use" >& 2 echo "No /wr/etc/dot-config to use" | tee $log_output >& 2
echo "no_config" > "$tmpdir"/dot-config_source echo "no_config" > "$tmpdir"/dot-config_source
echo "config_error" > "$tmpdir"/dot-config_status echo "config_error" > "$tmpdir"/dot-config_status
configured=false configured=false
...@@ -133,7 +135,7 @@ elif [ "$CONFIG_PTP_REMOTE_CONF" = "y" ]; then ...@@ -133,7 +135,7 @@ elif [ "$CONFIG_PTP_REMOTE_CONF" = "y" ]; then
tftp -g -r "$filename" -l $tmpconfig $host tftp -g -r "$filename" -l $tmpconfig $host
;; ;;
*) *)
echo "Invalid URL for ppsi.conf: \"$URL\"" >& 2 echo "Invalid URL for ppsi.conf: \"$URL\"" | tee $log_output >& 2
;; ;;
esac esac
if [ -f $tmpconfig ]; then if [ -f $tmpconfig ]; then
...@@ -142,5 +144,5 @@ elif [ "$CONFIG_PTP_REMOTE_CONF" = "y" ]; then ...@@ -142,5 +144,5 @@ elif [ "$CONFIG_PTP_REMOTE_CONF" = "y" ]; then
fi fi
else else
# no valid PTP option keep ppsi.conf with old postfix # no valid PTP option keep ppsi.conf with old postfix
echo "No valid PTP option in dot-config!" >& 2 echo "No valid PTP option in dot-config!" | tee $log_output >& 2
fi fi
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
PRE_FILE="/wr/etc/ppsi-pre.conf" PRE_FILE="/wr/etc/ppsi-pre.conf"
OUTPUT_FILE="/etc/ppsi.conf" OUTPUT_FILE="/etc/ppsi.conf"
DOTCONFIG_FILE="/wr/etc/dot-config" DOTCONFIG_FILE="/wr/etc/dot-config"
log_output=/dev/kmsg
unset JSON_FORMAT unset JSON_FORMAT
#decode script parameters #decode script parameters
...@@ -54,10 +55,10 @@ function get_fiber_delay_coeff() { ...@@ -54,10 +55,10 @@ function get_fiber_delay_coeff() {
IFS='=' read -a fpa <<< "$fiber_param" IFS='=' read -a fpa <<< "$fiber_param"
dc=${fpa[1]} dc=${fpa[1]}
else else
echo "$script_name: Unknown fiber=\"$fb\" in CONFIG_PORT"$i_port"_FIBER" echo "$script_name: Unknown fiber=\"$fb\" in CONFIG_PORT"$i_port"_FIBER" | tee $log_output
fi fi
else else
echo "$script_name: Invalid parameter fiber=\"$fb\" in CONFIG_PORT"$i_port"_FIBER" echo "$script_name: Invalid parameter fiber=\"$fb\" in CONFIG_PORT"$i_port"_FIBER" | tee $log_output
fi fi
fi fi
echo "$dc" echo "$dc"
...@@ -324,7 +325,7 @@ function set_instance_profile() { ...@@ -324,7 +325,7 @@ function set_instance_profile() {
eval ${lv}="ptp" eval ${lv}="ptp"
set_profile_for_PTP $inst set_profile_for_PTP $inst
elif [ -n "$p" ]; then elif [ -n "$p" ]; then
echo "$script_name: Invalid parameter profile=\"$p\" in ${inst}" echo "$script_name: Invalid parameter profile=\"$p\" in ${inst}" | tee $log_output
eval ${lv}="ha" eval ${lv}="ha"
else else
# default # default
...@@ -586,7 +587,7 @@ for i_port in {01..18}; do # scan all the physical ports ...@@ -586,7 +587,7 @@ for i_port in {01..18}; do # scan all the physical ports
&& [ "$ppsi_vlans" -le 4094 ] &> /dev/null; then && [ "$ppsi_vlans" -le 4094 ] &> /dev/null; then
v="$inst_vn[vlan]"; eval ${v}="$ppsi_vlans" v="$inst_vn[vlan]"; eval ${v}="$ppsi_vlans"
else else
echo "$script_name: Wrong value \"$ppsi_vlans\" in CONFIG_VLANS_PORT"$i_port"_VID" echo "$script_name: Wrong value \"$ppsi_vlans\" in CONFIG_VLANS_PORT"$i_port"_VID" | tee $log_output
continue; continue;
fi fi
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment