Git Product home page Git Product logo

clojure-control's Introduction

Introduction

Define clusters and tasks for system administration or code deployment, then execute them on one or many remote machines.

Clojure-control depends only on OpenSSH and clojure on the local control machine.Remote machines simply need a standard sshd daemon.

The idea came from node-control.

Gettting started

I recommend you to use clojure-control with lein control plugin,you can install the plugin by:

lein plugin install control 0.3.8           #For clojure 1.3+
lein plugin install control 0.3.1           #For clojure 1.2, some features are not valid in this version.Recommend using 0.3.3

And then use lein to create a control project,for example

lein new mycontrol

Creating a control file by:

 cd mycontrol
 lein control init

It will create a file named control.clj under mycontrol folder.Defines your clusters and tasks in this file,for example:

 (defcluster :default-cluster
     :clients [
              {:host "localhost" :user "root"}
     ])
 (deftask :date "echo date on cluster"  []
     (ssh "date"))

It defines a cluster named default-cluster,and defines a task named date to execute date command on remote machines.Run date task on default-cluster by:

lein control run default-cluster date

Output:

Performing default-cluster
Performing date for localhost
localhost:ssh:  date
localhost:stdout: Sun Jul 24 19:14:09 CST 2011
localhost:exit: 0

Also,you can run the task with user@host instead of a pre-defined cluster (since 0.3.5):

	 lein control run root@localhost date

You may have to type password when running this task. You can setup ssh public keys to avoid typing a password when logining remote machines.please visit HOWTO: set up ssh keys

Every task's running result is a map contains output and status,you can get them by:

 (let [rt (ssh "date")]
   (println (:status rt))
   (println (:stdout rt))
   (println (:stderr rt)))

You can do whatever you want with these values,for example,checking status is right or writing standard output to a file.

##Some practical tasks

A task to ping mysql:

(deftask :ping-mysql  []
  (let [stdout (:stdout (ssh "mysqladmin -u root  -p'password' ping"))]
      (if (.contains stdout "is alive")
  	  1
	  0)))

A task to deploy application:

(deftask :deploy-app []
      (local "tar zcvf app.tar.gz app/")
      (scp "app.tar.gz" "/home/user/")
      (ssh
           (run 
               (cd "/home/user"
				   (run
    			      (run "tar zxvf app.tar.gz")
   	    			  (env "JAVA_OPTS" "-XMaxPermSize=128m"
                         (run "bin/app.sh restart")))))))

Two tasks to install zookeeper c client:

 (deftask ldconfig
   []
     (ssh "ldconfig" :sudo true))

 (deftask install_zk_client
  []
      (ssh
	   (run
	       (run "mkdir -p /home/deploy/dennis")
		   (cd "/home/deploy/dennis"
		           (run "wget http://labs.renren.com/apache-mirror//zookeeper/zookeeper-3.4.3/zookeeper-3.4.3.tar.gz"))))
     (ssh (cd "/home/deploy/dennis"
            (run "tar zxvf zookeeper-3.4.3.tar.gz")))
     (ssh (cd "/home/deploy/dennis/zookeeper-3.4.3/src/c"
	        (run
	              (run "./configure --includedir=/usr/include")
	              (run "make")
	              (run "sudo make install"))))
	  (call :ldconfig))

##Documents

Contributors

sunng87

onycloud

ljos

##License

MIT licensed

clojure-control's People

Contributors

killme2008 avatar ljos avatar sunng87 avatar

Watchers

 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.