fpm-cookery fpm 的包装工具
使用过fpm 的大概应该了解构建rpm 以及deb包的流程了,我们需要做的事情还是比较多的,fpm-cookery
是一个fpm 的包装,可以简化我们基于fpm 打包的流程
安装
预备ruby 的安装,没有写,搜索相关文档即可
- 命令
gem install fpm-cookery
使用
基于ruby 的dsl 模式定义打包流程,https://github.com/bernd/fpm-cookery/tree/master/recipes 提供了好多参考
- 配置
mkdir -p recipes/redis
cd recipes/redis
touch recipe.rb redis-server.init.d
recipe.rb:
class Redis < FPM::Cookery::Recipe
homepage 'http://redis.io'
source 'http://download.redis.io/releases/redis-6.0.4.tar.gz'
# md5 'fe6395bbd2cadc45f4f20f6bbe05ed09'
name 'redis-server'
version '6.0.4'
revision '1'
description 'An advanced key-value store.'
conflicts 'redis-server'
config_files '/etc/redis/redis.conf'
def build
make
inline_replace 'redis.conf' do |s|
s.gsub! 'daemonize no', 'daemonize yes'
end
end
def install
# make :install, 'DESTDIR' => destdir
var('lib/redis').mkdir
%w(run log/redis).each {|p| var(p).mkdir }
bin.install ['src/redis-server', 'src/redis-cli']
etc('redis').install 'redis.conf'
etc('init.d').install workdir('redis-server.init.d') => 'redis-server'
end
end
redis-server.init.d:
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
# Description: redis-server - Persistent key-value db
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/redis-server
DAEMON_ARGS=/etc/redis/redis.conf
NAME=redis-server
DESC=redis-server
PIDFILE=/var/run/redis.pid
test -x $DAEMON || exit 0
test -x $DAEMONBOOTSTRAP || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
touch $PIDFILE
chown redis:redis $PIDFILE
chown redis:redis /var/log/redis
chown redis:redis /var/lib/redis
if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid redis:redis --exec $DAEMON -- $DAEMON_ARGS
then
echo "$NAME."
else
echo "failed"
fi
;;
stop)
echo -n "Stopping $DESC: "
if start-stop-daemon --stop --retry 10 --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
then
echo "$NAME."
else
echo "failed"
fi
rm -f $PIDFILE
;;
restart|force-reload)
${0} stop
${0} start
;;
status)
if [ -f $PIDFILE ]
then
PID=`cat $PIDFILE`
echo -n "Redis (pid: $PID): "
if ps aux | grep $PID > /dev/null
then
echo "running"
exit 0
else
echo "failed"
exit 3
fi
else
echo "Redis not running"
exit 3
fi
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
- 构建
fpm-cook clean
fpm-cook
- 效果
- 不同平台以及包类型的指定
我们可以通过-t 以及-p 方便的指定deb rpm,以及centos,debian,ubuntu 等参数,指定平台(前提是我们的包是系统二进制构建好的)
参考资料
https://github.com/bernd/fpm-cookery
https://fpm-cookery.readthedocs.io/en/latest/