Exploit database

GH-abe2ad96b80b02d002d3372d650c1c9f

craigsblackie/cve-2026-88771-netscaler

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-88771

9 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files2

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

evidence/rootfs-72.61/netscaler/nsstartpe.sh

Shell · 27,836 bytes
#!/bin/sh
# NetScaler Startup script - part 2
#
# Copyright 1998-2026 Citrix Systems, Inc. All rights reserved.
# This software and documentation contain valuable trade
# secrets and proprietary property belonging to Citrix Systems, Inc.
# None of this software and documentation may be copied,
# duplicated or disclosed without the express
# written permission of Citrix Systems, Inc.
#
# Options:	NONE
#

# XXX FreeBSD 11.4 set up TMP / TEMP
TMP=/var/tmp;export TMP
TEMP=/var/tmp;export TEMP

NETSCALER=${NETSCALER:-`cat /var/run/.NETSCALER`}
[ -r ${NETSCALER}/netscaler.conf ] && . ${NETSCALER}/netscaler.conf

NCORE=`/sbin/sysctl -n netscaler.nCore`
SYSID=`/sbin/sysctl -n netscaler.sysid`
SDXVPX=`/sbin/sysctl -n netscaler.sdxvpx`
VPXONCLOUD=`/sbin/sysctl -n netscaler.vpx_on_cloud`
PYTHON="/var/python/bin/python"
AZUREFIRSTBOOT="/flash/nsconfig/.AZURE/firstboot"
GCPFIRSTBOOT="/flash/nsconfig/.GCP/firstboot"
ALIFIRSTBOOT="/flash/nsconfig/.ALI/firstboot"
IBMFIRSTBOOT="/flash/nsconfig/.IBM/firstboot"
HADAEMONTAR="/var/cloudhadaemon.tgz"
HADAEMON="/var/cloudhadaemon/"

RAINSCALETAR="/var/cloudautoscale.tgz"
RAINSCALE="/var/rainman"

#Variables for licenses specified through '-l' argument
#declare a LICENSE_<feature> here if needed
LICENSE_SSLI=0

HWPMC="/nsconfig/.hwpmc"

issmallvar()
{
	df -k /var | while read line
	do
		set -- $line
		case "$6" in
		"/var" )
			if [ $2 -lt 1048001 ]
			then
				return 1
			else
				return 0
			fi
			;;
		*)
			continue
			;;
		esac
	done
	return 0
}

runex()
{
	if [ -x $NETSCALER/$1 ]
	then
		$NETSCALER/$1 $2 &
		echo $1 >>$NSKILLLIST
	fi
}

runsh()
{
	if [ -r $NETSCALER/$1 ]
	then
		sh $NETSCALER/$1 $2 &
		echo $1 >>$NSSTOPLIST
	fi
}

run_constant_profiling()
{

	# Do not run constant profiling on non-nCore builds
	if [ $NCORE -ne 1 ]
	then
		return 0
	fi

	# Run constant profiling for all other platforms/builds
	runex nsproflog.sh "cpuuse=900 start"
}

mkdir_default_krb()
{
	BASE_PATH_KRB="/nsconfig/krb"
	BASE_PATH_LSCHEMA="/nsconfig/loginschema"

	if [ ! -d ${BASE_PATH_KRB} ]
	then
		mkdir -m 0777 ${BASE_PATH_KRB}
	fi

	if [ ! -d ${BASE_PATH_LSCHEMA} ]
	then
		mkdir -m 0777 ${BASE_PATH_LSCHEMA}
	fi
}

mkdir_default_app_catalog()
{
	BASE_PATH_APP_CATALOG="/var/app_catalog"

	if [ ! -d ${BASE_PATH_APP_CATALOG} ]
	then
		mkdir -m 0777 ${BASE_PATH_APP_CATALOG}
	fi
}

start_monit_on_iked()
{
	MONITRC=/etc/monitrc
	CHECK_IKED_PROCESS="check process iked with pidfile /var/run/iked.pid"

	if test "`grep \"$CHECK_IKED_PROCESS\" $MONITRC`"
	then
		return
	fi

	# back up the original file
	[ -f $MONITRC ] && [ ! -e $MONITRC.bak ] && cp -pf $MONITRC $MONITRC.bak

	echo "## Check iked, which is a daemon to do IKE handshake for IPSEC" >> $MONITRC
	echo $CHECK_IKED_PROCESS >> $MONITRC
	echo "  start program  \"/bin/sh /etc/iked_ctl start\"" >> $MONITRC
	echo "  stop program   \"/bin/sh /etc/iked_ctl stop\"" >> $MONITRC

	killall -HUP monit
}

