大网数据广告活动
服务器运维问答

Puppet generated systemd unit files?

· 52CE 我爱测

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 => …

问题原文

原帖链接 · François Beausoleil · CC BY-SA 3.0

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?

已采纳解答

原帖链接 · jaxxstorm · CC BY-SA 4.0

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,
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-11-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。