From 24dcd4ee057fceb69b35b15f2253836ba5d721ad Mon Sep 17 00:00:00 2001
From: Sulverus <sulverus@gmail.com>
Date: Thu, 28 May 2015 22:25:06 +0300
Subject: [PATCH] gh-824 reload send file via control socket

---
 extra/dist/tarantoolctl | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/extra/dist/tarantoolctl b/extra/dist/tarantoolctl
index 0011525a0c..d6c5aca165 100755
--- a/extra/dist/tarantoolctl
+++ b/extra/dist/tarantoolctl
@@ -495,17 +495,35 @@ elseif cmd == 'status' then
     print(instance_name .. ' is running (pid:' .. default_cfg.pid_file .. ')')
     os.exit(0)
 elseif cmd == 'reload' then
-    if arg[1] == nil then
+    local filename = arg[1]
+    if filename == nil then
         log.error("Usage: tarantoolctl reload instance_name file.lua")
         os.exit(1)
     end
-    if fio.stat(arg[1]) == nil then
+    if fio.stat(filename) == nil then
         if errno() == errno.ENOENT then
-            print(arg[1] .. ': file not found')
+            print(filename .. ': file not found')
             os.exit(1)
         end
     end
-    dofile(arg[1])
+    local file = io.open(filename, 'rb')
+    local content = file:read('*all')
+
+    if fio.stat(console_sock) == nil then
+        log.warn("pid file exists, but the control socket (%s) doesn't",
+                console_sock)
+        os.exit(2)
+    end
+
+    local s = socket.tcp_connect('unix/', console_sock)
+    if s == nil then
+        log.warn("Can't access control socket %s", console_sock)
+        os.exit(3)
+    end
+    s:write("loadstring('" .. content .. "')()\n")
+    s:close()
+
+    os.exit(0)
 else
     log.error("Unknown command '%s'", cmd)
     os.exit(-1)
-- 
GitLab