start_monit_on_nskrb()
{
	MONITRC=/etc/monitrc
	CHECK_NSKRB_PROCESS="check process nskrb with pidfile /var/run/nskrb.pid"

	if test "`grep \"$CHECK_NSKRB_PROCESS\" $MONITRC`"
	then
		return
	fi

	# back up the original file
	[ -f $MONITRC ] && [ ! -e $MONITRC.bak ] && cp -pf $MONITRC $MONITRC.bak

	echo "## Check nskrb, the netscaler kerberos daemon" >> $MONITRC
	echo $CHECK_NSKRB_PROCESS >> $MONITRC
	echo "  start program  \"/bin/sh /etc/nskrb_ctl start\"" >> $MONITRC
	echo "  stop program   \"/bin/sh /etc/nskrb_ctl stop\"" >> $MONITRC

	killall -HUP monit
}

start_monit_on_du_daemon()
{
	MONITRC=/etc/monitrc
	CHECK_DU_DAEMON_PROCESS="check process du_daemon with pidfile /var/run/du_daemon.pid"

	if test "`grep \"$CHECK_DU_DAEMON_PROCESS\" $MONITRC`"
	then
		return 0
	fi

	# back up the original file
	[ -f $MONITRC ] && [ ! -e $MONITRC.bak ] && cp -pf $MONITRC $MONITRC.bak

	echo "## Check intel_crypto_du_daemon, a netscaler daemon" >> $MONITRC
	echo $CHECK_DU_DAEMON_PROCESS >> $MONITRC
	echo "  start program  \"/bin/sh /etc/du_daemon_ctl start\"" >> $MONITRC
	echo "  stop program   \"/bin/sh /etc/du_daemon_ctl stop\"" >> $MONITRC

	killall -HUP monit
}

start_monit_on_nscrlrefresh()
{
	MONITRC=/etc/monitrc
	CHECK_NSCRLREFRESH_PROCESS="check process nscrlrefresh with pidfile /var/run/nscrlrefresh.pid"

	if test "`grep \"$CHECK_NSCRLREFRESH_PROCESS\" $MONITRC`"
	then
		return
	fi

	# back up the original file
	[ -f $MONITRC ] && [ ! -e $MONITRC.bak ] && cp -pf $MONITRC $MONITRC.bak

	echo "## Check nscrlrefresh, a netscaler daemon" >> $MONITRC
	echo $CHECK_NSCRLREFRESH_PROCESS >> $MONITRC
	echo "  start program  \"/bin/sh /etc/nscrlrefresh_ctl start\"" >> $MONITRC
	echo "  stop program   \"/bin/sh /etc/nscrlrefresh_ctl stop\"" >> $MONITRC

	killall -HUP monit
}

start_monit_on_websocketd()
{
	MONITRC=/etc/monitrc
	CHECK_WEBSOCKETD_PROCESS="check process websocketd with pidfile /var/run/websocketd.pid"

	if test "`grep \"$CHECK_WEBSOCKETD_PROCESS\" $MONITRC`"
	then
		return
	fi

	# back up the original file
	[ -f $MONITRC ] && [ ! -e $MONITRC.bak ] && cp -pf $MONITRC $MONITRC.bak

	echo "## Check websocketd, a netscaler daemon" >> $MONITRC
	echo $CHECK_WEBSOCKETD_PROCESS >> $MONITRC
	echo "  start program  \"/bin/sh /etc/websocketd_ctl start\"" >> $MONITRC
	echo "  stop program   \"/bin/sh /etc/websocketd_ctl stop\"" >> $MONITRC

	killall -HUP monit
}

start_monit_on_safenet_gw()
{
	BASE_PATH_SAFENET="/var/safenet/safenet_is_enrolled"

	if [ ! -r "${BASE_PATH_SAFENET}" ]
	then
		return
	fi

	MONITRC=/etc/monitrc
	CHECK_SAFENET_GW_PROCESS="check process safenet_gw with pidfile /var/run/safenet_gw.pid"
	if test "`grep \"$CHECK_SAFENET_GW_PROCESS\" $MONITRC`"
	then
		return
	fi

	# back up the original file
	[ -f $MONITRC ] && [ ! -e $MONITRC.bak ] && cp -pf $MONITRC $MONITRC.bak

	echo "## Check safenet_gw, a netscaler daemon" >> $MONITRC
	echo $CHECK_SAFENET_GW_PROCESS >> $MONITRC
	echo " start program \"/bin/sh /etc/safenet_gw_ctl start\"" >> $MONITRC
	echo " stop program \"/bin/sh /etc/safenet_gw_ctl stop\"" >> $MONITRC

	killall -HUP monit
}

start_monit_on_nsazureagent()
{
	MONITRC=/etc/monitrc
	CHECK_NSAZUREAGENT_PROCESS="check process nsazureagent with pidfile /var/run/waagent.pid"

	if test "`grep \"$CHECK_NSAZUREAGENT_PROCESS\" $MONITRC`"
	then
		return
	fi

	# back up the original file
	[ -f $MONITRC ] && [ ! -e $MONITRC.bak ] && cp -pf $MONITRC $MONITRC.bak

	echo "## Check nsazureagent, azure agent daemon" >> $MONITRC
	echo $CHECK_NSAZUREAGENT_PROCESS >> $MONITRC
	echo "  start program  \"/bin/sh /etc/nsazureagent_ctl start\"" >> $MONITRC
	echo "  stop program   \"/bin/sh /etc/nsazureagent_ctl stop\"" >> $MONITRC

	killall -HUP monit
}

