Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[teamd]: Add teamd.sh start script to clean up STATE database #2250

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dockers/docker-teamd/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
rm -f /var/run/rsyslogd.pid
rm -f /var/run/teamd/*

if [[ x"$WARM_BOOT" != x"true" ]]; then
for pc in `ip link show | grep PortChannel | awk -F "[ :]" '{print $3}'`;
do ip link delete dev $pc
done
fi

mkdir -p /var/warmboot/teamd

supervisorctl start rsyslogd
Expand Down
5 changes: 2 additions & 3 deletions files/build_templates/teamd.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ After=updategraph.service

[Service]
User={{ sonicadmin_user }}
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we remove this one?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In stead of removing, we can just replace existing script.


In reply to: 232916218 [](ancestors = 232916218)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's better to align all these scripts later we could have some common functions that could simplify these scripts all together

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the unused scripts should be removed.

ExecStart=/usr/bin/{{docker_container_name}}.sh attach
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
ExecStart=/usr/local/bin/{{docker_container_name}}.sh attach
ExecStop=/usr/local/bin/{{docker_container_name}}.sh stop

[Install]
WantedBy=multi-user.target
61 changes: 61 additions & 0 deletions files/scripts/teamd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

SERVICE="teamd"
DEBUGLOG="/tmp/teamd-debug.log"

function debug()
{
/bin/echo `date` "- $1" >> ${DEBUGLOG}
}

function wait_for_database_service()
{
# Wait for redis server start before database clean
until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]];
do sleep 1;
done

# Wait for configDB initialization
until [[ $(/usr/bin/docker exec database redis-cli -n 4 GET "CONFIG_DB_INITIALIZED") ]];
do sleep 1;
done
}

function clean_up_tables()
{
redis-cli -n $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} service..."

wait_for_database_service

clean_up_tables 6 "LAG_TABLE*"

/usr/bin/${SERVICE}.sh start
/usr/bin/${SERVICE}.sh attach
}


stop() {
debug "Stopping ${SERVICE} service..."
/usr/bin/${SERVICE}.sh stop
}

case "$1" in
start|stop)
$1
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac