diff --git a/manifests/params.pp b/manifests/params.pp index 6de4af4..19c4fa1 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -5,4 +5,8 @@ class meetbot::params { 'xenial' => '/usr/lib/python2.7/dist-packages', default => '/usr/share/pyshared', } + $initd = $::lsbdistcodename ? { + 'trusty' => 'upstart', + default => 'systemd', + } } diff --git a/manifests/site.pp b/manifests/site.pp index f3bd1d4..6315169 100644 --- a/manifests/site.pp +++ b/manifests/site.pp @@ -106,11 +106,24 @@ define meetbot::site( environment => 'PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin', } -# we set this file as root ownership because meetbot overwrites it on shutdown -# this means when puppet changes it and restarts meetbot the file is reset - file { "/etc/init/${name}-meetbot.conf": + if ($::meetbot::params::initd == 'systemd') { + $initd_path = "/etc/systemd/system/${name}-meetbot.service" + # This is a hack to make sure that systemd is aware of the new service + # before we attempt to start it. + exec { "${name}-meetbot-systemd-daemon-reload": + command => '/bin/systemctl daemon-reload', + before => Service["${name}-meetbot"], + subscribe => File["${name}-initd"], + refreshonly => true, + } + } else { + $initd_path = "/etc/init/${name}-meetbot.conf" + } + + file { "${name}-initd": ensure => present, - content => template('meetbot/upstart.erb'), + path => $initd_path, + content => template("meetbot/${::meetbot::params::initd}.erb"), notify => Service["${name}-meetbot"], owner => 'root', replace => true, @@ -118,10 +131,10 @@ define meetbot::site( } service { "${name}-meetbot": - provider => upstart, + provider => $::meetbot::params::initd, require => [ Vcsrepo['/opt/meetbot'], - File["/etc/init/${name}-meetbot.conf"] + File["${name}-initd"] ], subscribe => [ File["${::meetbot::params::plugins_dir}/supybot/plugins/MeetBot"], diff --git a/templates/systemd.erb b/templates/systemd.erb new file mode 100644 index 0000000..9a39901 --- /dev/null +++ b/templates/systemd.erb @@ -0,0 +1,14 @@ +[Unit] +Description=<%= @name %> Meetbot Server +After=network.target + +[Service] +Type=simple +Environment=PYTHONPATH=/var/lib/meetbot/<%= @name %> +Group=meetbot +User=meetbot +WorkingDirectory=/var/lib/meetbot/<%= @name %> +ExecStart=/usr/bin/python /usr/bin/supybot /var/lib/meetbot/<%= @name %>.conf + +[Install] +WantedBy=multi-user.target