start_monit_on_nshastatusd()
{
	MONITRC=/etc/monitrc
	CHECK_NSHASTATUSD_PROCESS="check process nshastatusd with pidfile /var/run/hastatusd.pid"

	if test "`grep \"$CHECK_NSHASTATUSD_PROCESS\" $MONITRC`"
	then
		return
	fi

	# back up the original file
	[ -f $MONITRC ] && [ ! -e $MONITRC.bak ] && cp -pf $MONITRC $MONITRC.bak

	echo "## Check nshastatusd, NS HA state check daemon" >> $MONITRC
	echo $CHECK_NSHASTATUSD_PROCESS >> $MONITRC
	echo "  start program  \"/bin/sh /etc/nshastatusd_ctl start\"" >> $MONITRC
	echo "  stop program   \"/bin/sh /etc/nshastatusd_ctl stop\"" >> $MONITRC

	killall -HUP monit
}

start_monit_on_gcpaccountsd()
{
	MONITRC=/etc/monitrc
	CHECK_GCPACCOUNTSD_PROCESS="check process gcpaccountsd with pidfile /var/run/gcpaccountsd.pid"

	if test "`grep \"$CHECK_GCPACCOUNTSD_PROCESS\" $MONITRC`"
	then
		return
	fi

	# back up the original file
	[ -f $MONITRC ] && [ ! -e $MONITRC.bak ] && cp -pf $MONITRC $MONITRC.bak

	echo "## Check gcpaccountsd state check daemon" >> $MONITRC
	echo $CHECK_GCPACCOUNTSD_PROCESS >> $MONITRC
	echo "  start program  \"/bin/sh /etc/gcpaccountsd_ctl start\"" >> $MONITRC
	echo "  stop program   \"/bin/sh /etc/gcpaccountsd_ctl stop\"" >> $MONITRC

	killall -HUP monit
}

start_monit_on_nshaagent()
{
	MONITRC=/etc/monitrc
	CHECK_GCPHAAGENT_PROCESS="check process cloudhadaemon with pidfile /var/run/nscloudhaagent.pid"

	if test "`grep \"$CHECK_GCPHAAGENT_PROCESS\" $MONITRC`"
	then
		return
	fi

	# back up the original file
	[ -f $MONITRC ] && [ ! -e $MONITRC.bak ] && cp -pf $MONITRC $MONITRC.bak

	echo "## Check cloudhadaemon state check daemon" >> $MONITRC
	echo $CHECK_GCPHAAGENT_PROCESS >> $MONITRC
	echo "  start program  \"/bin/sh /etc/nscloudhaagent_ctl start\"" >> $MONITRC
	echo "  stop program   \"/bin/sh /etc/nscloudhaagent_ctl stop\"" >> $MONITRC

	killall -HUP monit
}

start_monit_on_rainscaleagent()
{
	MONITRC=/etc/monitrc
	if [ $VPXONCLOUD = "1" ] ; then
		CLOUD="AWS"
	elif [ $VPXONCLOUD = "3" ] ; then
		CLOUD="AZURE"
	elif [ $VPXONCLOUD = "4" ] ; then
		CLOUD="GCP"
	else
		return
	fi
	CHECK_RAINMAN_PROCESS="check process rainscaleagent with pidfile /flash/nsconfig/.$CLOUD/rain_scale.pid"

	if test "`grep \"$CHECK_RAINMAN_PROCESS\" $MONITRC`"
	then
		return
	fi

	# back up the original file
	[ -f $MONITRC ] && [ ! -e $MONITRC.bak ] && cp -pf $MONITRC $MONITRC.bak

	echo "## Check rainscaleagent state check daemon" >> $MONITRC
	echo $CHECK_RAINMAN_PROCESS >> $MONITRC
	echo "  start program  \"/bin/sh /etc/rainscaleagent_ctl start\"" >> $MONITRC
	echo "  stop program   \"/bin/sh /etc/rainscaleagent_ctl stop\"" >> $MONITRC

	killall -HUP monit
}


start_monit_on_customsnmpd()
{
	MONITRC=/etc/monitrc
	CHECK_CSNMPD_DAEMON_PROCESS="check process customsnmpd with pidfile /var/run/customsnmpd.pid"

	if test "`grep \"$CHECK_CSNMPD_DAEMON_PROCESS\" $MONITRC`"
	then
		return 0
	fi

	echo "## Check csnmpd daemon, a netscaler daemon" >> $MONITRC
	echo $CHECK_CSNMPD_DAEMON_PROCESS >> $MONITRC
	echo "  start program  \"/bin/sh /etc/customsnmpd_ctl start\"" >> $MONITRC
	echo "  stop program   \"/bin/sh /etc/customsnmpd_ctl stop\"" >> $MONITRC

	killall -HUP monit
}

