Code Monkey home page Code Monkey logo

bash-empty-daemon's Introduction

bash-empty-daemon

Template of empty daemon for Linux on pure bash. Imagine, you need to make auto deploy from one server to another 5 or more servers. You may install special software for this with many dependencies and lot of else soft. But why? You can create SSH key for master server and attach this key to other slave servers. Then you need only bash commands and thats all.

cd ~
git clone [email protected]:vladimirok5959/bash-empty-daemon.git
cd bash-empty-daemon
chmod 0744 run.sh
./run.sh
./run.sh (once|start|stop|status|update)
./run.sh once
Loop. Every one second. Do something here...
Loop. Every one second. Do something here...
Loop. Every one second. Do something here...
^C
./run.sh status
Daemon is not runned
./run.sh start
./run.sh status
Daemon is runned with pid = 18504
cat ./logs/all.log
Loop. Every one second. Do something here...
Loop. Every one second. Do something here...
Loop. Every one second. Do something here...
Loop. Every one second. Do something here...
...
Loop. Every one second. Do something here...
./run.sh stop
Daemon stoped
./run.sh once

Will run script in non deamon mode. This is easy way to debug daemon body in file loop.sh, also you can simply shutdown daemon by pressing Ctrl+C.

./run.sh start

Will run in daemon mode and you can safety close remote ssh connection.

./run.sh stop

Will stop daemon.

./run.sh status

Will show if daemon runned currently on not.

./run.sh update

Self update. Get the latest daemon template from GIT and update main script. Auto update do not touched user scripts. Can be safety runned. Auto update will stop daemon, make updates and will run daemon automatically, if he was worked before updates.

Where I can put my code?

Look into file scripts/example.sh:

#!/bin/sh

# Example
echo "Loop. Every one second. Do something here..."

Contents of this file and any of *.sh file in script folder will be fired every second and each time.

Examples?

  1. Check for command on master server via file and create in /tmp dir on slave server file time.txt with time from master server.
#!/bin/sh

if [ -f "/tmp/command1.txt" ]; then
	# Need to remove this file, because script will be run this command every second
	rm /tmp/command1.txt

	# Simple write some to log file
	echo "I recive command 1!"

	# Create test file
	echo "$(date '+%F %T')" > /tmp/time.txt

	# Copy file to remote server
	scp -P 22 /tmp/time.txt [email protected]:/tmp/time.txt

	# Delete created file on master
	rm /tmp/time.txt

	# Write to logs
	echo "Command 1 is done!"
fi
  1. Check for command and make some simple changes on slave server.
#!/bin/sh

if [ -f "/tmp/command2.txt" ]; then
	rm /tmp/command2.txt
	ssh -p 22 [email protected] 'cd /tmp; mkdir daemon;'
	ssh -p 22 [email protected] 'cd /tmp/daemon; mkdir test; cd test; touch test'
fi

Tested on Linux Debian and Mac OS X High Sierra.
You can easy make auto deploy for GIT for example or something else.
You can use bash-daemon-maker to assembly and install your daemon in less of one minute. Enjoy.

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.