I expected the following to actually start my service:

  ensure   => running,
  start    => "cd /vagrant/nginx-reverse-proxy/legacy && /usr/bin/bundle exec ruby app.rb -o -e production -p ${port}",
  provider => 'systemd',

I know and undertand that the start command isn't correct, but I don't know how to start the actual Ruby Sinatra app. I actually expected something like this to work:

  ensure   => running,
  command  => "cd /vagrant/nginx-reverse-proxy/legacy && /usr/bin/bundle exec ruby app.rb -o -e production -p ${port}",
  provider => 'systemd',

Somewhat like cron. I'm used to daemontools, and systemd's model is completely different. Do I have to create the unit file myself? And link the unit file?

I've found How to enable systemd instantiated service with puppet? which starts some kind of USB device. I also found camptocamp/puppet-systemd which seems to manage systemd itself. Puppet's docs on systemd service provider are rather sparse in details.

How does one create a systemd service using Puppet?


Yes, you need to create a unit file. The command attribute you've specified there isn't actually a valid attribute for the service resource

You're best off adding an ERB template with your unit file, here's an example:

Description=My Ruby Service
After=basic.target network.target

ExecStart=/usr/bin/bundle exec ruby app.rb -o -e production -p 4567"


Then, set up the template in Puppet and make sure you refresh systemd. Some example code:

file { '/lib/systemd/system/myservice.service':
  mode    => '0644',
  owner   => 'root',
  group   => 'root',
  content => template('modulename/myservice.systemd.erb'),
exec { 'myservice-systemd-reload':
  command     => 'systemctl daemon-reload',
  path        => [ '/usr/bin', '/bin', '/usr/sbin' ],
  refreshonly => true,

Now that's done, you can start the service as normal:

service { 'myservice':
  ensure   => running,
  enable   => true,
  provider => provider,
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.