diff options
author | nachoparker <nacho@ownyourbits.com> | 2018-02-16 16:35:16 +0300 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2018-02-18 22:08:45 +0300 |
commit | f8381f42cde734b95a1df9802a3e71f323e9344d (patch) | |
tree | 92f6da5b4a982585293e0c3fc509b1b9db2bb308 | |
parent | 51b1e5dd526e2795521834b4da0866ee3eb88a1b (diff) |
log all NCP actions to /var/log/ncp.logv0.46.14
-rwxr-xr-x | etc/library.sh | 17 | ||||
-rw-r--r-- | ncp-web/ncp-output.php | 5 | ||||
-rw-r--r-- | ncp-web/wizard/JS/wizard.js | 2 | ||||
-rw-r--r-- | nextcloudpi.sh | 12 | ||||
-rwxr-xr-x | update.sh | 11 |
5 files changed, 30 insertions, 17 deletions
diff --git a/etc/library.sh b/etc/library.sh index 7329f8af..7e313701 100755 --- a/etc/library.sh +++ b/etc/library.sh @@ -105,13 +105,26 @@ function is_active_script() ) } +function run_and_log() +{ + local SCRIPT=$1 + touch /var/log/ncp.log + chmod 640 /var/log/ncp.log + chown root:www-data /var/log/ncp.log + echo -e "[ $( basename "$SCRIPT" .sh ) ]" >> /var/log/ncp.log + configure 2>&1 | tee -a /var/log/ncp.log + local RET="${PIPESTATUS[0]}" + echo "" >> /var/log/ncp.log + return "$RET" +} + function launch_script() { ( local SCRIPT=$1 source ./"$SCRIPT" set +x - configure + run_and_log "$SCRIPT" ) } @@ -140,7 +153,7 @@ function configure_script() printf '\033[2J' && tput cup 0 0 # clear screen, don't clear scroll, cursor on top echo -e "Launching $( basename "$SCRIPT" .sh )" set +x - configure + run_and_log "$SCRIPT" return 0 ) } diff --git a/ncp-web/ncp-output.php b/ncp-web/ncp-output.php index 6450250a..8bea03bb 100644 --- a/ncp-web/ncp-output.php +++ b/ncp-web/ncp-output.php @@ -45,7 +45,7 @@ function pingClient() */ function follow($file) { - $size = 0; + $size = filesize($file); while (true) { if ( !file_exists($file) ) @@ -78,7 +78,8 @@ function follow($file) session_write_close(); echo str_pad('',1024*1024*4); // make sure the browser buffer becomes full -follow( '/run/ncp.log' ); +touch( '/var/log/ncp.log' ); +follow( '/var/log/ncp.log' ); // License // diff --git a/ncp-web/wizard/JS/wizard.js b/ncp-web/wizard/JS/wizard.js index 7b343e51..464c2ac9 100644 --- a/ncp-web/wizard/JS/wizard.js +++ b/ncp-web/wizard/JS/wizard.js @@ -32,8 +32,6 @@ $(document).ready(function(){ $('button').prop('disabled', true); addNotification( action, 'gray-bg' ) ; - logOutput( '\n[ ' + action + ' ]' + '\n' ); - $.post('../ncp-launcher.php', { action:'launch', ref: action, diff --git a/nextcloudpi.sh b/nextcloudpi.sh index 9cc100c1..7aebe4da 100644 --- a/nextcloudpi.sh +++ b/nextcloudpi.sh @@ -107,17 +107,7 @@ DIR=/usr/local/etc/nextcloudpi-config.d test -f $DIR/$1 || { echo "File not found"; exit 1; } source /usr/local/etc/library.sh cd $DIR -touch /run/ncp.log -chmod 640 /run/ncp.log -chown root:www-data /run/ncp.log -launch_script $1 &> /run/ncp.log -RET=$? - -# clean log for the next PHP backend call to start clean, -# but wait until everything from current execution is read -sleep 0.5 && echo "" > /run/ncp.log - -exit $RET +launch_script $1 EOF chmod 700 /home/www/ncp-launcher.sh echo "www-data ALL = NOPASSWD: /home/www/ncp-launcher.sh , /sbin/halt" >> /etc/sudoers @@ -249,6 +249,17 @@ EOF sed -i 's|^ServerSignature .*|ServerSignature Off|' /etc/apache2/conf-enabled/security.conf sed -i 's|^ServerTokens .*|ServerTokens Prod|' /etc/apache2/conf-enabled/security.conf + # upgrade launcher after logging improvements + cat > /home/www/ncp-launcher.sh <<'EOF' +#!/bin/bash +DIR=/usr/local/etc/nextcloudpi-config.d +test -f $DIR/$1 || { echo "File not found"; exit 1; } +source /usr/local/etc/library.sh +cd $DIR +launch_script $1 +EOF + chmod 700 /home/www/ncp-launcher.sh + } # end - only live updates exit 0 |