Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate service runner & root cron tab entries #20

Merged
merged 2 commits into from
May 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 53 additions & 26 deletions emoncmsupdate
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,54 @@ date

echo

#########################################################################################

uid=`id -u`
echo "EUID: $uid"

if [ "$uid" = "0" ] ; then
# update is being ran mistakenly as root, need to remove all sudo crontab service runner entries
echo "update running as root: remove sudo crontab service runner entries"
crontab -l > mycron
if grep -Fxq " * * * * * /home/pi/emonpi/service-runner >> /var/log/service-runner.log 2>&1" mycron ; then
sed -i "/\s\* \* \* \* \* \/home\/pi\/emonpi\/service-runner >> \/var\/log\/service-runner.log 2>&1/d" ./mycron
fi
if grep -Fxq "* * * * * /home/pi/emonpi/service-runner >> /var/log/service-runner.log 2>&1" mycron ; then
sed -i "/\* \* \* \* \* \/home\/pi\/emonpi\/service-runner >> \/var\/log\/service-runner.log 2>&1/d" ./mycron
fi
crontab mycron
rm mycron
echo "switching to Pi user & restarting script"
su -c ./$0 pi
exit
fi

#########################################################################################

# Add backup module service-runner
echo "Checking cron tab for service runner entry..."
crontab -l > mycron
# Check crontab entry does not already exist, if not add new entry
if ! grep -Fxq "* * * * * /home/pi/emonpi/service-runner >> /var/log/service-runner.log 2>&1" mycron ; then
echo "Add service runner cron entry"
echo "* * * * * /home/pi/emonpi/service-runner >> /var/log/service-runner.log 2>&1" >> mycron
crontab mycron
else
echo "service runner crontab entry already installed"
fi
rm mycron

# Check if double service runner (with space) entry exits, if so remove it
crontab -l > mycron
if grep -Fxq " * * * * * /home/pi/emonpi/service-runner >> /var/log/service-runner.log 2>&1" mycron ; then
echo "Remove duplicate service runner entry"
sed -i "/\s\* \* \* \* \* \/home\/pi\/emonpi\/service-runner >> \/var\/log\/service-runner.log 2>&1/d" ./mycron
crontab mycron
fi
rm mycron

#########################################################################################

echo "git pull /var/www/emoncms"
cd /var/www/emoncms
git branch
Expand Down Expand Up @@ -49,7 +97,7 @@ cd /var/www/emoncms/Modules/dashboard
git branch
git pull

echo
echo

if [ -d /var/www/emoncms/Modules/graph ]; then
echo "git pull /var/www/emoncms/Modules/graph"
Expand All @@ -62,7 +110,7 @@ else
git clone https://github.com/emoncms/graph
fi

echo
echo

if [ -d /home/pi/postprocess ]; then
echo "git pull /home/pi/postprocess"
Expand Down Expand Up @@ -115,7 +163,7 @@ if [ -f /etc/init.d/emoncms-nodes-service ]; then
sudo /etc/init.d/emoncms-nodes-service restart
fi

echo
echo
if [ -f /etc/init.d/openhab ]; then
sudo /etc/init.d/openhab restart
fi
Expand All @@ -127,27 +175,6 @@ if [ -f /etc/init.d/mqtt_input ]; then
sudo /etc/init.d/mqtt_input restart
fi
echo
echo "set log rotate config owner to root"
sudo chown root:root /etc/logrotate.conf
echo "Restarting Services..."

# Add backup module service-runner
echo "Checking cron tab for service runner entry..."
# Add root crontab entry to run wifi check script ever 5min
crontab -l > mycron #write out current root crontab
# Check crontab entry does not already exist, if not add new entry
if ! grep -Fxq "* * * * * /home/pi/emonpi/service-runner >> /var/log/service-runner.log 2>&1" mycron ; then
echo "Add service runner cron entry"
echo "* * * * * /home/pi/emonpi/service-runner >> /var/log/service-runner.log 2>&1" >> mycron #echo new cron into cronfile
crontab mycron #install new cron file
else
echo "service runner crontab entry already installed"
fi
sudo rm mycron

# Check if double service runner (with space) entry exits, if so remove it
crontab -l > mycron
if grep -Fxq " * * * * * /home/pi/emonpi/service-runner >> /var/log/service-runner.log 2>&1" mycron ; then
echo "Remove duplicate service runner entry"
sed -i "/\s\* \* \* \* \* \/home\/pi\/emonpi\/service-runner >> \/var\/log\/service-runner.log 2>&1/d" ./mycron
crontab mycron
sudo rm mycron
fi
4 changes: 3 additions & 1 deletion emonpiupdate
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ echo
echo "================================="
echo "EmonPi update started"
echo "================================="

echo
echo "EUID: $EUID"
echo
# Needed for emonPi LCD Hi-Link 3G dongle support
sudo pip install xmltodict
sudo pip install requests
Expand Down
5 changes: 4 additions & 1 deletion service-runner-update.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash

# emonPi update for use with service-runner add following entry to crontab:
# * * * * * /home/pi/emonpi/service-runner >> /var/log/service-runner.log 2>&1
# * * * * * /home/pi/emonpi/service-runner >> /var/log/service-runner.log 2>&1

# Make FS RW
rpi-rw

echo
echo "EUID: $EUID"

# Clear log update file
cat /dev/null > /home/pi/data/emonpiupdate.log

Expand Down
3 changes: 3 additions & 0 deletions update
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ touch $LOCK
# Make FS RW
rpi-rw

echo
echo "EUID: $EUID"

# Clear log update file
cat /dev/null > /home/pi/data/emonpiupdate.log

Expand Down