forked from sonic-otn/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
submit the otss and syncd-ot service shell
- Loading branch information
Showing
2 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/bin/bash | ||
|
||
function debug() | ||
{ | ||
/usr/bin/logger $1 | ||
/bin/echo `date` "- $1" >> ${DEBUGLOG} | ||
} | ||
|
||
function lock_service_state_change() | ||
{ | ||
debug "Locking ${LOCKFILE} from ${SERVICE}$DEV service" | ||
|
||
exec {LOCKFD}>${LOCKFILE} | ||
/usr/bin/flock -x ${LOCKFD} | ||
trap "/usr/bin/flock -u ${LOCKFD}" 0 2 3 15 | ||
|
||
debug "Locked ${LOCKFILE} (${LOCKFD}) from ${SERVICE}$DEV service" | ||
} | ||
|
||
function unlock_service_state_change() | ||
{ | ||
debug "Unlocking ${LOCKFILE} (${LOCKFD}) from ${SERVICE}$DEV service" | ||
/usr/bin/flock -u ${LOCKFD} | ||
} | ||
|
||
function wait_for_database_service() | ||
{ | ||
# Wait for redis server start before database clean | ||
until [[ $($SONIC_DB_CLI PING | grep -c PONG) -gt 0 ]]; do | ||
sleep 1; | ||
done | ||
|
||
# Wait for configDB initialization | ||
until [[ $($SONIC_DB_CLI CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; | ||
do sleep 1; | ||
done | ||
} | ||
|
||
# This function cleans up the tables with specific prefixes from the database | ||
# $1 the index of the database | ||
# $2 the string of a list of table prefixes | ||
function clean_up_tables() | ||
{ | ||
$SONIC_DB_CLI $1 EVAL " | ||
local tables = {$2} | ||
for i = 1, table.getn(tables) do | ||
local matches = redis.call('KEYS', tables[i]) | ||
for j,name in ipairs(matches) do | ||
redis.call('DEL', name) | ||
end | ||
end" 0 | ||
} | ||
|
||
start() { | ||
debug "Starting ${SERVICE}$DEV service..." | ||
|
||
lock_service_state_change | ||
|
||
wait_for_database_service | ||
|
||
$SONIC_DB_CLI APPL_DB FLUSHDB | ||
|
||
# start service docker | ||
/usr/bin/${SERVICE}.sh start $DEV | ||
debug "Started ${SERVICE}$DEV service..." | ||
|
||
# Unlock has to happen before reaching out to peer service | ||
unlock_service_state_change | ||
} | ||
|
||
wait() { | ||
if [[ ! -z $DEV ]]; then | ||
/usr/bin/docker-wait-any -s ${SERVICE}$DEV | ||
else | ||
/usr/bin/docker-wait-any -s ${SERVICE} | ||
fi | ||
} | ||
|
||
stop() { | ||
debug "Stopping ${SERVICE}$DEV service..." | ||
|
||
[[ -f ${LOCKFILE} ]] || /usr/bin/touch ${LOCKFILE} | ||
|
||
lock_service_state_change | ||
|
||
/usr/bin/${SERVICE}.sh stop $DEV | ||
debug "Stopped ${SERVICE}$DEV service..." | ||
|
||
# Unlock has to happen before reaching out to peer service | ||
unlock_service_state_change | ||
} | ||
|
||
DEV=$2 | ||
|
||
SERVICE="swss" | ||
DEBUGLOG="/tmp/swss-syncd-debug$DEV.log" | ||
LOCKFILE="/tmp/swss-syncd-lock$DEV" | ||
NAMESPACE_PREFIX="asic" | ||
if [ "$DEV" ]; then | ||
NET_NS="$NAMESPACE_PREFIX$DEV" #name of the network namespace | ||
SONIC_DB_CLI="sonic-db-cli -n $NET_NS" | ||
else | ||
NET_NS="" | ||
SONIC_DB_CLI="sonic-db-cli" | ||
fi | ||
|
||
case "$1" in | ||
start|wait|stop) | ||
$1 | ||
;; | ||
*) | ||
echo "Usage: $0 {start|wait|stop}" | ||
exit 1 | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
|
||
. /usr/local/bin/syncd_common.sh | ||
|
||
function stopplatform1() | ||
{ | ||
debug "shutdown syncd process ..." | ||
/usr/bin/docker exec -i syncd$DEV /usr/bin/syncd_request_shutdown --cold | ||
|
||
# wait until syncd quits gracefully or force syncd to exit after | ||
# waiting for 20 seconds | ||
start_in_secs=${SECONDS} | ||
end_in_secs=${SECONDS} | ||
timer_threshold=20 | ||
while docker top syncd$DEV | grep -q /usr/bin/syncd \ | ||
&& [[ $((end_in_secs - start_in_secs)) -le $timer_threshold ]]; do | ||
sleep 0.1 | ||
end_in_secs=${SECONDS} | ||
done | ||
|
||
if [[ $((end_in_secs - start_in_secs)) -gt $timer_threshold ]]; then | ||
debug "syncd process in container syncd$DEV did not exit gracefully" | ||
fi | ||
|
||
/usr/bin/docker exec -i syncd$DEV /bin/sync | ||
debug "Finished shutdown syncd process ..." | ||
} | ||
|
||
OP=$1 | ||
DEV=$2 | ||
|
||
SERVICE="syncd" | ||
DEBUGLOG="/tmp/swss-syncd-debug$DEV.log" | ||
LOCKFILE="/tmp/swss-syncd-lock$DEV" | ||
NAMESPACE_PREFIX="asic" | ||
if [ "$DEV" ]; then | ||
NET_NS="$NAMESPACE_PREFIX$DEV" #name of the network namespace | ||
SONIC_DB_CLI="sonic-db-cli -n $NET_NS" | ||
else | ||
NET_NS="" | ||
SONIC_DB_CLI="sonic-db-cli" | ||
fi | ||
|
||
case "$1" in | ||
start|wait|stop) | ||
$1 | ||
;; | ||
*) | ||
echo "Usage: $0 {start|wait|stop}" | ||
exit 1 | ||
;; | ||
esac |