start_ptp_on_cluster()
{
	NS_CONF="/nsconfig/ns.conf"
	CHECK_CLUSTER_INSTANCE="add cluster instance"

	if test "`grep \"$CHECK_CLUSTER_INSTANCE\" \"$NS_CONF\"`"
	then
		CLUSTER=1
	else
		CLUSTER=0
	fi

	if [ $CLUSTER -eq 1 ]
	then
		runex ptpd
		echo "PTPd started!!\n"
	fi
}

check_customtrap()
{
	NS_CONF="/nsconfig/ns.conf"
	CHECK_CUSTOM_OPTION="customTrap ENABLED"

	if ! grep -q "$CHECK_CUSTOM_OPTION" "$NS_CONF"
	then
		chmod u+w /etc/crontab
		sed -i '' '/custom_snmpd.py/d' /etc/crontab 2>/dev/null
		chmod u-w /etc/crontab
	else
		if ! grep -q "custom_snmpd.py" /etc/crontab
		then
			chmod u+w /etc/crontab
			echo "root   lockf -t 0 -k -s /tmp/.customsnmpd_lock /var/python/bin/python3 /netscaler/custom_snmpd.py" >> /etc/crontab
			chmod u-w /etc/crontab
		fi
	fi
}

: >$NSSTOPLIST
: >$NSKILLLIST

# This function parses comma seperated list of available licenses
# and sets LICENSE_<feature> variable to 1 (whose initial value is 0)
# This variable can be used to perform actions based on availability of
# specific licenses
# ps:To pass new license to this script, change function start_daemons() in nsboot.c
parse_licenses()
{
	LICENSES=$(echo $1 | tr "," "\n")
	for lic in $LICENSES
	do
		case $lic in
		"ssli") LICENSE_SSLI=1
			;;
		esac
	done
}

# Parses arguments
parse_args()
{
	while getopts "l:" arg; do
		case $arg in
		l)
			parse_licenses $OPTARG
			;;
		esac
	done
}

parse_args $*

smp=""
[ -f ${NSCONFIG}/.nssmp ] && smp="-s"

# The former contents of nsstart_pre_nsconfread.sh:
runex nsgslbautosync daemon
runex nsmap "-l"
runex nsaggregatord
runex nsclusterd
# (end of former contents of nsstart_pre_nsconfread.sh)

runex monuploadd

echo -e "\nStarting NSconfigd now..."
$NETSCALER/nsconfigd -S
echo -e "\nNsconfigd started successfully"

# tell pitboss we're in third stage initialization
$NETSCALER/pb_tool -s 3

# NextGen API upgrade script to run once at time of upgrade only
[ -r $NSCONFIG/nsnextgen_upgrade.sh ] 	&& sh $NSCONFIG/nsnextgen_upgrade.sh && rm -f $NSCONFIG/nsnextgen_upgrade.sh
# start NextGen API infra
$PYTHON -m ngapi_lib.ngapictl.main --bootup &

runex nsfsyncd -d

# start nsfsyncd client

[ -f /etc/crontab ] && [ ! -e /etc/crontab.bak ] && \
        cp -pf /etc/crontab /etc/crontab.bak
# Avoid duplicate nsfsyncd entries in the case that /etc/crontab
# is a link to /nsconfig/crontab, and this linked file has nsfsyncd
# entries (by mistake).
chmod u+w /etc/crontab
[ ! -f /tmp/.nsfsyncd_lock ]  && touch /tmp/.nsfsyncd_lock && chmod 600 /tmp/.nsfsyncd_lock
sed -i '' '/nsfsyncd/d' /etc/crontab 2>/dev/null
echo "*       *       *       *       *       root   lockf -t 0 -k -s /tmp/.nsfsyncd_lock /netscaler/nsfsyncd -p" >> /etc/crontab
chmod u-w /etc/crontab

