ruby-grafana-reporter icon indicating copy to clipboard operation
ruby-grafana-reporter copied to clipboard

Add systemd service file

Open bolausson opened this issue 1 year ago • 4 comments

Hej,

you might want to add a systemd service file to your repo.

Something like that: /etc/systemd/system/ruby-grafana-reporter.service

[Unit]
Description=Ruby Grafana reporter
After=network-online.target multi-user.target
Wants=network-online.target
# StartLimitIntervalSec > StartLimitBurst*RestartSec
StartLimitInterval=600s
StartLimitBurst=20

[Service]
Type=simple
User=bolausson
Group=bolausson
WorkingDirectory=/home/bolausson/tools/ruby-grafana-reporter
ExecStart=/home/bolausson/.local/share/gem/ruby/3.0.0/bin/ruby-grafana-reporter --config /home/bolausson/tools/ruby-grafana-reporter/grafana_reporter.config
KillMode=control-group
Restart=always
RestartSec=20s
SyslogIdentifier=ruby-grafana-reporter
MemoryMax=100M

[Install]
WantedBy=multi-user.target

bolausson avatar May 28 '24 13:05 bolausson

How can I add such a file to a gem? I guess, I would need some kind of an installer for including something like that, right?

If not, please give me a hint, on how this could be done. Looks interesting!

divinity666 avatar Jun 08 '24 21:06 divinity666

I have no clue about ruby and gem. I would simply add it to your GitHub repo. If people need it, they can grab it from your repo and put it in place.

If you want to include in a gem - maybe this helps: https://stackoverflow.com/questions/10625267/approach-for-installing-system-service-implemented-as-ruby-gem

bolausson avatar Jun 09 '24 14:06 bolausson

If you have a good idea on how this could be implemented to work for other users out of the box as well, feel free to provide a PR.

divinity666 avatar Mar 20 '25 20:03 divinity666

Warning:

I don't know about any best practices in the Ruby world and I don't know what is possible with the ruby install mechanism!

You would have to install it to a known destination like /opt/ruby-grafana-reporter and create a user & group e.g. "ruby-grafana-reporter" during setup.

Then you can provide a pre-configured systemd unit file e.g. by replacing in my above example:

User=bolausson
Group=bolausson
WorkingDirectory=/home/bolausson/tools/ruby-grafana-reporter
ExecStart=/home/bolausson/.local/share/gem/ruby/3.0.0/bin/ruby-grafana-reporter --config /home/bolausson/tools/ruby-grafana-reporter/grafana_reporter.config

with

User=ruby-grafana-reporter
Group=ruby-grafana-reporter
WorkingDirectory=/opt/ruby-grafana-reporter
ExecStart=/opt/ruby-grafana-reporter/bin/ruby-grafana-reporter --config /opt/ruby-grafana-reporter/etc/grafana_reporter.config

Or simply run as root (which I would not encourage to do)

bolausson avatar Mar 21 '25 06:03 bolausson