Approach for installing system service implemented

2019-05-16 09:34发布

问题:

After years of being away from Ruby, I'm back full-force and have just cut my first gem, which includes an executable. Everything works like a charm.

The problem I am facing, however, is that I ALSO have a startup script (not part of the gem istelf) that daemonizes the executable. Additionally, I'd also like for the startup script to point the executable at configuration in a place like /var/

To the best of my knowledge, there's no way with rubygems, gemspec, etc., to specify files getting blown out to other parts of your system during install (e.g. startup script to /etc/init.d, and config to /var/). It certainly wouldn't make sense if you COULD do that.

So... my question is... what IS the proper procedure for automating the installation of something like this. I'm using RHEL, and am wondering if it's, perhaps, time for me to get my feet wet with making my first RPM.

Any thoughts?

回答1:

You can do it. However it is probably not quite the recommended approach. But yes it is possible to run arbitary code during gem installation using the extensions option.

From the RubyGems Manual:

Usage
  spec.extensions << 'ext/rmagic/extconf.rb'

Notes
These files will be run when the gem is installed, causing the 
C (or whatever) code to be compiled on the user’s machine.

Just place whatever ruby code you need into the extconf.rb (or equivalent) file.

Examples for building C-extensions from the RubyGems Guides:
http://guides.rubygems.org/c-extensions/