From 35510e73efa534d601a5fd9d64e6d506ae291bbf Mon Sep 17 00:00:00 2001 From: Matt Henderson Date: Tue, 12 Sep 2017 16:40:41 -0400 Subject: [PATCH 1/6] Run app within try block. --- application/frontend/web/index.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/application/frontend/web/index.php b/application/frontend/web/index.php index 5835d0f..fbfffa3 100644 --- a/application/frontend/web/index.php +++ b/application/frontend/web/index.php @@ -4,6 +4,8 @@ /* NOTE: The composer autoloader will be one of the first things loaded by * this required file. */ $config = require('../config/load-configs.php'); + $application = new yii\web\Application($config); + $application->run(); } catch (Sil\PhpEnv\EnvVarNotFoundException $e) { // Log to syslog (Logentries). @@ -21,6 +23,3 @@ ], JSON_PRETTY_PRINT); exit($responseContent); } - -$application = new yii\web\Application($config); -$application->run(); From b34e6e482e0c7a137948c4064f8e867302fb0f5c Mon Sep 17 00:00:00 2001 From: Matt Henderson Date: Tue, 12 Sep 2017 16:41:06 -0400 Subject: [PATCH 2/6] Catch and report any type of exception. --- application/frontend/web/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/frontend/web/index.php b/application/frontend/web/index.php index fbfffa3..cb5a6d0 100644 --- a/application/frontend/web/index.php +++ b/application/frontend/web/index.php @@ -6,11 +6,11 @@ $config = require('../config/load-configs.php'); $application = new yii\web\Application($config); $application->run(); -} catch (Sil\PhpEnv\EnvVarNotFoundException $e) { +} catch (\Throwable $t) { // Log to syslog (Logentries). openlog('email-service', LOG_NDELAY | LOG_PERROR, LOG_USER); - syslog(LOG_CRIT, $e->getMessage()); + syslog(LOG_CRIT, $t->getMessage()); closelog(); // Return error response code/message to HTTP request. @@ -18,7 +18,7 @@ http_response_code(500); $responseContent = json_encode([ 'name' => 'Internal Server Error', - 'message' => $e->getMessage(), + 'message' => $t->getMessage(), 'status' => 500, ], JSON_PRETTY_PRINT); exit($responseContent); From 651f79f9d5285f5a99705f24dc0ab1dd1bf22f55 Mon Sep 17 00:00:00 2001 From: Matt Henderson Date: Tue, 12 Sep 2017 16:46:12 -0400 Subject: [PATCH 3/6] Catch/report any CLI exception, too. --- application/yii | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/application/yii b/application/yii index c15f835..753c92c 100755 --- a/application/yii +++ b/application/yii @@ -8,32 +8,31 @@ * @license http://www.yiiframework.com/license/ */ -defined('YII_DEBUG') or define('YII_DEBUG', true); -defined('YII_ENV') or define('YII_ENV', 'dev'); - -// fcgi doesn't have STDIN and STDOUT defined by default -defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); -defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w')); - -require(__DIR__ . '/vendor/autoload.php'); -require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); -require(__DIR__ . '/common/config/bootstrap.php'); - try { + defined('YII_DEBUG') or define('YII_DEBUG', true); + defined('YII_ENV') or define('YII_ENV', 'dev'); + + // fcgi doesn't have STDIN and STDOUT defined by default + defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); + defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w')); + + require(__DIR__ . '/vendor/autoload.php'); + require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); + require(__DIR__ . '/common/config/bootstrap.php'); + $config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/common/config/main.php'), require(__DIR__ . '/console/config/main.php') ); -} catch (Sil\PhpEnv\EnvVarNotFoundException $e) { - fwrite(STDERR, $e->getMessage() . PHP_EOL); + $application = new yii\console\Application($config); + $exitCode = $application->run(); + exit($exitCode); +} catch (\Throwable $t) { + fwrite(STDERR, $t->getMessage() . PHP_EOL); openlog('email-service', LOG_NDELAY | LOG_PERROR, LOG_USER); - syslog(LOG_CRIT, $e->getMessage()); + syslog(LOG_CRIT, $t->getMessage()); closelog(); exit(1); } - -$application = new yii\console\Application($config); -$exitCode = $application->run(); -exit($exitCode); From 61888fb93ffbc8c980f43086faef1c187f7814c0 Mon Sep 17 00:00:00 2001 From: Matt Henderson Date: Tue, 12 Sep 2017 17:06:56 -0400 Subject: [PATCH 4/6] Allow HttpExceptions to return the desired error / status code. --- application/frontend/web/index.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/application/frontend/web/index.php b/application/frontend/web/index.php index cb5a6d0..9755359 100644 --- a/application/frontend/web/index.php +++ b/application/frontend/web/index.php @@ -6,6 +6,16 @@ $config = require('../config/load-configs.php'); $application = new yii\web\Application($config); $application->run(); +} catch (yii\web\HttpException $e) { + + // Log to syslog (Logentries). + openlog('email-service', LOG_NDELAY | LOG_PERROR, LOG_USER); + syslog(LOG_CRIT, $e->getMessage()); + closelog(); + + // Let the error bubble on up. + throw $e; + } catch (\Throwable $t) { // Log to syslog (Logentries). From 9b31ebfc9dc549c623462cf20c6f94a9fa7938b7 Mon Sep 17 00:00:00 2001 From: Phillip Shipley Date: Wed, 22 Nov 2017 17:34:05 -0500 Subject: [PATCH 5/6] update method of getting env into cron --- application/run-cron.sh | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/application/run-cron.sh b/application/run-cron.sh index 31631b8..d64b60f 100755 --- a/application/run-cron.sh +++ b/application/run-cron.sh @@ -18,16 +18,7 @@ chown -R www-data:www-data \ runny /data/yii migrate --interactive=0 # Dump env to a file -touch /etc/cron.d/email -env | while read line ; do - echo "$line" >> /etc/cron.d/email -done - -# Add env vars to idp-cron to make available to scripts -cat /etc/cron.d/email-cron >> /etc/cron.d/email - -# Remove original cron file without env vars -rm -f /etc/cron.d/email-cron +env >> /etc/environment # Start cron daemon cron -f From 22a94eb087cc97f888e3692773bd1454886085e8 Mon Sep 17 00:00:00 2001 From: Phillip Shipley Date: Mon, 27 Nov 2017 15:29:32 -0500 Subject: [PATCH 6/6] revert cron env load to test --- application/run-cron.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/application/run-cron.sh b/application/run-cron.sh index d64b60f..62adf12 100755 --- a/application/run-cron.sh +++ b/application/run-cron.sh @@ -18,7 +18,16 @@ chown -R www-data:www-data \ runny /data/yii migrate --interactive=0 # Dump env to a file -env >> /etc/environment +touch /etc/cron.d/email +env | while read line ; do + echo "$line" >> /etc/cron.d/email +done + +# Add env vars to idp-cron to make available to scripts +cat /etc/cron.d/email-cron >> /etc/cron.d/email + +# Remove original cron file without env vars +rm -f /etc/cron.d/email-cron # Start cron daemon cron -f