NSSDPROXY_SYSID="450094"
if [ $SYSID = $NSSDPROXY_SYSID ] ;then
	# start nsconnector logging script if this is a nsconnector image.
	if ! grep nsconnector_logger.py /etc/crontab > /dev/null 2>&1; then
		# back up the original file
		[ -f /etc/crontab ] && [ ! -e /etc/crontab.bak ] && \
			cp -pf /etc/crontab /etc/crontab.bak
		# Trigger the logging script every 2 minutes.
		chmod u+w /etc/crontab
		echo "*/2       *       *       *       *       root    /var/python/bin/python /netscaler/nsconnector_logger.py" >> /etc/crontab
		chmod u-w /etc/crontab
	fi

	# start nsconnector logging clean up script if this is a nsconnector image.
	if ! grep nsconnector_disk_clean_up.py /etc/crontab > /dev/null 2>&1; then
		# back up the original file
		[ -f /etc/crontab ] && [ ! -e /etc/crontab.bak ] && \
			cp -pf /etc/crontab /etc/crontab.bak
		# Trigger the logging script every 2 minutes.
		chmod u+w /etc/crontab
		echo "*       */24       *       *       *       root    /var/python/bin/python /netscaler/nsconnector_disk_clean_up.py" >> /etc/crontab
		chmod u-w /etc/crontab
	fi

	chmod a+rwx,u-w,g-w,o-w /netscaler/connectivity_test.py
	touch /var/nsconnector/connectivity.json
	touch /var/log/connectivity_check.log
	chmod a+rw /var/nsconnector/connectivity.json
	chmod a+rw /var/log/connectivity_check.log

	# start upgrade script if not started
	if ! grep connector_upgrade.py /etc/crontab > /dev/null 2>&1; then
		# back up the original file
		[ -f /etc/crontab ] && [ ! -e /etc/crontab.bak ] && \
			cp -pf /etc/crontab /etc/crontab.bak
		# Trigger the connector upgrade script every 10 minutes
		chmod u+w /etc/crontab
		echo "*/10       *       *       *       *       root    /var/python/bin/python /netscaler/connector_upgrade.py" >> /etc/crontab
		chmod u-w /etc/crontab
	fi
fi

# start URLSET auto update process
if [ -s /var/download/mapping-urlset ]; then
	if [ -x "$NETSCALER/auto_update_urlset" ]; then
		echo -e "\nStarting auto_update_urlset now..."
		$NETSCALER/auto_update_urlset
	fi
fi

runex nsreadfile
runex imi "-d"
runex migrate_ZebOS.sh "--restart-daemons"
# -Q - check that we really have LCD at the serial port
#runex nslcd "-kQ"
# -Q (read on lcd port) is failing at many places [hardware problem]
###
# DO NOT run nslcd on platforms that do not have LCD
# - 450xxx: VPXs
# - 560xxx: MPX-16000s (Wente)
# -  35xxx: MPX-9100s (Matua)
if   [ $(($SYSID/1000)) -ne 450 ] \
  && [ $(($SYSID/1000)) -ne 560 ] \
  && [ $(($SYSID/1000)) -ne  35 ]; then
	runex nslcd "-k"
fi

#Any daemon that would be monitored by monit needs
#capabilities to dynamically edit the monitrc file in nsstartpe.sh
#monitrc file should not be hardcoded with netscaler daemons !
#Follow the below primer for future monit clients

#spawning nscrlrefresh
killall nscrlrefresh
rm -f /var/run/nscrlrefresh.pid
/bin/sh /etc/nscrlrefresh_ctl start
#Dynamically append monitrc file to include nscrlrefresh
start_monit_on_nscrlrefresh

#spawning websocketd
killall websocketd
rm -f /var/run/websocketd.pid
/bin/sh /etc/websocketd_ctl start
#Dynamically append monitrc file to include websocketd
start_monit_on_websocketd

#spawning admautoregd and mastools
/bin/sh /var/mastools/scripts/admautoreg/admautoregd_ctl startup

#Start nskrb daemon
rm -f /var/run/nskrb.pid
runex nskrb "nsauth"
start_monit_on_nskrb
mkdir_default_krb

#start safenet_gw daemon
if [ -r "/var/safenet/safenet_is_enrolled" ]
then
	killall safenet_gw
	rm -f /var/run/safenet_gw.pid
	/bin/sh /etc/safenet_gw_ctl start boot
	#Dynamically append monitrc file to include safenet_gw
	start_monit_on_safenet_gw
fi

runex nsslapapp
runex nsaaad "-n 10 -p 8766"
# In Tagma release, we are not supporting advanced EPA. So, now we no more need epa service running.
#runex nsepasvc /* Review with Bharat */
killall iked
rm -f /var/run/iked.pid
runex iked
start_monit_on_iked

runex aslearn "-start -f /netscaler/aslearn.conf"
runex snmpd
# The check for SSL Interception feature license is removed and certforger daemon will be running as
# it will be used for Dynamic Client Certificate Generation (C3D) feature also.
# Even after removal of check, the SSL Interception feature won't be available to users as the
# Forward proxy feature is also required for it.
runex nscertforgerd

#nscertfetcher: daemon periodically interacts with ADM and PE to keep the PE
# in-memory zero touch cert store in sync with ADM.
runex nscertfetcher

$NETSCALER/nsclfsyncd -s

# XXX until nsaggregatord problem is resolved
runsh nslog.sh "start $NSLOG_OPTIONS"
runsh nssync.sh "start"
runsh nsumon.sh "start"
if [ $SYSID = "450000" ] || [ $SDXVPX = "1" ]
then
	runsh nsvpx-distribution.sh "start"
fi

$NETSCALER/nscfsyncd -s

runex syshealthd
runex nscac64p

check_customtrap
start_monit_on_customsnmpd
# Only start nscollect when there is enough room
issmallvar
if [ $? -eq 1 ]
then
	echo "/var size < 1GB: nscollect not started"
