deploy.py fails handling an existing PID file
At the very beginning of the script, we try to acquire a pidfile but it seems we don't handle the case where the pidfile already exists:
root@idc-bgd-drcroh-8b9f:~# python3 /usr/local/bin/deploy.py
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pid/base.py", line 198, in create
self._flock(self.fh.fileno())
File "/usr/local/lib/python3.5/dist-packages/pid/posix.py", line 22, in _flock
fcntl.flock(self.fh.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
BlockingIOError: [Errno 11] Resource temporarily unavailable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/deploy.py", line 246, in <module>
with PidFile('deploy.pid', piddir="/var/run/") as p:
File "/usr/local/lib/python3.5/dist-packages/pid/base.py", line 239, in __enter__
self.create()
File "/usr/local/lib/python3.5/dist-packages/pid/base.py", line 202, in create
raise PidFileAlreadyLockedError(exc)
pid.base.PidFileAlreadyLockedError: [Errno 11] Resource temporarily unavailable
The pidfile already exists:
root@idc-bgd-drcroh-8b9f:~# ls -l /var/run/deploy.pid
-rw-r--r-- 1 root root 5 Aug 5 18:29 /var/run/deploy.pid
This PID is the one from a command I ran manually 4 days ago:
root@idc-bgd-drcroh-8b9f:~# cat /var/run/deploy.pid
9765
root@idc-bgd-drcroh-8b9f:~# ps aux | fgrep 9765
root 7425 0.0 0.0 5116 884 pts/1 S+ 14:33 0:00 grep -F --color=auto 9765
root 9765 0.1 0.4 25060 18680 pts/0 S Aug05 9:52 python3 /usr/local/bin/olip_database_upgrade.py
(which should have completed long ago but that's for an other issue to be filled)
As a result, the Deploy process can not happen.