XenoAura
11/27/2017 - 12:16 AM

Обновляет локальный проект. Запуск honcho(Procfile), перезапуск при изменении config.py

Обновляет локальный проект. Запуск honcho(Procfile), перезапуск при изменении config.py

#!/bin/bash
#Ctrl+C handler
sigint_handler()
{
    kill -SIGINT $PID
    wait $PID
    echo "CryptoTraider stoped"
    exit
}
trap sigint_handler SIGINT SIGTERM

# Install "inotify-tools" package
if [ $(dpkg-query -W -f='${Status}' inotify-tools 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
    apt-get install inotify-tools -y;
fi

# Start bot script
echo "Recieve update from repository"
git fetch origin

# Reset --hard id "update" args
# Use:
# ./start.sh update
if [ "$1" == "update" ]; then
    echo "!!! HARD UPDATE !!!"
    git reset --hard origin/master
    git merge origin/master
    exit
else
    updated=$(git log HEAD..origin/master --oneline)
fi


if [[ "${updated}" != "" ]] ; then
    echo "Updates received"
    echo "Commit list:"
    git log HEAD..origin/master --oneline
    echo "Update bot?(wait 10 sec) y/n"
    read -t 10 upd
    if [ "$upd" == "y" ]; then
        echo "Start updates"
        git merge origin/master # completing the pull
    else
        echo "Start without updates"
    fi
else
    echo "No updates"
    echo "Start"
fi


# Check config change.py
while true; do
    honcho start &
    PID=$!
    # inotifywait -e modify -e move -e create -e delete -e attrib --format %e config.txt
    inotifywait -e modify -e create -e attrib config.py
    kill -SIGINT $PID
    wait $PID
done