else
	runex datadaemon
	runex nscollect "start"
	runex nscollect "aggmode"
fi
runex metricscollector
# Uncomment the line below to enable Netscaler apachemon daemon.
#runex apachemon
# Uncomment the line below to enable Netscaler syslog daemon.
#runex nsconmsg "-s syslog=1 -d eventwait"

# Run constant profiling on selected platforms/builds.
run_constant_profiling

# Set "set system parameter -forcePasswordChange ENABLED" for On-Prem VPX
if [ $VPXONCLOUD -eq 0 ] ; then
	if   [ $SYSID -eq 450000 ] \
	  || [ $SYSID -eq 450010 ] \
	  || [ $SYSID -eq 450020 ] \
	  || [ $SYSID -eq 450070 ] ; then
		#SYSIDs correspond to VPX on Xen, ESX, HyperV and KVM respectively
		/netscaler/NSVAconf -p
	fi
fi

if [ $SYSID = "450040" ] ;then
	if [ -e /flash/nsconfig/.AWS/firstboot ] ; then
		echo "AWS configuring network ... calling NSVAconf "
		mkdir -p /var/nstmp/awsconfigd
		# back up the original file
		[ -f /etc/resolv.conf ] && [ ! -e /etc/resolv.conf.bak ] && \
			cp -pf /etc/resolv.conf /etc/resolv.conf.bak
		cp /flash/nsconfig/.AWS/resolv.conf /etc/resolv.conf

		if [ -f $HADAEMONTAR ] ; then
			cd /var
			tar zxf $HADAEMONTAR
			if [ $? -ne 0 ]; then
				echo "hadaemon extraction failed!!\n"
			fi
			cd /var/cloudhadaemon/
			$PYTHON -m pip install . --no-index --no-deps --no-build-isolation
			if [ $? -ne 0 ]; then
				echo "hadaemon installation failed!!\n"
			fi
			rm -rf $HADAEMON
			rm $HADAEMONTAR
		else
			echo "hadaemon package is not present!! \n"
		fi
		if [ -f $RAINSCALETAR ] ; then
			cd /var
			tar zxf $RAINSCALETAR
			if [ $? -ne 0 ]; then
				echo "rainscale extraction failed!!\n"
			else
				cd $RAINSCALE
				$PYTHON -m pip install . --no-index --no-deps --no-build-isolation
				if [ $? -ne 0 ]; then
					echo "rainscale installation failed!!\n"
				fi
			fi
			rm -rf $RAINSCALE
			rm $RAINSCALETAR
		else
			echo "rainscale package is not present!! \n"
		fi
	fi

	if [ ! -e /nsconfig/aws_bootstrap ] ; then
		/netscaler/aws_bootstrap.sh
	fi

	#Check hostname after stop/start/reboot in Cloud Instance

	/netscaler/aws_reboot_hostname_check.sh

	/netscaler/NSVAconf -f

	# NSVAconf ensure PE is up.



	start_monit_on_nshastatusd
	#Registering HA daemon with monitd
	start_monit_on_nshaagent
	start_monit_on_rainscaleagent
fi

# Start PTPd
start_ptp_on_cluster

# start nscopo daemon
runex nscopo "-vv -p"

if [ $VPXONCLOUD = "5" ] ; then
	if [ -f $ALIFIRSTBOOT ] ; then
		# back up the original file
		[ -f /etc/resolv.conf ] && [ ! -e /etc/resolv.conf.bak ] && \
			cp -pf /etc/resolv.conf /etc/resolv.conf.bak
		cp /flash/nsconfig/.ALI/resolv.conf /etc/resolv.conf
	fi
	/netscaler/NSVAconf -f
fi

if [ $VPXONCLOUD = "6" ] ; then
	if [ -f $IBMFIRSTBOOT ] ; then
		# back up the original file
		[ -f /etc/resolv.conf ] && [ ! -e /etc/resolv.conf.bak ] && \
			cp -pf /etc/resolv.conf /etc/resolv.conf.bak
		cp /flash/nsconfig/.IBM/resolv.conf /etc/resolv.conf
		echo "IBM FIRSTboot\n"
		if [ -f $LIBNITROTAR ] ; then
			cd /var
			tar zxf $LIBNITROTAR
			if [ $? -ne 0 ]; then
				echo "libnitrocli extraction failed!!\n"
			fi
			cd /var/libnitrocli/
			$PYTHON -m pip install /var/libnitrocli/ --no-index --no-deps --no-build-isolation
			if [ $? -ne 0 ]; then
				echo "libnitrocli installation failed!!\n"
			fi
		else
			echo "libnitrocli package is not present!! \n"
		fi
	fi
	/netscaler/NSVAconf -f
fi

if [ $VPXONCLOUD = "3" ] ; then
	# back up the original file
	[ -f /etc/resolv.conf ] && [ ! -e /etc/resolv.conf.bak ] && \
		cp -pf /etc/resolv.conf /etc/resolv.conf.bak
	cp /flash/nsconfig/.AZURE/resolv.conf /etc/resolv.conf
	if [ -f $AZUREFIRSTBOOT ] ; then
		/netscaler/NSVAconf -f
	fi
	start_monit_on_nshastatusd
	start_monit_on_nsazureagent
	start_monit_on_nshaagent
	start_monit_on_rainscaleagent
fi

if [ $VPXONCLOUD = "4" ] ; then
	if [ -f $GCPFIRSTBOOT ] ; then

		if [ -f $HADAEMONTAR ] ; then
			cd /var
			tar zxf $HADAEMONTAR
			if [ $? -ne 0 ]; then
				echo "hadaemon extraction failed!!\n"
			fi
			cd /var/cloudhadaemon/
			$PYTHON -m pip install . --no-index --no-deps --no-build-isolation
			if [ $? -ne 0 ]; then
				echo "hadaemon installation failed!!\n"
			fi
		else
			echo "hadaemon package is not present!! \n"
		fi

		if [ -f $RAINSCALETAR ] ; then
			cd /var
			tar zxf $RAINSCALETAR
			if [ $? -ne 0 ]; then
				echo "rainscale extraction failed!!\n"
			else
				cd $RAINSCALE
				$PYTHON -m pip install . --no-index --no-deps --no-build-isolation
				if [ $? -ne 0 ]; then
					echo "rainscale installation failed!!\n"
				fi
			fi
		else
			echo "rainscale package is not present!! \n"
		fi

	fi
	# NSVAconf is invoked for a second time on first boot,
	# to reset password of nsroot account
	/netscaler/NSVAconf -f

	rm $GCPFIRSTBOOT

	GCP_PID_FILE="/var/run/gcpaccountsd.pid"
	cat /etc/sshd_config | grep -v "AuthorizedKeysFile" > /var/tmp/sshdconfig_backup
	echo "AuthorizedKeysFile %h/.ssh/authorized_keys" >> /var/tmp/sshdconfig_backup
	# back up the original file
	[ -f /etc/sshd_config ] && [ ! -e /etc/sshd_config.bak ] && \
		cp -pf /etc/sshd_config /etc/sshd_config.bak
	mv /var/tmp/sshdconfig_backup /etc/sshd_config
	killall sshd
	/usr/sbin/sshd -f /etc/sshd_config
	/var/python/bin/python /var/python/bin/google_accounts_daemon &
	rm $GCP_PID_FILE
	touch $GCP_PID_FILE
	chmod 600 $GCP_PID_FILE
	ps -aux | grep google_accounts_daemon | grep -v grep | awk '{print $2}' > $GCP_PID_FILE
	# Registering GCP accounts daemon with monitd.
	start_monit_on_gcpaccountsd

	start_monit_on_nshastatusd
	#Registering HA daemon with monitd
	start_monit_on_nshaagent
	start_monit_on_rainscaleagent
fi

# For GCP & KVM remove rainscale install package.
if [ $SYSID = "450070" ] ;then
	rm $RAINSCALETAR
	rm -rf $RAINSCALE
fi

# start nstraceaggregator
runex nstraceaggregator

#Part of ENH0617478. Following change for OpenStack only.
#First boot execution only. Calling NSVAConf second time
#to set random password for nsroot.
if [ $VPXONCLOUD -eq 2 ] ; then
	if [ -r /tmp/openstack/password ] ; then
		/netscaler/NSVAconf -f
		rm /tmp/openstack/password
	fi
fi

#Checks /nsconfig/.hwpmc file before starting Intel HWPMC stats collection
#If not present, it has to be created manually to start collection
if [ -f $HWPMC ]; then
	$PYTHON /netscaler/start_hwpmc.py
	echo "$HWPMC found. Start recording hwpmc"
fi

[ -r $NSCONFIG/nsafter.sh ] && sh $NSCONFIG/nsafter.sh


# Part of ENH0617478. Following change for OpenStack only.
# As part of this enhancement, nsbefore and nsafter files
# will be modified in NSVAconf. Once nsbefore.sh and
# nsafter.sh executed with custome entries, those files
# needs to be reverted back with orginal one or removed (if not exists previously)
# Following code takes care of restoring original copy or removing
# nsafter file (if does not exists.) Removing file will work only on first boot.
if [ $VPXONCLOUD -eq 2 ] ; then
	if [ -r /var/nsafter.sh.bk ] ; then
		mv /var/nsafter.sh.bk $NSCONFIG/nsafter.sh
	elif [ -r /tmp/firstboot ] ; then
		#You will come to this logic only first time.
		#If there was no previous copy, delete file as
		# it will contain commands with nscli 127.0.0.1:nsroot which should
		# not be exposed to customer
		[ -r $NSCONFIG/nsafter.sh ] && rm $NSCONFIG/nsafter.sh
		rm /tmp/firstboot
	fi
fi
[ -r $NSCONFIG/nsafterupgrade.sh ] && sh $NSCONFIG/nsafterupgrade.sh && rm -f $NSCONFIG/nsafterupgrade.sh

#On devices with Intel crypto cards, start device utilization daemon
NUM_COLETO_DEVICES=`/sbin/sysctl -n netscaler.ns_coleto_devices`
NUM_LWS_DEVICES=`/sbin/sysctl -n netscaler.ns_lewisburg_devices`
NUM_QAT2_0_DEVICES=`/sbin/sysctl -n netscaler.ns_qat2_0_devices`
hypervised_ns=`/sbin/sysctl -n netscaler.hypervised_ns`	#sysctl output looks like "netscaler.hypervised_ns: 0"
#If the variables are null for whatever reason, set them to 0 instead
hypervised_ns=${hypervised_ns:=0}
NUM_COLETO_DEVICES=${NUM_COLETO_DEVICES:=0}
NUM_LWS_DEVICES=${NUM_LWS_DEVICES:=0}
NUM_QAT2_0_DEVICES=${NUM_QAT2_0_DEVICES:=0}
if ( [ $NUM_COLETO_DEVICES -ne 0 ] || [ $NUM_LWS_DEVICES -ne 0 ] || [ $NUM_QAT2_0_DEVICES -ne 0 ] ) \
   && [ $hypervised_ns -eq 0 ]; then
	DU_DAEMON="du_daemon"
	du_pid=`pgrep -x $DU_DAEMON`
	if [ "x$du_pid" == "x" ]
	then
		rm -f /var/run/du_daemon.pid
		/bin/sh /etc/du_daemon_ctl start
	fi

	#Dynamically append monitrc file to include intel_crypto_du_daemon
	start_monit_on_du_daemon
fi

# Start for fix: NSHELP-22507

# Wait till ns.conf is completely loaded before running
# configuration/nsapimgr knobs in rc.netscaler
# to avoid issues like NSHELP-22507, BUG0357011.

# to capture output of ns_get_nsconf_read_end()
TMP_NSSTARTPE_WAIT_FILE=$(mktemp /var/tmp/nsstartpe.sh.tmp.$$.XXXXXX)
> $TMP_NSSTARTPE_WAIT_FILE

nsconmsg -d consmsg > $TMP_NSSTARTPE_WAIT_FILE &
NSCONMSG_CMD_PID=$!

# read number of PEs
NUMPE=$(sysctl -n netscaler.num_pe_running)

nsapimgr_wr.sh -ys call=ns_get_nsconf_read_end > /dev/null

i=0
NSLOAD_MAX_WAIT_ATTEMPTS=15

while [ $i -lt $NSLOAD_MAX_WAIT_ATTEMPTS ]
do
	i=$(( $i + 1 ))

	# For nsconmsg to write output to file
	sleep 1

	# is loading of ns.conf done ?
	NUMPE_INIT_DONE=$(grep 'nsconf_read_end:1' $TMP_NSSTARTPE_WAIT_FILE | wc -l)

	[ $NUMPE_INIT_DONE -ge $NUMPE ] && break
done

if [ $i == $NSLOAD_MAX_WAIT_ATTEMPTS ] && [ $NUMPE_INIT_DONE != $NUMPE ]
then
	echo "\nLoading ns.conf did not complete in $NSLOAD_MAX_WAIT_ATTEMPTS seconds, commands in rc.netscaler might not be effective."
fi
#kill the nsconmsg started above
kill -9 $NSCONMSG_CMD_PID
rm -f $TMP_NSSTARTPE_WAIT_FILE

# End of fix: NSHELP-22507

[ -r $NSCONFIG/rc.netscaler ]	&& sh $NSCONFIG/rc.netscaler

# Update the cpusets for non-PE components
cpus=$(sysctl netscaler.cpus_in_mgmt_pool | sed -n -e 's/^.*(s) //p')
case $cpus in
*,* )
	# kernel process (needs to be done in two steps)
	cpuset -C -l $cpus -p 0
	cpuset -c -l $cpus -p 0
	# default cpuset
	cpuset -c -l $cpus -s 1
	;;
esac


emgmt_cpu_count=$(sysctl netscaler.additional_mgmt_cpu)

ns_smt_handling_sysctl=$(($(sysctl -n netscaler.smt_handling)))
if [ $ns_smt_handling_sysctl -eq 1 ] || [ -f /nsconfig/.smt_handling ]
then
	ns_smt_handling=1
else
	ns_smt_handling=0
fi

emCpuCount=$(echo $emgmt_cpu_count | (cut -d: -f2 ))
fpath=/nsconfig/extramgmtcpu.conf
if [ $SDXVPX = "0" ] && [ $emCpuCount != 0 ] && [ $ns_smt_handling -eq 0 ]; then
	> $fpath
else
	rm -f $fpath
fi

echo -e "\nStarting management log exporting..."
$PYTHON /netscaler/logexport.py start &
echo -e "\nmanagement log exporting started successfully"

exit 0
# vim: set noet ts=4: