sonic-buildimage/dockers/docker-database/flush_unused_database
Myron Sosyak 5ab300b626
Fix python version (#7658)
#### Why I did it
To avoid the following logs 
```
Mar 15 15:52:04.599302 igk-dut-04 INFO database#/supervisord: flushdb /bin/bash: /usr/local/bin/flush_unused_database: /usr/bin/python: bad interpreter: No such file or directory
Mar 15 15:52:04.599947 igk-dut-04 INFO database#supervisord 2021-03-15 15:52:04,599 INFO exited: flushdb (exit status 126; not expected)
```

#### How I did it
Fix  shebang
#### How to verify it
Check the logs
2021-05-20 15:47:46 -07:00

29 lines
804 B
Python
Executable File

#!/usr/bin/python3
import swsssdk
import redis
import subprocess
import time
while(True):
output = subprocess.Popen(['sonic-db-cli', 'PING'], stdout=subprocess.PIPE).communicate()[0]
if 'PONG' in output:
break
time.sleep(1)
instlists = swsssdk.SonicDBConfig.get_instancelist()
for instname, v in instlists.items():
insthost = v['hostname']
instsocket = v['unix_socket_path']
dblists = swsssdk.SonicDBConfig.get_dblist()
for dbname in dblists:
dbid = swsssdk.SonicDBConfig.get_dbid(dbname)
dbinst = swsssdk.SonicDBConfig.get_instancename(dbname)
# this DB is on current instance, skip flush
if dbinst == instname:
continue
r = redis.Redis(host=insthost, unix_socket_path=instsocket, db=dbid)
r.flushdb()