node.jsで簡易多重起動防止

const lockFilePath = __dirname + "/main.lock";
function lockFile() {
    try {
        var file = fs.openSync(lockFilePath, 'r');
        fs.close(file);
        return false;
    } catch (e1) {
        try {
            fs.writeFileSync(lockFilePath);
            return true;
        } catch (e2) {
            console.error(e2);
            return false;
        }
    }
}

function unlockFile() {
    fs.unlink(lockFilePath, function(err){
        if (err) throw err;
    })
}

if(!lockFile()){
    console.error("Another proccess running. abort");
    process.exit();
}