diff --git a/how to know if windows or linux.py b/how to know if windows or linux.py new file mode 100644 index 0000000..b3d720c --- /dev/null +++ b/how to know if windows or linux.py @@ -0,0 +1,8 @@ + +import os +print os.name + +if os.name == 'nt': + print 'windows' +else: + print 'linux' diff --git a/index.html b/index.html new file mode 100644 index 0000000..04062f4 --- /dev/null +++ b/index.html @@ -0,0 +1,6 @@ + +
This is title
+ +Hello world + + \ No newline at end of file diff --git a/post-receive b/post-receive new file mode 100644 index 0000000..d1e90a6 --- /dev/null +++ b/post-receive @@ -0,0 +1 @@ +/git/puppet.git/hooks/commit_hooks/web-post-receive.sh -d 'localhost' -f '/etc/puppetlabs/code/environments/' -r 'git@alis-dsg-pupms:/git/puppet.git' -i '/git/puppet.git/hooks/id_rsa' -u 'root' diff --git a/python flask.py b/python flask.py new file mode 100644 index 0000000..f29e849 --- /dev/null +++ b/python flask.py @@ -0,0 +1,9 @@ +from flask import Flask +app = Flask(__name__) + +@app.route("/") +def index(): + return "Hello World!" + +if __name__ == "__main__": + app.run(debug=True) diff --git a/web-post-receive.sh b/web-post-receive.sh new file mode 100644 index 0000000..e851614 --- /dev/null +++ b/web-post-receive.sh @@ -0,0 +1,83 @@ +#!/bin/bash +#This need to be on the git server where the on /opt/stash-hooks +usage () { + echo "This script convert the Git branches in puppet environment using SSH" + echo "Usage:" + echo "$0 -d -f -r -u -i " + exit 0 +} + + +if [ "$#" -ne 10 ]; then + echo "Error: Illegal number of parameters" + usage +fi +while getopts "h:d:f:r:i:u:" opt; do + case $opt in + h) + usage + ;; + d) + DESTSERVER=$OPTARG + ;; + f) + FOLDER=$OPTARG + ;; + r) + REPO=$OPTARG + ;; + u) + USER=$OPTARG + ;; + i) + SSHKEY=$OPTARG + ;; + + *) + usage + ;; + esac +done +#debug: +echo "destenation server: $DESTSERVER" +echo "env folder: $FOLDER" +echo "remote user: $USER" +echo "ssh key:$SSHKEY" +echo "Git repo: $REPO" + +read oldrev newrev refname + +REPOSITORY=$REPO +#REPOSITORY="/opt/git/puppet.git" +BRANCH=$( echo "${refname}" | sed -n 's!^refs/heads/!!p' ) +#ENVIRONMENT_BASE="/tmp/puppet/environments" +ENVIRONMENT_BASE=$FOLDER + +# master branch, as defined by git, is production +if [[ "${BRANCH}" == "production" ]]; then + ACTUAL_BRANCH="production" +else + ACTUAL_BRANCH=${BRANCH} +fi + +# newrev is a bunch of 0s +echo "${newrev}" | grep -qs '^0*$' +if [ "$?" -eq "0" ]; then + # branch is marked for deletion + if [ "${ACTUAL_BRANCH}" = "production" ]; then + echo "No way!" + exit 1 + fi + pid1=`ps -ef |grep python |grep -v grep |head -1 |tr -s " " "#"|cut -d "#" -f2` + kill -9 $pid1 + + #or service flask stop if there is service + ssh -i $SSHKEY ${USER}@${DESTSERVER} "/usr/bin/pupdate.sh -d ${ENVIRONMENT_BASE} -r ${REPO} -b ${ACTUAL_BRANCH} -a delete" + service flask start +else + pid1=`ps -ef |grep python |grep -v grep |head -1 |tr -s " " "#"|cut -d "#" -f2` + kill -9 $pid1 + ssh -i $SSHKEY ${USER}@${DESTSERVER} "/usr/bin/pupdate.sh -d ${ENVIRONMENT_BASE} -r ${REPO} -b ${ACTUAL_BRANCH} -a update" + service flask start +fi +exit 0