Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding st2scheduler #4382

Merged
merged 2 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions conf/logrotate.conf
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ notifempty
endscript
}

## Scheduler
/var/log/st2/st2scheduler*.log {
daily
rotate 5
postrotate
st2ctl reopen-log-files st2scheduler > /dev/null
endscript
}

## Workflow Engine
/var/log/st2/st2workflowengine*.log {
daily
Expand Down
3 changes: 3 additions & 0 deletions conf/st2.dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ remote_dir = /tmp
logging = st2actions/conf/logging.resultstracker.conf
query_interval = 0.1

[scheduler]
logging = st2actions/conf/logging.scheduler.conf

[notifier]
logging = st2actions/conf/logging.notifier.conf

Expand Down
4 changes: 4 additions & 0 deletions conf/st2.package.conf
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ remote_dir = /tmp

[workflow_engine]
logging = /etc/st2/logging.workflowengine.conf

[scheduler]
logging = /etc/st2/logging.scheduler.conf

3 changes: 3 additions & 0 deletions conf/st2.prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ logging = /etc/st2timersengine/logging.st2timersengine.conf

[workflow_engine]
logging = /etc/st2actions/logging.workflowengine.conf

[scheduler]
logging = /etc/st2actions/logging.scheduler.conf
22 changes: 22 additions & 0 deletions st2actions/bin/st2scheduler
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python2.7
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
from st2actions.cmd import scheduler


if __name__ == '__main__':
sys.exit(scheduler.main())
44 changes: 44 additions & 0 deletions st2actions/conf/logging.scheduler.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[loggers]
keys=root

[handlers]
keys=consoleHandler, fileHandler, auditHandler

[formatters]
keys=simpleConsoleFormatter, verboseConsoleFormatter, gelfFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler, fileHandler, auditHandler

[handler_consoleHandler]
class=StreamHandler
level=INFO
formatter=simpleConsoleFormatter
args=(sys.stdout,)

[handler_fileHandler]
class=st2common.log.FormatNamedFileHandler
level=DEBUG
formatter=verboseConsoleFormatter
args=('logs/st2scheduler.log',)

[handler_auditHandler]
class=st2common.log.FormatNamedFileHandler
level=AUDIT
formatter=gelfFormatter
args=('logs/st2scheduler.audit.log',)

[formatter_simpleConsoleFormatter]
class=st2common.logging.formatters.ConsoleLogFormatter
format=%(asctime)s %(levelname)s [-] %(message)s
datefmt=

[formatter_verboseConsoleFormatter]
class=st2common.logging.formatters.ConsoleLogFormatter
format=%(asctime)s %(thread)s %(levelname)s %(module)s [-] %(message)s
datefmt=

[formatter_gelfFormatter]
class=st2common.logging.formatters.GelfLogFormatter
format=%(message)s
22 changes: 22 additions & 0 deletions st2actions/conf/syslog.scheduler.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[loggers]
keys=root

[handlers]
keys=syslogHandler

[formatters]
keys=syslogVerboseFormatter

[logger_root]
level=DEBUG
handlers=syslogHandler

[handler_syslogHandler]
class=st2common.log.ConfigurableSyslogHandler
level=DEBUG
formatter=syslogVerboseFormatter
args=()

[formatter_syslogVerboseFormatter]
format=st2scheduler[%(process)d]: %(levelname)s %(thread)s %(module)s [-] %(message)s
datefmt=
3 changes: 2 additions & 1 deletion st2actions/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'bin/st2actionrunner',
'bin/st2notifier',
'bin/st2resultstracker',
'bin/st2workflowengine'
'bin/st2workflowengine',
'bin/st2scheduler',
]
)
25 changes: 9 additions & 16 deletions st2actions/st2actions/cmd/actionrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys

from st2actions import config
from st2actions import scheduler, worker
from st2actions import worker
from st2common import log as logging
from st2common.service_setup import setup as common_setup
from st2common.service_setup import teardown as common_teardown
Expand Down Expand Up @@ -41,28 +41,21 @@ def _setup():
def _run_worker():
LOG.info('(PID=%s) Worker started.', os.getpid())

components = [
scheduler.get_scheduler(),
worker.get_worker()
]
action_worker = worker.get_worker()

try:
for component in components:
component.start()

for component in components:
component.wait()
action_worker.start()
action_worker.wait()
except (KeyboardInterrupt, SystemExit):
LOG.info('(PID=%s) Worker stopped.', os.getpid())

errors = False

for component in components:
try:
component.shutdown()
except:
LOG.exception('Unable to shutdown %s.', component.__class__.__name__)
errors = True
try:
action_worker.shutdown()
except:
LOG.exception('Unable to shutdown worker.')
errors = True

if errors:
return 1
Expand Down
82 changes: 82 additions & 0 deletions st2actions/st2actions/cmd/scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Monkey patching should be done as early as possible.
# See http://eventlet.net/doc/patching.html#monkeypatching-the-standard-library
from __future__ import absolute_import
from st2common.util.monkey_patch import monkey_patch
monkey_patch()

import os
import signal
import sys

