1
0
mirror of https://github.com/jordansissel/fpm synced 2025-08-27 03:41:34 +02:00
fpm/docs/source/pleaserun.rst
2017-07-28 15:31:28 -07:00

118 lines
4.4 KiB
ReStructuredText

`pleaserun` - Please, run!
===================
Synopsis::
fpm -s pleaserun [other flags] program [args...]
The `pleaserun` source uses the pleaserun_ project to help you build a package
that installs a service.
.. _pleaserun: http://github.com/jordansissel/pleaserun
`pleaserun` supports the following service managers:
* sysv, /etc/init.d/whatever
* upstart
* systemd
* runit
* launchd (OS X)
Automatic Platform Detection
----------------------------
Targeting multiple platforms with a single package is hard. What init system is used? Can you predict?
fpm+pleaserun can detect this at installation-time!
One Package for All Platforms
-----------------------------
The following is an example which creates an rpm that makes `redis` service
available::
fpm -s pleaserun -t rpm -n redis-service /usr/bin/redis-server
The output looks like this::
Created package {:path=>"redis-service-1.0-1.x86_64.rpm"}
.. note::
Your package will detect the service platform (systemd, upstart, etc) automatically upon installation :)
Let's see what happens when I install this on Fedora 25 (which uses systemd)::
% sudo rpm -i redis-service-1.0-1.x86_64.rpm
Platform systemd (default) detected. Installing service.
To start this service, use: systemctl start redis-server
And checking on our service::
% systemctl status redis-server
● redis-server.service - redis-server
Loaded: loaded (/etc/systemd/system/redis-server.service; disabled; vendor pr
Active: inactive (dead)
(It is inactive and disabled because fpm does not start it by default)
As you can see in the above example, `fpm` added an after-install script which
detects the service manager during installation. In this case, `systemd` was
detected.
The above example shows installing on Fedora 25, which uses systemd. You can use this same rpm package on CentOS 6, which uses upstart, and it will still work::
% sudo rpm -i redis-service-1.0-1.x86_64.rpm
Platform upstart (0.6.5) detected. Installing service.
To start this service, use: initctl start redis-server
And checking on our service::
% initctl status redis-server
redis-server stop/waiting
Hurray! We now have a single rpm that installs this `redis-service` service on
most systems.
Questions You May Have
----------------------
How does the package know whether to use systemd, upstart, sysv, or something else?
fpm creates a package that `does a platform check`_ when the `package is installed`_
.. _does a platform check: https://github.com/jordansissel/fpm/blob/master/templates/pleaserun/install.sh#L101-L113
.. _package is installed: https://github.com/jordansissel/fpm/blob/master/templates/pleaserun/scripts/after-install.sh
Does this mean I need ruby and pleaserun installed on the target system?
Fortunately, no! fpm creates a package that consists only of the install scripts and the service files. The install scripts are written in bourne shell `/bin/sh`.
Here's an example::
% fpm -s pleaserun -t rpm -n example /usr/bin/example
% rpm -qlp example-1.0-1.x86_64.rpm
/usr/share/pleaserun/example/generate-cleanup.sh
/usr/share/pleaserun/example/install-path.sh
/usr/share/pleaserun/example/install.sh
/usr/share/pleaserun/example/launchd/10.9/files/Library/LaunchDaemons/example.plist
/usr/share/pleaserun/example/launchd/10.9/install_actions.sh
/usr/share/pleaserun/example/systemd/default/files/etc/default/example
/usr/share/pleaserun/example/systemd/default/files/etc/systemd/system/example.service
/usr/share/pleaserun/example/systemd/default/install_actions.sh
/usr/share/pleaserun/example/sysv/lsb-3.1/files/etc/default/example
/usr/share/pleaserun/example/sysv/lsb-3.1/files/etc/init.d/example
/usr/share/pleaserun/example/upstart/0.6.5/files/etc/default/example
/usr/share/pleaserun/example/upstart/0.6.5/files/etc/init/example.conf
/usr/share/pleaserun/example/upstart/1.5/files/etc/default/example
/usr/share/pleaserun/example/upstart/1.5/files/etc/init/example.conf
The package includes service definitions for your specific service that can
target systemd, a few versions of upstart, launchd, and sysv.
Upon install, the `install.sh` script is run which detects the correct service
definition to install.
Does the package clean up after itself when I remove it?
It should. When installing, the package generates a manifest of what service files were installed, and it uses that manifest to clean up when the package is uninstalled or removed.