Add systemd support

This adds a basic service file for celeryd and associated bits to
install it on Xenial and beyond.

Change-Id: I58ab956832acabf9e5af5f815e37ed1eb365a649
This commit is contained in:
Ian Wienand 2018-04-09 09:39:28 +10:00
parent a80352f938
commit adfb969dcf
2 changed files with 59 additions and 14 deletions

View File

@ -3,20 +3,51 @@
class askbot::site::celeryd (
$site_root,
) {
file { '/etc/init/askbot-celeryd.conf':
ensure => present,
owner => 'root',
group => 'root',
mode => '0644',
content => template('askbot/celeryd.upstart.conf.erb'),
require => Exec['askbot-migrate'],
}
service { 'askbot-celeryd':
ensure => running,
enable => true,
hasrestart => true,
require => File['/etc/init/askbot-celeryd.conf'],
subscribe => [ Exec['askbot-migrate'], File["${site_root}/config/settings.py"] ]
if ($::operatingsystem == 'Ubuntu') and versioncmp($::operatingsystemrelease, '16.04') >= 0 {
file { '/etc/systemd/system/askbot-celeryd.service':
ensure => present,
owner => 'root',
group => 'root',
content => template('askbot/askbot-celeryd.service.erb'),
require => Exec['askbot-migrate'],
}
service { 'askbot-celeryd':
ensure => running,
enable => true,
hasrestart => false,
require => File['/etc/systemd/system/askbot-celeryd.service'],
}
# This is a hack to make sure that systemd is aware of the new service
# before we attempt to start it.
exec { 'celeryd-systemd-daemon-reload':
command => '/bin/systemctl daemon-reload',
before => Service['askbot-celeryd'],
subscribe => File['/etc/systemd/system/askbot-celeryd.service'],
refreshonly => true,
}
} else {
file { '/etc/init/askbot-celeryd.conf':
ensure => present,
owner => 'root',
group => 'root',
mode => '0644',
content => template('askbot/celeryd.upstart.conf.erb'),
require => Exec['askbot-migrate'],
}
service { 'askbot-celeryd':
ensure => running,
enable => true,
hasrestart => true,
require => File['/etc/init/askbot-celeryd.conf'],
subscribe => [ Exec['askbot-migrate'], File["${site_root}/config/settings.py"] ]
}
}
}

View File

@ -0,0 +1,14 @@
[Unit]
Description=Celery Service
After=network.target
[Service]
Type=simple
User=www-data
Group=www-data
WorkingDirectory=/srv/askbot-site/config
ExecStart=/usr/askbot-env/bin/python manage.py celeryd -c 5 --maxtasksperchild=1000 --time-limit=30
ExecStop=/bin/kill -INT $MAINPID
[Install]
WantedBy=multi-user.target