From 2ed9a2eddfbe3d3df68b8431e3594b590595b537 Mon Sep 17 00:00:00 2001 From: "Dmitry E. Oboukhov" <unera@debian.org> Date: Wed, 1 Oct 2014 15:35:18 +0400 Subject: [PATCH] Add status command for tarantoolctl. closes #497 --- extra/dist/dist.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/extra/dist/dist.lua b/extra/dist/dist.lua index b4d9e381ce..9e14590b8b 100755 --- a/extra/dist/dist.lua +++ b/extra/dist/dist.lua @@ -65,6 +65,18 @@ Each instance can be controlled by C<dist.lua>: dist.lua enter instance_name +=head2 status + + dist.lua status instance_name + +Check if instance is up. + +If pid file exists and control socket exists and control socket is alive +returns code C<0>. + +Return code != 0 in other cases. Can complain in log (stderr) if pid file +exists and socket doesn't, etc. + =head1 COPYRIGHT Copyright (C) 2010-2013 Tarantool AUTHORS: @@ -272,6 +284,36 @@ elseif cmd == 'enter' then console.on_client_disconnect( function(self) self.running = false end ) console.start() os.exit(0) +elseif cmd == 'status' then + if fio.stat(force_cfg.pid_file) == nil then + if errno() == errno.ENOENT then + os.exit(1) + end + log.error("Cant access pidfile %s: %s", + force_cfg.pid_file, errno.strerror()) + end + + if fio.stat(console_sock) == nil then + if errno() == errno.ENOENT then + log.warn("pidfile is exists, but control socket (%s) isn't", + console_sock) + os.exit(2) + end + end + + local s = socket.tcp_connect('unix/', console_sock) + if s == nil then + if errno() ~= errno.EACCES then + log.warn("Can't access control socket %s: %s", console_sock, + errno.strerror()) + os.exit(3) + else + os.exit(0) + end + end + + s:close() + os.exit(0) else log.error("Unknown command '%s'", cmd) os.exit(-1) -- GitLab