Skip to content

Commit 9db164a

Browse files
authored
Add example: create rpm&deb packages with init scripts
Took me some time to figure out how to use the api -- So I am submitting this example to add some documentation for the API, specifically pleaserun.
1 parent 9b854df commit 9db164a

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env ruby
2+
$: << File.join(File.dirname(__FILE__), "..", "..", "lib")
3+
4+
# This example uses the API to create a package from local files
5+
# it also creates necessary init-scripts and systemd files so our executable can be used as a service
6+
7+
require "fpm"
8+
require "tmpdir"
9+
require "fpm/package/pleaserun"
10+
11+
# enable logging
12+
FPM::Util.send :module_function, :logger
13+
FPM::Util.logger.level = :info
14+
FPM::Util.logger.subscribe STDERR
15+
16+
package = FPM::Package::Dir.new
17+
18+
# Set some attributes
19+
package.name = "my-service"
20+
package.version = "1.0"
21+
22+
# Add a script to run after install (should be in the current directory):
23+
package.scripts[:after_install] = 'my_after_install_script.sh'
24+
25+
# Example for adding special attributes
26+
package.attributes[:deb_group] = "super-useful"
27+
package.attributes[:rpm_group] = "super-useful"
28+
29+
# Add our files (should be in the current directory):
30+
package.input("my-executable=/usr/bin/")
31+
package.input("my-library.so=/usr/lib/")
32+
33+
# Now, add our init-scripts, systemd services, and so on:
34+
pleaserun = package.convert(FPM::Package::PleaseRun)
35+
pleaserun.input ["/usr/bin/my-executable", "--foo-from", "bar"]
36+
37+
# Create two output packages!
38+
output_packages = []
39+
output_packages << pleaserun.convert(FPM::Package::RPM)
40+
output_packages << pleaserun.convert(FPM::Package::Deb)
41+
42+
# and write them both.
43+
begin
44+
output_packages.each do |output_package|
45+
output = output_package.to_s
46+
output_package.output(output)
47+
48+
puts "successfully created #{output}"
49+
end
50+
ensure
51+
# defer cleanup until the end
52+
output_packages.each {|p| p.cleanup}
53+
end

0 commit comments

Comments
 (0)