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

WIP Better method to create tmpfs /var/log files on startup #81

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 0 additions & 31 deletions stretch/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,6 @@
echo" My IP address is":
hostname -I

# Create log dirs and files on tempfs partition
# Will only run if /var/log is mounted in tmpfs
if ( mount | grep "on /var/log "| grep -q "^tmpfs " )
then
for i in "redis" "apache2" "mysql" "openhab" "openhab2" "logrotate" "mosquitto" "supervisor"; do mkdir /var/log/"$i"; done
for i in "emoncms.log" "mysql.log" "mqtt_input.log" "redis/redis-server.log" "service-runner.log" "mysql/error.log" "apache2/error.log" "supervisor/supervisord.log" "ntp_update.log"; do touch /var/log/"$i"; done
for i in "emoncms.log" "mysql.log" "mqtt_input.log" "redis/redis-server.log" "service-runner.log" "mysql/error.log" "apache2/error.log" "supervisor/supervisord.log" "ntp_update.log"; do ""chmod 666"" /var/log/"$i"; done
chown -R root:adm /var/log/apache2
chown -R redis:redis /var/log/redis
chown -R mysql:adm /var/log/mysql
chown -R openhab:openhab /var/log/openhab
chown -R openhab:openhab /var/log/openhab2
chown -R pi:pi /var/log/logrotate
chown -R mosquitto:mosquitto /var/log/mosquitto
chown -R dataplicity:dataplicity /var/log/supervisor;

# Start / Restart services,they should run happy now log dir's are created
# sleep 3
service mysql restart
service redis-server restart
service mosquitto restart
service emonhub restart
service emonPiLCD restart
service apache2 restart
#service supervisor restart
service feedwriter restart
service mqtt_input restart
service lwrfd restart

fi

# Run emonPi Update of first factory boot as Pi user (run condition > web connection exisits && ~/data/emonpiu$
su pi -c '/home/pi/emonpi/./firstbootupdate'

Expand Down
57 changes: 57 additions & 0 deletions update-tmpfiles-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh

# Script that searches in /var/log for subdirectories and updates
# tmpfiles.d config file to ensure that all directories are recreated
# on boot

# This script could be called:
# * Manually after user has installed their own packages
# * During shutdown via systemd. see:
# https://superuser.com/questions/1016827/how-do-i-run-a-script-before-everything-else-on-shutdown-with-systemd
# * Automatically after installing packages via apt-get. see:
# https://www.cyberciti.biz/faq/debian-ubuntu-linux-hook-a-script-command-to-apt-get-upgrade-command/

# Requires /var/log and /usr/lib/tmpfiles.d
if [ ! -d /var/log ]; then
echo "/var/log does not exist"
exit 1;
fi
if [ ! -d /usr/lib/tmpfiles.d ]; then
echo "/usr/lib/tmpfiles.d does not exist"
exit 1;
fi

STATIC_CONF=/usr/lib/tmpfiles.d/emonpi.conf
DYNAMIC_CONF=/usr/lib/tmpfiles.d/emonpi-dynamic.conf

DYNAMIC_HEADER="# This file is part of emonpi
#
# Since /var/log is mounted as tmpfs, the contents do not persist across reboots.
#
# This file contains entries for directories in /var/log that have been discovered
# dynamically at runtime. For instance directories created by extra packages
# that have been installed by the user
#
# The update-tmpfiles-config.sh script will search /var/log and append entries
# to this file for any directories that exist that are not already managed by tmpfiles

# See tmpfiles.d(5) for details

# Type Path Mode UID GID Age Argument
"

# Make sure config files exist
# TODO: copy static file from /home/pi/emonpi/???
[ -f ${STATIC_CONF} ] || /usr/bin/touch ${STATIC_CONF}

[ -f ${DYNAMIC_CONF} ] || echo "${DYNAMIC_HEADER}" > ${DYNAMIC_CONF}

# Find any unknown directories that have been created in /var/log, and add
# dynamic entries for them
for d in `find /var/log -mindepth 1 -type d`; do
/bin/grep -q $d ${STATIC_CONF} ${DYNAMIC_CONF}
if [ $? -ne 0 ]; then
echo "Found new log dir in tmpfs mounted /var/log: $d"
/usr/bin/stat -c "d %n %#a %U %G" $d >>${DYNAMIC_CONF}
fi
done