diff options
author | Phil Davis <phil.davis@world.inf.org> | 2013-03-03 17:03:12 +0545 |
---|---|---|
committer | Phil Davis <phil.davis@world.inf.org> | 2013-03-03 17:03:12 +0545 |
commit | 2189a810b7f872bad8f60986a28e0a7a3fa9d738 (patch) | |
tree | 9f630728d2e2453cf24035517f384738e97eae3e /config | |
parent | f7fb69e9c7906ec4275a822018d2da6582a59bfc (diff) | |
download | pfsense-packages-2189a810b7f872bad8f60986a28e0a7a3fa9d738.tar.gz pfsense-packages-2189a810b7f872bad8f60986a28e0a7a3fa9d738.tar.bz2 pfsense-packages-2189a810b7f872bad8f60986a28e0a7a3fa9d738.zip |
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.
Diffstat (limited to 'config')
-rw-r--r-- | config/bandwidthd/bandwidthd.inc | 58 |
1 files 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'] = <<<EOD -/bin/mkdir -p {$bandwidthd_nano_dir} -/bin/mkdir -p {$bandwidthd_htdocs_dir} -/bin/ln -s {$bandwidthd_base_dir}/bandwidthd {$bandwidthd_nano_dir}/bandwidthd -/bin/ln -s {$bandwidthd_config_dir} {$bandwidthd_nano_dir}/etc +if [ ! -d "{$bandwidthd_nano_dir}" ] ; then + if [ -e "{$bandwidthd_nano_dir}" ] ; then + /bin/rm -f {$bandwidthd_nano_dir} + fi + /bin/mkdir -p {$bandwidthd_nano_dir} +fi +if [ ! -d "{$bandwidthd_htdocs_dir}" ] ; then + if [ -e "{$bandwidthd_htdocs_dir}" ] ; then + /bin/rm -f {$bandwidthd_htdocs_dir} + fi + /bin/mkdir -p {$bandwidthd_htdocs_dir} +fi +if [ ! -L "{$bandwidthd_nano_dir}/bandwidthd" ] ; then + if [ -e "{$bandwidthd_nano_dir}/bandwidthd" ] ; then + /bin/rm -Rf {$bandwidthd_nano_dir}/bandwidthd + fi + /bin/ln -s {$bandwidthd_base_dir}/bandwidthd {$bandwidthd_nano_dir}/bandwidthd +fi +if [ ! -L "{$bandwidthd_nano_dir}/etc" ] ; then + if [ -e "{$bandwidthd_nano_dir}/etc" ] ; then + /bin/rm -Rf {$bandwidthd_nano_dir}/etc + fi + /bin/ln -s {$bandwidthd_config_dir} {$bandwidthd_nano_dir}/etc +fi + cd {$bandwidthd_nano_dir} {$bandwidthd_nano_dir}/bandwidthd cd - EOD; + if (!is_dir($bandwidthd_nano_dir)) { + if (file_exists($bandwidthd_nano_dir)) { + unlink($bandwidthd_nano_dir); + } + mkdir($bandwidthd_nano_dir); + } } else { $bandwidthd_htdocs_dir = $bandwidthd_base_dir . "/htdocs"; $rc['start'] = <<<EOD @@ -246,16 +273,29 @@ EOD; /* write out rc.d start/stop file */ write_rcfile($rc); - exec("/bin/rm /usr/local/www/bandwidthd"); - exec("/bin/ln -s " . $bandwidthd_htdocs_dir . " /usr/local/www/bandwidthd"); - exec("echo \"Please start bandwidthd to populate this directory.\" > " . $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"); - } ?> |