Giter VIP home page Giter VIP logo

linker's Introduction

linker

Linker is a lightweight dependency resolver

Compile

gcc linker.c -lpthread -o linker

Help

$ linker -h

linker [opt] [event:script].. [service:event]..
 
opt: 
                -h              : print help
                -r <role>       : set role [deamon/waitfor] 
                -p <port>       : listen port
                -P <peerport>   : peer port (port to send request/response)
                example:
                ./linker -p 5000 -r deamon  mysql_start:/usr/local/mysql_start_check.sh 
                ./linker -p 4000 -P 5000 -r waitfor mysql:mysql_start 

How to use

Role:

Linker use two roles:
1. Daemon
2. waitfor

While running as daemon linker runs in background, to perform event check requests. On a event check request from dependent node, it executes corresponsing event check script and return response

While running as waitfor linker runs in foreground, to halt execution till all the event has successfully occured

Using with Docker Compose:

linker can be useful in a docker compose environment. Docker entrypoint script can use linker to waitfor other service in different container

For a situation where webserver container depends on mysql container, we can use docker compose features to link and depends_on. Although depends_on check if the container has started, but not the application status

to halt webserver from starting, linter can be used to waitfor mysql to start

Daemon

to check mysql status locally, linker deamon can be started in mysql container as:

linker -r deamon -p 5001 -P 5000 mysql_start:./mysql_start_check.sh

Here we registering mysql_start_check.sh script for mysql_start event mysql_start_check.sh should return zero if mysql is started, and non zero in case of error
mysql_start_check.sh script can be written as:

#!/bin/bash

USER=root
PASS=root123

mysqladmin -h remote_server_ip -u$USER -p$PASS processlist

 if [ $? -eq 0 ]
        then
                echo "do nothing"
        else
                ssh remote_server_ip
                service mysqld start
 fi
Waitfor

to make webserver container wait for mysql to start, linker can be started to waitfor in the entrypoint script:

linker -r waitfor -p 5000 -P 5001 mysql:mysql_start

A service name can be used, which would be resolved dynamically if the containers are linked

Multiple events:

In a daemon multiple events check script can be resgisterd For example in db service:

linker -r deamon -p 5001 -P 5000 mysql_start:./mysql_start_check.sh pesql_start:./pesql_start_check.sh

At the same way, While waiting for multiple events can be resgisterd as

linker -r waitfor -p 5000 -P 5001 db:mysql_start db:pesql_start 

linker's People

Contributors

s8sg avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.