Determine pidfile location from RabbitMQ version
# First-party Ruby libraries
require 'resolv'
+require 'socket'
require 'timeout'
@@ -19,6 +20,9 @@ require 'monit_interface'
# methods that automatically configure and deploy rabbitmq and celery as needed.
module TaskQueue
+ # Indicates an error when determining the version of rabbitmq.
+ class UnknownVersion < StandardError; end
+
# The default name of the service.
NAME = "TaskQueue"
@@ -76,11 +80,21 @@ module TaskQueue
raise AppScaleException.new(msg)
end
+ pidfile = File.join('/', 'var', 'lib', 'rabbitmq', 'mnesia',
+ "rabbit@#{Socket.gethostname}.pid")
+ begin
+ rabbitmq_version = self.get_rabbitmq_version
+ if rabbitmq_version[0] <= 3 && rabbitmq_version[1] < 4
+ pidfile = '/var/run/rabbitmq/pid'
+ end
+ rescue TaskQueue::UnknownVersion => error
+ Djinn.log_warn("Error while getting rabbitmq version: #{error.message}")
+ end
+
Djinn.log_run("mkdir -p #{CELERY_STATE_DIR}")
service_bin = `which service`.chomp
start_cmd = "#{service_bin} rabbitmq-server start"
stop_cmd = "#{service_bin} rabbitmq-server stop"
- pidfile = '/var/run/rabbitmq/pid'
MonitInterface.start_daemon(:rabbitmq, start_cmd, stop_cmd, pidfile)
end
@@ -294,4 +308,25 @@ module TaskQueue
return server_ports
end
+ def self.get_rabbitmq_version()
+ version_re = /Version: (\d+)\.(\d+)./
+
+ begin
+ rabbitmq_info = `dpkg -s rabbitmq-server`
+ rescue Errno::ENOENT
+ raise TaskQueue::UnknownVersion.new('The dpkg command was not found')
+ end
+
+ match = version_re.match(rabbitmq_info)
+ raise TaskQueue::UnknownVersion.new('Unable to find version') if match.nil?
+
+ begin
+ major_version = Integer(match[1])
+ minor_version = Integer(match[2])
+ rescue ArgumentError, TypeError
+ raise TaskQueue::UnknownVersion.new('Invalid rabbitmq version')
+ end
+
+ return [major_version, minor_version]
+ end
end
