From 2189a810b7f872bad8f60986a28e0a7a3fa9d738 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Sun, 3 Mar 2013 17:03:12 +0545 Subject: bandwidthd robust filesystem creation Make the code that starts bandwidthd check for the correct dirs and symlinks, leave them alone if they are already there, and put them in place if they are missing. This fixes some places where some commands were generating "already exists" warnings, and generally makes sure that whatever someone does at the command line to mess with bandwidthd dirs and links, they will be put back when bandwidthd starts. --- config/bandwidthd/bandwidthd.inc | 58 +++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/config/bandwidthd/bandwidthd.inc b/config/bandwidthd/bandwidthd.inc index c0115d81..8821ac76 100644 --- a/config/bandwidthd/bandwidthd.inc +++ b/config/bandwidthd/bandwidthd.inc @@ -228,14 +228,41 @@ EOD; $bandwidthd_nano_dir = "/var/bandwidthd"; $bandwidthd_htdocs_dir = $bandwidthd_nano_dir . "/htdocs"; $rc['start'] = << " . $bandwidthd_htdocs_dir . "/index.html"); + if (!is_dir($bandwidthd_htdocs_dir)) { + if (file_exists($bandwidthd_htdocs_dir)) { + unlink($bandwidthd_htdocs_dir); + } + mkdir($bandwidthd_htdocs_dir); + } + $bandwidthd_www_link = $g["www_path"] . "/bandwidthd"; + if (!is_link($bandwidthd_www_link)) { + if (file_exists($bandwidthd_www_link)) { + // It is a file and not a link - clean it up. + unlink($bandwidthd_www_link); + } + symlink($bandwidthd_htdocs_dir, $bandwidthd_www_link); + } + $bandwidthd_index_file = $bandwidthd_htdocs_dir . "/index.html"; + if (!file_exists($bandwidthd_index_file)) { + exec("echo \"Please start bandwidthd to populate this directory.\" > " . $bandwidthd_index_file); + } conf_mount_ro(); config_unlock(); - stop_service("bandwidthd"); start_service("bandwidthd"); - } ?> -- cgit v1.2.3