Commit 4f917a2c authored by Boxiang Sun's avatar Boxiang Sun

test

parent dd5bc0e0
......@@ -82,6 +82,7 @@ setup(name=name,
'apacheproxy = slapos.recipe.apacheproxy:Recipe',
'certificate_authority = slapos.recipe.certificate_authority:Recipe',
'certificate_authority.request = slapos.recipe.certificate_authority:Request',
'check_cron_service = slapos.recipe.check_cron_service:Recipe',
'check_page_content = slapos.recipe.check_page_content:Recipe',
'check_port_listening = slapos.recipe.check_port_listening:Recipe',
'check_url_available = slapos.recipe.check_url_available:Recipe',
......
##############################################################################
#
# Copyright (c) 2023 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from slapos.recipe.librecipe import GenericBaseRecipe
import sys
import os
class Recipe(GenericBaseRecipe):
"""
Create script that will check if the cron.log contains any errors.
"""
def install(self):
timeout_file = os.path.join(os.getcwd(), 'etc/promise_timeout')
config = {
'cron_log': self.options['cron_log'],
}
promise = self.createExecutable(
self.options['path'],
self.substituteTemplate(self.getTemplateFilename('check_cron.in'), config)
)
return [promise]
CRON_LOG="%(cron_log)s"
if [ -z $CRON_LOG ]; then
echo "No cron.log specified." >&2
exit 3
fi
cat $CRON_LOG | grep "ERROR" > /dev/null
# If there has an error,
# Report it to somewhere?
......@@ -15,8 +15,12 @@
[template-matomo-instance]
filename = matomo-instance.cfg.in
md5sum = 145ebeb4adcd4ec3d13929f1d2ee239c
md5sum = 8f7f7c1ae6395f5c12894eb6ba2e8424
[template-matomo-backup.sh]
filename = matomo-backup.sh.in
md5sum = fb29ad59813ef62c3f5934d4a0d90e14
[custom-promise]
filename = promise/check_cron_service.py
md5sum = 2e2696061faac493908d87a3cce10988
......@@ -20,6 +20,20 @@ context =
section parameter_dict instance-parameter
key php_bin php-bin:wrapper-path
[promise-cron]
<= monitor-promise-base
promise = check_cron_service
name = promise-cron.py
config-cron_log = ${cron-simplelogger:log}
# Add the custom promise to check that the index file exists
[check-cron-promise]
recipe = slapos.cookbook:promise.plugin
eggs = slapos.core
file = {{ custom_promise }}
output = ${directory:plugins}/check-cron-service.py
config-cron_log = ${cron-simplelogger:log}
[apache-php-service]
environment=
MATOMO_DATABASE_HOST=${mariadb-urlparse:host}:${mariadb-urlparse:port}
......
import os
from zope.interface import implementer
from slapos.grid.promise import interface
from slapos.grid.promise.generic import GenericPromise
@implementer(interface.IPromise)
class RunPromise(GenericPromise):
def __init__(self, config):
"""
Called when initialising the promise before testing.
Sets the configuration and the periodicity.
"""
super(RunPromise, self).__init__(config)
self.setPeriodicity(minute=2)
def sense(self):
"""
Called every time the promise is tested.
Signals a positive or negative result.
In this case, check whether the file exists.
"""
path = self.getConfig('cron_log')
if os.path.isfile(path):
self.logger.info("cron_log %s exists and is a file", path)
else:
self.logger.error("cron_log %s does not exist or is not a file", path)
def test(self):
"""
Called after sense() if the instance is still converging.
Returns success or failure based on sense results.
In this case, fail if the previous sensor result is negative.
"""
return self._test(result_count=1, failure_amount=1)
def anomaly(self):
"""
Called after sense() if the instance has finished converging.
Returns success or failure based on sense results.
Failure signals the instance has diverged.
In this case, fail if two out of the last three results are negative.
"""
return self._anomaly(result_count=3, failure_amount=2)
......@@ -32,7 +32,7 @@ archive-root = matomo
# Without it the instance-matomo.cfg file will not be executed
[custom-application-deployment]
path = ${template-matomo-instance:output}
part-list = matomo-backup.sh matomo-backup-cron
part-list = matomo-backup.sh matomo-backup-cron check-cron-promise
db-name = matomo
db-user = matomo
......@@ -46,11 +46,16 @@ context =
key diffutils_location diffutils:location
key php_location apache-php:location
key matomo_backup_sh template-matomo-backup.sh:target
key custom_promise custom-promise:target
# download matomo-backup.sh.in
[template-matomo-backup.sh]
<= matomo-download
# Download the custom promise
[custom-promise]
<= matomo-download
[partition-info]
recipe = slapos.cookbook:request.serialised
configuration.mariadb-computer-guid = ${slap-connection:computer-id}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment