Skip to content

Instantly share code, notes, and snippets.

View crizstian's full-sized avatar

Cristian Ramirez crizstian

View GitHub Profile
resource "aws_subnet" "database_subnet" {
cidr_block = "${var.database_private_cidr}"
availability_zone = "${data.aws_availability_zones.available_zones.names[0]}"
vpc_id = "${module.aero_bastion_network.bastion_vpc_id}"
tags {
Application = "${var.cluster_name}"
Environment = "${terraform.workspace}"
Name = "${var.cluster_name}-database-subnet"
}
resource "aws_subnet" "bastion_private_subnet" {
cidr_block = "${var.bastion_private_cidr}"
availability_zone = "${var.available_zone}"
vpc_id = "${aws_vpc.bastion_vpc.id}"
tags {
Application = "${var.bastion_cluster_name}"
Environment = "${terraform.workspace}"
Name = "${var.bastion_cluster_name}-private-subnet"
}
#!/bin/bash -e
export playbook=$1
sudo apt-get upgrade -y
sudo apt-get update
sudo apt-get install software-properties-common -y
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible -y
cd /var/tmp
sudo ansible-playbook -i "localhost," -c local $playbook
# /bin/bash
chmod +x environment.sh
# add aws keys
AWS_ACCESS_KEY=
AWS_SECRET_KEY=
function buildImage {
export MACHINE_TYPE=$1
/usr/local/bin/packer build -force $2.json
}
buildImage mongodb aws
resource "aws_vpc" "bastion_vpc" {
cidr_block = "${var.bastion_cidr}"
enable_dns_hostnames = true
enable_dns_support = true
tags {
Application = "${var.bastion_cluster_name}"
Environment = "${terraform.workspace}"
Name = "${var.bastion_cluster_name}-vpc"
}
}
resource "aws_security_group" "bastion_sg" {
description = "Enable HTTP ingress"
vpc_id = "${aws_vpc.bastion_vpc.id}"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
const cluster = require('cluster')
const testW = require('./test-worker')
let readlogs, saveLogs
// local logic worker recieved
const test = () => {
readlogs.send({msg: 'hey calmenla !!!'})
readlogs.on('message', ({msg, id}) => {
console.log('Master ' + process.pid + ' received message from worker ' + id + '.', msg)
// ##############################################
// WORKERS
} else if (process.env.WorkerName === 'readlogs') {
console.log('👉🏽 Worker readlogs ' + process.pid + ' has started.')
process.on('message', async ({logfiles}) => {
try {
const read = await readLogFiles.parseFiles(logfiles)
process.send({read, logfiles})
} catch (e) {
console.log(`something went wrong with reading logs => ${e}`)
'use strict'
const cluster = require('cluster')
const watch = require('node-watch')
const FtpClient = require('ftp-client')
const fs = require('fs')
const config = require('./config/config')
const readLogFiles = require('./read-files')
const saveToDB = require('./db-actions')
const moveAndDelete = require('./move-delete-files')
@crizstian
crizstian / logparser-server.js
Created October 30, 2017 15:35
cluster main process
// Fisrt we need to be in the master worker scope to be able
// to init all the main process
if (cluster.isMaster) {
console.log(`
--- 🤘🏽 Master ${process.pid} is running 🤘🏽 ---
`)
// then we start all the workers process
let readlogs = cluster.fork({WorkerName: 'readlogs'})
let savelogs = cluster.fork({WorkerName: 'savelogs'})