Skip to content

Instantly share code, notes, and snippets.

@remyd1
Last active June 18, 2020 14:29
Show Gist options
  • Save remyd1/2853f489d828ecda52183ca37a813f4e to your computer and use it in GitHub Desktop.
Save remyd1/2853f489d828ecda52183ca37a813f4e to your computer and use it in GitHub Desktop.
cleaning salt from ext git
#!/bin/bash
CURDIR=`pwd`
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
usage="usage:\n
$0 --[r]estart=no --with[g]it=no --[d]ebug=no --[e]rase=no --[l]ock=no --[c]ommit=''\n\n
- Between brackets is the short option format (you have to use it with only 1 dash (-), \n
eg :\"$0 -g=y\" ) \n
- Default is 'no' for all options (except 'commit' which is an empty value).\n
- Note that withgit option will pull, then put an automatic message to your commit,\n
and finally push to your repository... If you want to change the default message,\n
just enter a message like this : \n
$0 -g=y -c='This is my commit message' \n
- erase option remove the salt cache directory\n
- lock option will remove any lock on the server (could happen with git backend)\n
- restart option restart the salt-master service."
function start {
NOW=`date +"%Y%m%d_%H%m%S"`
service salt-master start
echo "salt-master started at: $NOW"
}
function stop {
NOW=`date +"%Y%m%d_%H%m%S"`
service salt-master stop
echo "salt-master stopped at: $NOW"
}
for i in "$@"
do
case $i in
-r=*|--restart=*)
RESTART="${i#*=}"
shift # past argument=value
;;
-c=*|--commit=*)
COMMIT="${i#*=}"
shift # past argument=value
;;
-d=*|--debug=*)
DEBUG="${i#*=}"
shift # past argument=value
;;
-g=*|--withgit=*)
WITHGIT="${i#*=}"
shift # past argument=value
;;
-e=*|--erase=*)
ERASE="${i#*=}"
shift # past argument=value
;;
-l=*|--lock=*)
LOCK="${i#*=}"
shift # past argument=value
;;
--default)
DEFAULT=YES
shift # past argument with no value
;;
*)
# unknown option
echo -e $usage
exit 1
;;
esac
done
#cd ${DIR}
if [[ "$WITHGIT" == "yes" ]] || [[ "$WITHGIT" == "Y" ]] || [[ "$WITHGIT" == "y" ]];then
git pull
if [[ -n "$COMMIT" ]];then
git commit -a -m "$COMMIT"
else
git commit -a -m "something has been updated"
fi
git push
fi
if [[ "$RESTART" == "yes" ]] || [[ "$RESTART" == "Y" ]] || [[ "$RESTART" == "y" ]];then
stop
fi
if [[ "$LOCK" == "yes" ]] || [[ "$LOCK" == "Y" ]] || [[ "$LOCK" == "y" ]];then
salt-run cache.clear_git_lock git_pillar
salt-run cache.clear_git_lock gitfs type=update
fi
# delete and clear the cache
salt-run fileserver.clear_cache backend=git
#salt-run fileserver.clear_lock
salt-run cache.clear_all
if [[ "$ERASE" == "yes" ]] || [[ "$ERASE" == "Y" ]] || [[ "$ERASE" == "y" ]];then
rm -rf /var/cache/salt/master/{git_pillar,pillar_gitfs}
fi
salt-run fileserver.update backend=git
if [[ "$DEBUG" == "yes" ]] || [[ "$DEBUG" == "Y" ]] || [[ "$DEBUG" == "y" ]];then
salt-run git_pillar.update -l debug
else
salt-run git_pillar.update
fi
salt-call saltutil.sync_all
if [[ "$RESTART" == "yes" ]] || [[ "$RESTART" == "Y" ]] || [[ "$RESTART" == "y" ]];then
start
fi
salt '*' saltutil.sync_all
salt '*' mine.update
cd ${CURDIR}
#!/bin/bash
CURDIR=`pwd`
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
usage="usage:\n
$0 --restart=yes --withgit=yes --debug=no --erase=no --commit=\"blabla\"\n
- Note that withgit option will pull, then put an automatic message to your commit, and finally push to your repository...\n
- erase option remove the salt cache directory\n
- restart option restart the salt-master service.\n
- commit is the commit message to use with 'withgit' option. If not defined it will be \"something has been updated\""
function start {
NOW=`date +"%Y%m%d_%H%m%S"`
service salt-master start
echo "salt-master started at: $NOW"
}
function stop {
NOW=`date +"%Y%m%d_%H%m%S"`
service salt-master stop
echo "salt-master stopped at: $NOW"
}
for i in "$@"
do
case $i in
-r=*|--restart=*)
RESTART="${i#*=}"
shift # past argument=value
;;
-d=*|--debug=*)
DEBUG="${i#*=}"
shift # past argument=value
;;
-c=*|--commit=*)
COMMIT="${i#*=}"
shift # past argument=value
;;
-g=*|--withgit=*)
WITHGIT="${i#*=}"
shift # past argument=value
;;
-e=*|--erase=*)
ERASE="${i#*=}"
shift # past argument=value
;;
--default)
DEFAULT=YES
shift # past argument with no value
;;
*)
# unknown option
echo -e $usage
exit 1
;;
esac
done
#cd ${DIR}
if [[ "$WITHGIT" == "yes" ]] || [[ "$WITHGIT" == "Y" ]] || [[ "$WITHGIT" == "y" ]];then
git pull
if [[ -n "$COMMIT" ]];then
git commit -a -m "$COMMIT"
else
git commit -a -m "something has been updated"
fi
git push
fi
if [[ "$RESTART" == "yes" ]] || [[ "$RESTART" == "Y" ]] || [[ "$RESTART" == "y" ]];then
stop
fi
#salt-run cache.clear_git_lock git_pillar
# delete and clear the cache
salt-run fileserver.clear_cache backend=git
#salt-run fileserver.clear_lock
salt-run cache.clear_pillar
if [[ "$ERASE" == "yes" ]] || [[ "$ERASE" == "Y" ]] || [[ "$ERASE" == "y" ]];then
rm -rf /var/cache/salt/master/{git_pillar,pillar_gitfs}
fi
salt-run fileserver.update
if [[ "$DEBUG" == "yes" ]] || [[ "$DEBUG" == "Y" ]] || [[ "$DEBUG" == "y" ]];then
salt-run git_pillar.update -l debug
else
salt-run git_pillar.update
fi
salt-call saltutil.refresh_pillar
if [[ "$RESTART" == "yes" ]] || [[ "$RESTART" == "Y" ]] || [[ "$RESTART" == "y" ]];then
start
fi
salt '*' saltutil.refresh_pillar
cd ${CURDIR}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment