4

I expected the following to actually start my service:

service{'legacy':
  ensure   => running,
  start    => "cd /vagrant/nginx-reverse-proxy/legacy && /usr/bin/bundle exec ruby app.rb -o 127.0.0.1 -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:

service{'legacy':
  ensure   => running,
  command  => "cd /vagrant/nginx-reverse-proxy/legacy && /usr/bin/bundle exec ruby app.rb -o 127.0.0.1 -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?

12

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:

[Unit]
Description=My Ruby Service
Wants=basic.target
After=basic.target network.target

[Service]
WorkingDirectory=/vagrant/nginx-reverse-proxy/legacy
ExecStart=/usr/bin/bundle exec ruby app.rb -o 127.0.0.1 -e production -p 4567"
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

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.