mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-18 10:46:22 +00:00
Fix double-printed logs after container restart
This commit is contained in:
parent
72ed2883fe
commit
761a0cbd82
@ -1,3 +1,4 @@
|
||||
* Fix duplicate logs issue [Kostas]
|
||||
* **[Breaking]** Do not bind mount /run/dbus to /run/dbus [Pablo]
|
||||
* Default to not bind mounting kmod if container distro can't be found [Pablo]
|
||||
* Use log-timestamp to add timestamps to logs [Pablo]
|
||||
|
@ -3,6 +3,7 @@ Docker = require 'dockerode'
|
||||
PUBNUB = require 'pubnub'
|
||||
Promise = require 'bluebird'
|
||||
es = require 'event-stream'
|
||||
Lock = require 'rwlock'
|
||||
|
||||
disableLogs = false
|
||||
|
||||
@ -52,17 +53,25 @@ exports.log = ->
|
||||
publish(arguments...)
|
||||
|
||||
do ->
|
||||
_lock = new Lock()
|
||||
_writeLock = Promise.promisify(_lock.async.writeLock)
|
||||
loggerLock = (containerId) ->
|
||||
_writeLock(containerId)
|
||||
.disposer (release) ->
|
||||
release()
|
||||
|
||||
attached = {}
|
||||
exports.attach = (app) ->
|
||||
if !attached[app.containerId]
|
||||
dockerPromise.then (docker) ->
|
||||
docker.getContainer(app.containerId)
|
||||
.attachAsync({ stream: true, stdout: true, stderr: true, tty: true })
|
||||
.then (stream) ->
|
||||
attached[app.containerId] = true
|
||||
stream.pipe(es.split())
|
||||
.on('data', publish)
|
||||
.on 'error', ->
|
||||
attached[app.containerId] = false
|
||||
.on 'end', ->
|
||||
attached[app.containerId] = false
|
||||
Promise.using loggerLock(app.containerId), ->
|
||||
if !attached[app.containerId]
|
||||
dockerPromise.then (docker) ->
|
||||
docker.getContainer(app.containerId)
|
||||
.attachAsync({ stream: true, stdout: true, stderr: true, tty: true })
|
||||
.then (stream) ->
|
||||
attached[app.containerId] = true
|
||||
stream.pipe(es.split())
|
||||
.on('data', publish)
|
||||
.on 'error', ->
|
||||
attached[app.containerId] = false
|
||||
.on 'end', ->
|
||||
attached[app.containerId] = false
|
||||
|
Loading…
Reference in New Issue
Block a user