aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2011-01-03 18:31:08 +0100
committerLaurent Bachelier <laurent@bachelier.name>2011-01-03 18:31:08 +0100
commit01145bbba225b57f6145e9a5885863b1d579afdb (patch)
tree0a25e84949ff03280a4b2e126daa1b0998e4277d
parentUse log_dir option for tail (diff)
downloadsymfttpd-01145bbba225b57f6145e9a5885863b1d579afdb.tar.xz
Rewrite the configuration file between restarts
…as it might have been deleted, likely by a "symfony cc"
-rw-r--r--lib/Template.php18
-rwxr-xr-xspawn12
2 files changed, 23 insertions, 7 deletions
diff --git a/lib/Template.php b/lib/Template.php
index 89db03e..7ec5b14 100644
--- a/lib/Template.php
+++ b/lib/Template.php
@@ -19,4 +19,22 @@ class Template
return ob_get_clean();
}
+
+ /**
+ * Write the main lighttpd config file
+ * @param array $options
+ * @return boolean|integer Failure or number of bytes written
+ *
+ * @author Laurent Bachelier <laurent@bachelier.name>
+ */
+ static public function writeConfig($options)
+ {
+ $config_file = $options['config_dir'].'/lighttpd.conf';
+
+ return file_put_contents(
+ $config_file,
+ Template::get($options['config_template'], $options)
+ );
+ }
+
}
diff --git a/spawn b/spawn
index e71ed37..942e093 100755
--- a/spawn
+++ b/spawn
@@ -21,6 +21,7 @@ $options['bind'] = Argument::get('A', 'all', false)
: Argument::get('b', 'bind', '127.0.0.1');
$options['project_path'] = $project_path;
$options['config_dir'] = $project_path.'/cache/lighttpd';
+$options['config_file'] = $options['config_dir'].'/lighttpd.conf';
$options['log_dir'] = $project_path.'/log/lighttpd';
// hack: .sf files are not removed by symfony cc
$options['pidfile'] = $options['config_dir'].'/.sf';
@@ -73,11 +74,7 @@ catch (ExecutableNotFoundError $e)
exit(1);
}
-$config_file = $options['config_dir'].'/lighttpd.conf';
-file_put_contents(
- $config_file,
- Template::get($options['config_template'], $options)
-);
+Template::writeConfig($options);
// Pretty information. Nothing interesting code-wise.
log_message('lighttpd started on '
@@ -105,7 +102,7 @@ flush();
if (!$options['fork'])
{
- passthru($options['lighttpd_cmd'].' -D -f '.escapeshellarg($config_file));
+ passthru($options['lighttpd_cmd'].' -D -f '.escapeshellarg($options['config_file']));
log_message('Terminated.');
}
else
@@ -156,7 +153,7 @@ else
{
unlink($options['restartfile']);
}
- passthru($options['lighttpd_cmd'].' -D -f '.escapeshellarg($config_file));
+ passthru($options['lighttpd_cmd'].' -D -f '.escapeshellarg($options['config_file']));
if (!file_exists($options['restartfile']))
{
log_message('Terminated.');
@@ -164,6 +161,7 @@ else
else
{
log_message('Something in web/ changed. Restarting lighttpd.');
+ Template::writeConfig($options);
}
} while (file_exists($options['restartfile']));
}