#!/usr/bin/env ruby require "bundler/setup" require 'base' require 'optparse' require 'json' require 'yaml' require 'active_support/all' require 'daemon_spawn' class Bitcoin2GraphdbDaemon < DaemonSpawn::Base def start(args) puts "Bitcoin2GraphdbDaemon start : #{Time.now}" migration = Bitcoin2Graphdb::Migration.new(config(args)[:bitcoin2graphdb]) migration.run end def stop puts "Bitcoin2GraphdbDaemon stop : #{Time.now}" end private def config(args) config_index = args.index("-c") if config_index && args.length > config_index + 1 && File.exists?(args[config_index + 1]) YAML.load(File.read(args[config_index + 1])).deep_symbolize_keys else raise ArgumentError.new 'configuration file not specified or does not exist.' end end end Bitcoin2GraphdbDaemon.spawn!({ working_dir: Dir.pwd, log_file: File.expand_path(Dir.pwd + '/bitcoin2graphdb.log'), pid_file: File.expand_path(Dir.pwd + '/bitcoin2graphdb.pid'), sync_log: true, singleton: true})