diff --git a/site-cookbooks/ipfs/.gitignore b/site-cookbooks/ipfs/.gitignore new file mode 100644 index 0000000..c15fe86 --- /dev/null +++ b/site-cookbooks/ipfs/.gitignore @@ -0,0 +1 @@ +/.kitchen/ diff --git a/site-cookbooks/ipfs/.kitchen.yml b/site-cookbooks/ipfs/.kitchen.yml new file mode 100644 index 0000000..276fa35 --- /dev/null +++ b/site-cookbooks/ipfs/.kitchen.yml @@ -0,0 +1,17 @@ +--- +driver: + name: vagrant + +provisioner: + name: chef_solo + +platforms: + - name: ubuntu-14.04 + - name: ubuntu-16.04 + - name: debian-8.7 + +suites: + - name: default + run_list: + - recipe[ipfs::default] + attributes: diff --git a/site-cookbooks/ipfs/Berksfile b/site-cookbooks/ipfs/Berksfile new file mode 100644 index 0000000..2e1a070 --- /dev/null +++ b/site-cookbooks/ipfs/Berksfile @@ -0,0 +1,3 @@ +source "https://api.berkshelf.com" + +metadata diff --git a/site-cookbooks/ipfs/Berksfile.lock b/site-cookbooks/ipfs/Berksfile.lock new file mode 100644 index 0000000..b57f089 --- /dev/null +++ b/site-cookbooks/ipfs/Berksfile.lock @@ -0,0 +1,24 @@ +DEPENDENCIES + ipfs + path: . + metadata: true + +GRAPH + ark (2.2.1) + build-essential (>= 0.0.0) + seven_zip (>= 0.0.0) + windows (>= 0.0.0) + build-essential (8.0.0) + mingw (>= 1.1) + seven_zip (>= 0.0.0) + compat_resource (12.16.3) + ipfs (0.1.0) + ark (>= 0.0.0) + mingw (1.2.5) + compat_resource (>= 12.16.3) + seven_zip (>= 0.0.0) + ohai (5.0.0) + seven_zip (2.0.2) + windows (>= 1.2.2) + windows (2.1.1) + ohai (>= 4.0.0) diff --git a/site-cookbooks/ipfs/Gemfile b/site-cookbooks/ipfs/Gemfile new file mode 100644 index 0000000..01382a5 --- /dev/null +++ b/site-cookbooks/ipfs/Gemfile @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +gem "rake" +gem "test-kitchen" +gem "kitchen-vagrant" +gem "berkshelf" diff --git a/site-cookbooks/ipfs/Gemfile.lock b/site-cookbooks/ipfs/Gemfile.lock new file mode 100644 index 0000000..e760d2b --- /dev/null +++ b/site-cookbooks/ipfs/Gemfile.lock @@ -0,0 +1,134 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.5.0) + public_suffix (~> 2.0, >= 2.0.2) + artifactory (2.7.0) + berkshelf (5.2.0) + addressable (~> 2.3, >= 2.3.4) + berkshelf-api-client (>= 2.0.2, < 4.0) + buff-config (~> 2.0) + buff-extensions (~> 2.0) + buff-shell_out (~> 1.0) + cleanroom (~> 1.0) + faraday (~> 0.9) + httpclient (~> 2.7) + minitar (~> 0.5, >= 0.5.4) + mixlib-archive (~> 0.1) + octokit (~> 4.0) + retryable (~> 2.0) + ridley (~> 5.0) + solve (> 2.0, < 4.0) + thor (~> 0.19) + berkshelf-api-client (3.0.0) + faraday (~> 0.9) + httpclient (~> 2.7) + ridley (>= 4.5, < 6.0) + buff-config (2.0.0) + buff-extensions (~> 2.0) + varia_model (~> 0.6) + buff-extensions (2.0.0) + buff-ignore (1.2.0) + buff-ruby_engine (1.0.0) + buff-shell_out (1.1.0) + buff-ruby_engine (~> 1.0) + celluloid (0.16.0) + timers (~> 4.0.0) + celluloid-io (0.16.2) + celluloid (>= 0.16.0) + nio4r (>= 1.1.0) + chef-config (12.19.36) + addressable + fuzzyurl + mixlib-config (~> 2.0) + mixlib-shellout (~> 2.0) + cleanroom (1.0.0) + erubis (2.7.0) + faraday (0.9.2) + multipart-post (>= 1.2, < 3) + fuzzyurl (0.9.0) + hashie (3.5.5) + hitimes (1.2.4) + httpclient (2.8.3) + json (2.0.3) + kitchen-vagrant (1.0.2) + test-kitchen (~> 1.4) + minitar (0.6.1) + mixlib-archive (0.4.1) + mixlib-log + mixlib-authentication (1.4.1) + mixlib-log + mixlib-config (2.2.4) + mixlib-install (2.1.12) + artifactory + mixlib-shellout + mixlib-versioning + thor + mixlib-log (1.7.1) + mixlib-shellout (2.2.7) + mixlib-versioning (1.1.0) + molinillo (0.5.6) + multipart-post (2.0.0) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (4.1.0) + net-ssh-gateway (1.3.0) + net-ssh (>= 2.6.5) + nio4r (2.0.0) + octokit (4.6.2) + sawyer (~> 0.8.0, >= 0.5.3) + public_suffix (2.0.5) + rake (11.3.0) + retryable (2.0.4) + ridley (5.1.0) + addressable + buff-config (~> 2.0) + buff-extensions (~> 2.0) + buff-ignore (~> 1.2) + buff-shell_out (~> 1.0) + celluloid (~> 0.16.0) + celluloid-io (~> 0.16.1) + chef-config (>= 12.5.0) + erubis + faraday (~> 0.9.0) + hashie (>= 2.0.2, < 4.0.0) + httpclient (~> 2.7) + json (>= 1.7.7) + mixlib-authentication (>= 1.3.0) + retryable (~> 2.0) + semverse (~> 2.0) + varia_model (~> 0.6) + safe_yaml (1.0.4) + sawyer (0.8.1) + addressable (>= 2.3.5, < 2.6) + faraday (~> 0.8, < 1.0) + semverse (2.0.0) + solve (3.1.0) + molinillo (>= 0.5) + semverse (>= 1.1, < 3.0) + test-kitchen (1.15.0) + mixlib-install (>= 1.2, < 3.0) + mixlib-shellout (>= 1.2, < 3.0) + net-scp (~> 1.1) + net-ssh (>= 2.9, < 5.0) + net-ssh-gateway (~> 1.2) + safe_yaml (~> 1.0) + thor (~> 0.18) + thor (0.19.4) + timers (4.0.4) + hitimes + varia_model (0.6.0) + buff-extensions (~> 2.0) + hashie (>= 2.0.2, < 4.0.0) + +PLATFORMS + ruby + +DEPENDENCIES + berkshelf + kitchen-vagrant + rake + test-kitchen + +BUNDLED WITH + 1.14.3 diff --git a/site-cookbooks/ipfs/chefignore b/site-cookbooks/ipfs/chefignore new file mode 100644 index 0000000..7be3c6d --- /dev/null +++ b/site-cookbooks/ipfs/chefignore @@ -0,0 +1 @@ +.kitchen diff --git a/site-cookbooks/ipfs/recipes/default.rb b/site-cookbooks/ipfs/recipes/default.rb index 81b95b7..85e45b8 100644 --- a/site-cookbooks/ipfs/recipes/default.rb +++ b/site-cookbooks/ipfs/recipes/default.rb @@ -33,26 +33,24 @@ execute "ipfs init --empty-repo" do not_if { File.directory? "/home/ipfs/.ipfs" } end -if platform?('ubuntu') && node[:platform_version].to_f >= 15.04 +if platform?('ubuntu') && node[:platform_version].to_f < 15.04 || + platform?('debian') && node['platform_version'].to_f < 8 + template "ipfs.initd.service.erb" do + path "/etc/init.d/ipfs" + source 'ipfs.initd.service.erb' + owner 'root' + group 'root' + mode '0750' + notifies :restart, "service[ipfs]", :delayed + end + service "ipfs" do - provider Chef::Provider::Service::Systemd - end - - # Configure ipfs - execute "ipfs config Addresses.Gateway /ip4/127.0.0.1/tcp/9090" do - environment "IPFS_PATH" => "/home/ipfs/.ipfs" - user "ipfs" - not_if "ipfs config Addresses.Gateway | grep /ip4/127.0.0.1/tcp/9090" - notifies :restart, "service[ipfs]", :delayed - end - - execute "ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '[\"kredits.kosmos.org\"]'" do - environment "IPFS_PATH" => "/home/ipfs/.ipfs" - user "ipfs" - not_if "ipfs config API.HTTPHeaders.Access-Control-Allow-Origin | grep kredits.kosmos.org" - notifies :restart, "service[ipfs]", :delayed + provider Chef::Provider::Service::Init::Debian + action [:enable] + supports start: true, stop: true, restart: true, reload: false, status: true end +else execute "systemctl daemon-reload" do command "systemctl daemon-reload" action :nothing @@ -67,4 +65,25 @@ if platform?('ubuntu') && node[:platform_version].to_f >= 15.04 notifies :run, "execute[systemctl daemon-reload]", :delayed notifies :restart, "service[ipfs]", :delayed end + + service "ipfs" do + provider Chef::Provider::Service::Systemd + action [:enable] + end + +end + +# Configure ipfs +execute "ipfs config Addresses.Gateway /ip4/127.0.0.1/tcp/9090" do + environment "IPFS_PATH" => "/home/ipfs/.ipfs" + user "ipfs" + not_if "ipfs config Addresses.Gateway | grep /ip4/127.0.0.1/tcp/9090" + notifies :restart, "service[ipfs]", :delayed +end + +execute "ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '[\"kredits.kosmos.org\"]'" do + environment "IPFS_PATH" => "/home/ipfs/.ipfs" + user "ipfs" + not_if "ipfs config API.HTTPHeaders.Access-Control-Allow-Origin | grep kredits.kosmos.org" + notifies :restart, "service[ipfs]", :delayed end diff --git a/site-cookbooks/ipfs/templates/default/ipfs.initd.service.erb b/site-cookbooks/ipfs/templates/default/ipfs.initd.service.erb new file mode 100644 index 0000000..38e5d74 --- /dev/null +++ b/site-cookbooks/ipfs/templates/default/ipfs.initd.service.erb @@ -0,0 +1,102 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: ipfs daemon +# Required-Start: $local_fs $remote_fs $network $syslog $named +# Required-Stop: $local_fs $remote_fs $network $syslog $named +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Starts the ipfs daemon +# Description: Starts the ipfs daemon using the start-stop-daemon +### END INIT INFO + +# Author: Dylan Powers = 3.2-14) to ensure that this file is present +# and status_of_proc is working. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() { + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test >/dev/null \ + || return 1 + start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \ + --background --chuid $IPFS_USER --no-close \ + --exec /usr/bin/env IPFS_PATH="$IPFS_PATH" $DAEMON 2>>$IPFS_PATH/daemon.log 1>/dev/null \ + -- $DAEMON_ARGS \ + || return 2 +} + +# +# Function that stops the daemon/service +# +do_stop() { + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + + # Delete the pid + rm -f $PIDFILE + return "$RETVAL" +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + status) + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + restart) + do_stop + do_start + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2 + exit 3 + ;; +esac