from st2actions.scheduler import scheduler
from st2actions.scheduler import config
from st2common import log as logging
from st2common.service_setup import teardown as common_teardown
from st2common.service_setup import setup as common_setup

__all__ = [
'main'
]

LOG = logging.getLogger(__name__)


def _setup_sigterm_handler():
def sigterm_handler(signum=None, frame=None):
# This will cause SystemExit to be throw and allow for component cleanup.
sys.exit(0)

# Register a SIGTERM signal handler which calls sys.exit which causes SystemExit to
# be thrown. We catch SystemExit and handle cleanup there.
signal.signal(signal.SIGTERM, sigterm_handler)


def _setup():
common_setup(service='scheduler', config=config, setup_db=True, register_mq_exchanges=True,
register_signal_handlers=True)
_setup_sigterm_handler()


def _run_scheduler():
LOG.info('(PID=%s) Scheduler started.', os.getpid())

scheduler_instance = scheduler.get_scheduler()

try:
scheduler_instance.start()
scheduler_instance.wait()
except (KeyboardInterrupt, SystemExit):
LOG.info('(PID=%s) Scheduler stopped.', os.getpid())

errors = False

try:
scheduler_instance.shutdown()
except:
LOG.exception('Unable to shutdown scheduler.')
errors = True

if errors:
return 1
except:
LOG.exception('(PID=%s) Scheduler unexpectedly stopped.', os.getpid())
return 1

return 0


def _teardown():
common_teardown()


def main():
try:
_setup()
return _run_scheduler()
except SystemExit as exit_code:
sys.exit(exit_code)
except:
LOG.exception('(PID=%s) Scheduler quit due to exception.', os.getpid())
return 1
finally:
_teardown()
Empty file.
53 changes: 53 additions & 0 deletions st2actions/st2actions/scheduler/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

from oslo_config import cfg

from st2common import config as common_config
from st2common.constants import system as sys_constants


def parse_args(args=None):
cfg.CONF(args=args, version=sys_constants.VERSION_STRING)


def register_opts():
_register_common_opts()
_register_service_opts()


def get_logging_config_path():
return cfg.CONF.scheduler.logging


def _register_common_opts():
common_config.register_opts()


def _register_service_opts():
scheduler_opts = [
cfg.StrOpt(
'logging',
default='conf/logging.scheduler.conf',
Copy link
Member

@arm4b arm4b Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://stackstorm.slack.com/archives/C029K4CBU/p1539194738000100

One of the things we discussed in Slack if there is a chance to use safe defaults that will let the packaged service start up when respective st2.conf logging setting is absent.

Curious if it's possible to set the default to

[scheduler]
logging = /etc/st2/logging.scheduler.conf

because currently conf/logging.scheduler.conf can't be found if setting is set via st2.conf.

Not sure if that could break any Unit tests and which logging config path/st2.conf is used there.

help='Location of the logging configuration file.'
)
]

cfg.CONF.register_opts(scheduler_opts, group='scheduler')


register_opts()
2 changes: 1 addition & 1 deletion st2actions/tests/unit/test_queue_consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from kombu.message import Message

from st2actions import worker
from st2actions import scheduler
from st2actions.scheduler import scheduler
from st2actions.container.base import RunnerContainer
from st2common.constants import action as action_constants
from st2common.models.db.liveaction import LiveActionDB
Expand Down
2 changes: 1 addition & 1 deletion st2common/bin/st2ctl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

COMPONENTS="st2actionrunner st2api st2stream st2auth st2garbagecollector st2notifier st2resultstracker st2rulesengine st2sensorcontainer st2chatops st2timersengine st2workflowengine mistral"
COMPONENTS="st2actionrunner st2api st2stream st2auth st2garbagecollector st2notifier st2resultstracker st2rulesengine st2sensorcontainer st2chatops st2timersengine st2workflowengine st2scheduler mistral"
ST2_CONF="/etc/st2/st2.conf"

# Ensure global environment is sourced if exists
Expand Down
2 changes: 1 addition & 1 deletion st2tests/st2tests/mocks/liveaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import traceback

from st2actions import worker
from st2actions import scheduler
from st2actions.scheduler import scheduler
from st2common.constants import action as action_constants
from st2common.models.db.liveaction import LiveActionDB

Expand Down
8 changes: 8 additions & 0 deletions tools/launchdev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ function st2start(){
--config-file $ST2_CONF
done

# Run the scheduler server
echo 'Starting screen session st2-scheduler'
screen -d -m -S st2-scheduler ./virtualenv/bin/python \
./st2actions/bin/st2scheduler \
--config-file $ST2_CONF

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to add an entry for st2-scheduler under /~https://github.com/StackStorm/st2/blob/master/tools/launchdev.sh#L354.

# Run the sensor container server
echo 'Starting screen session st2-sensorcontainer'
screen -d -m -S st2-sensorcontainer ./virtualenv/bin/python \
Expand Down Expand Up @@ -360,6 +366,8 @@ function st2start(){
"st2-resultstracker"
"st2-notifier"
"st2-auth"
"st2-timersengine"
"st2-scheduler"
)

if [ "${include_mistral}" = true ]; then
Expand Down