Run docker with image build from source code
steps
- sudo mvn install -DskipTests -Ddockerfile.skip=falseto build docker image
- sudo docker tag thingsboard/tb-postgres saiyn/thingsboardto update the image which will be replaced in tht running container
- sudo docker-compose stopto stop container
- sudo cat ~/mytb-data/db/postmaster.pidto check the process of postgres int the container
- wait for a moment to let the stop done, and then sudo docker run -it -v ~/.mytb-data:/data --rm saiyn/thingsboard upgrade-tb.sh
if everythings goes fine, then we should see logs like below:

- sudo ls ~/.mytb-data/dbto check postmaster.pid exist or not, it should be gone otherwise we will get troblue later
- sudo docker-compose rm mytbto remove the old container
- sudo docker-compose up -dto bring everything up to work and all process done
Notes when rebuild and deploy a new docker image
tb-postgres的image内部嵌入了postgres server, 启动逻辑是如果检测到~/.mytb-data/目录下如果有db目录,那就不会在去创建postgres server,这样导致重新build no cache的image进行
运行后出现无法连接到postgres server的问题。
另外在~/.mytb-data/目录下还会生成如下两个隐藏文件,如果不删除.firstxx会导致新建的postgres不会创建默认的thingsboard db.
所以,在build出新的iamge后,需要删除~/.mytb-data/目录下的db和隐藏文件,不过应该考虑更好的做法。

code flow
bulk import csv data
  AbstractBulkImportService (saveKvs()) -> DefaultTelemetrySubscriptionService (saveANdNotify()) -> BaseTimeseriresService (save()) ->  
    -> savePartition()
    -> saveLatest()
    -> save()
    
backup
script rule node
parse Gps
var new_meta = JSON.stringify(metadata, function(key, value){
    switch (key) {
        case 'ts':
            return new Date().getTime(); 
        
        default:
            return value;
    }
});
var longit = msg.gps.longit;
var latitu = msg.gps.latitu;
var du = Math.floor((Math.floor(longit) / 100));
var fen = parseInt((Math.floor(longit) / 100 + "").split(".")[1]);
var miao = parseInt((longit + "").split(".")[1]) * 60 / 1000000;
var longit_new = parseFloat((du + fen / 60 + miao / 60 / 60).toFixed(6));
var new_msg = {
    longit : longit_new,
    latitu : latitu,
    
};