Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
tomerb3 authored Jan 24, 2018
1 parent 3e4e7a2 commit ad0d070
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
8 changes: 8 additions & 0 deletions how to know if windows or linux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

import os
print os.name

if os.name == 'nt':
print 'windows'
else:
print 'linux'
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<header><title>This is title</title></header>
<body>
Hello world
</body>
</html>
1 change: 1 addition & 0 deletions post-receive
Original file line number Diff line number Diff line change
@@ -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'
9 changes: 9 additions & 0 deletions python flask.py
Original file line number Diff line number Diff line change
@@ -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)
83 changes: 83 additions & 0 deletions web-post-receive.sh
Original file line number Diff line number Diff line change
@@ -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 <destination server> -f <environment folder> -r <the Git repo URL> -u <user> -i <path to ssh key>"
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

0 comments on commit ad0d070

Please sign in to comment.