diff --git a/ansible/prod/inventory.yml b/ansible/prod/inventory.yml index 51ba5b9..788a14d 100644 --- a/ansible/prod/inventory.yml +++ b/ansible/prod/inventory.yml @@ -1,2 +1,4 @@ all: hosts: shmyga.ru + vars: + service_host: 172.31.1.100 diff --git a/ansible/roles/deploy/tasks/main.yml b/ansible/roles/deploy/tasks/main.yml index f0e59e1..77fa9d7 100644 --- a/ansible/roles/deploy/tasks/main.yml +++ b/ansible/roles/deploy/tasks/main.yml @@ -18,7 +18,7 @@ dest: "{{ project_dir }}/current" state: link -- name: "restart {{ project_name }} service" - systemd: - state: restarted - name: "{{ project_name }}" +#- name: "restart {{ project_name }} service" +# systemd: +# state: restarted +# name: "{{ project_name }}" diff --git a/ansible/roles/deploy/tasks/repo.yml b/ansible/roles/deploy/tasks/repo.yml index 467effe..864b06e 100644 --- a/ansible/roles/deploy/tasks/repo.yml +++ b/ansible/roles/deploy/tasks/repo.yml @@ -2,6 +2,7 @@ git: repo: "{{ repo_url }}" dest: "{{ project_dir }}/repo" + version: ansible - name: Creates directory for release file: diff --git a/ansible/roles/setup/defaults/main.yml b/ansible/roles/setup/defaults/main.yml new file mode 100644 index 0000000..b1feafd --- /dev/null +++ b/ansible/roles/setup/defaults/main.yml @@ -0,0 +1 @@ +service_host: localhost \ No newline at end of file diff --git a/ansible/roles/setup/vars/main.yml b/ansible/roles/setup/vars/main.yml index 3e73dcc..a0cf180 100644 --- a/ansible/roles/setup/vars/main.yml +++ b/ansible/roles/setup/vars/main.yml @@ -5,5 +5,5 @@ ansible_become_pass: 1234!QAZ service_name: "{{ project_name }}" service_description: "{{ project_smartname }} server" service_work_dir: "{{ project_dir }}/current/target" -service_command: "/usr/bin/neko {{ project_dir }}/current/target/{{ project_name }}.n" +service_command: "/usr/bin/neko {{ project_dir }}/current/target/{{ project_name }}.n {{ service_host }}" service_user: www-data diff --git a/build/server.js b/build/server.js index 4b75073..937fa16 100755 --- a/build/server.js +++ b/build/server.js @@ -40,7 +40,7 @@ const build = () => function build() { const test = (build) => function test() { const argv = yargs.argv; return build() - .pipe(new Neko().run(argv.dev)) + .pipe(new Neko().run('localhost')) .pipe(debug()); }; diff --git a/src/client/haxe/ru/m/tankz/Init.hx b/src/client/haxe/ru/m/tankz/Init.hx index cb1728e..9ca9d83 100644 --- a/src/client/haxe/ru/m/tankz/Init.hx +++ b/src/client/haxe/ru/m/tankz/Init.hx @@ -31,9 +31,9 @@ class Init { private static function getHost():String { #if flash var url = Lib.current.loaderInfo.url; - var r:EReg = ~/((app|https?):\/\/?[-_\w\d\.]+(:\d+)?)\/?/; - if (r.match(url) && !(r.matched(2) == "app")) { - return r.matched(1); + var r:EReg = ~/(app|https?):\/\/?([-_\w\d\.]+)(:\d+)?\/?/; + if (r.match(url) && !(r.matched(1) == "app")) { + return r.matched(2); } else { return "localhost"; } diff --git a/src/server/haxe/ru/m/tankz/server/Server.hx b/src/server/haxe/ru/m/tankz/server/Server.hx index 1f62cd8..f96ff7c 100755 --- a/src/server/haxe/ru/m/tankz/server/Server.hx +++ b/src/server/haxe/ru/m/tankz/server/Server.hx @@ -18,7 +18,7 @@ import sys.net.Socket; class Server extends ThreadServer { - private static inline var TAG = "Server"; + private static inline var TAG = 'Server'; public function new() { super(); @@ -26,16 +26,17 @@ class Server extends ThreadServer { override public function clientConnected(s:Socket):Session { var session = new Session(s); - L.d(TAG, "Client connected"); + L.d(TAG, 'Client connected'); return session; } override public function clientDisconnected(session:Session) { - L.d(TAG, "Client disconnected"); + L.d(TAG, 'Client disconnected'); session.connection.handler.emit(ConnectionEvent.DISCONNECTED); } override public function readClientMessage(session:Session, buf:Bytes, pos:Int, len:Int) { + //L.d(TAG, 'Client message: ${buf}'); return {msg: buf.sub(pos, len), bytes: len}; } @@ -52,12 +53,15 @@ class Server extends ThreadServer { #if debug L.push(new SocketLogger()); #end - L.d(TAG, "Running"); - L.i(TAG, "Build: " + CompilationOption.get("build")); + L.d(TAG, 'Running'); + L.i(TAG, 'Build: ${CompilationOption.get("build")}'); Provider.setFactory(IConfigBundle, ServerConfigBundle); Provider.setFactory(ILevelBundle, ServerLevelBundle); Provider.setFactory(IControlFactory, NoneControlFactory); + var host:String = Sys.args().length > 0 ? Sys.args()[0] : "localhost"; + var port:Int = Sys.args().length > 1 ? Std.parseInt(Sys.args()[1]) : 5000; var wserver = new Server(); - wserver.run("localhost", 5000); + L.i(TAG, 'Start on ${host}:${port}'); + wserver.run(host, port); } } \ No newline at end of file diff --git a/src/server/haxe/ru/m/tankz/server/session/Session.hx b/src/server/haxe/ru/m/tankz/server/session/Session.hx index 1ae9176..707ba74 100755 --- a/src/server/haxe/ru/m/tankz/server/session/Session.hx +++ b/src/server/haxe/ru/m/tankz/server/session/Session.hx @@ -30,6 +30,16 @@ import sys.net.Socket; typedef ServerConnection = IConnection; class Session { + private static inline var TAG = 'Session'; + + private static var POLICY_FILE:String = [ + '', + '', + '', + '', + '', + '' + ].join('\n'); public static var sessions:Map = new Map(); @@ -53,6 +63,12 @@ class Session { connection.pushData(bytes); } else { var str:String = bytes.getString(0, bytes.length); + if (str == '' + String.fromCharCode(0)) { + L.d(TAG, 'policy-file-request'); + socket.output.writeString(POLICY_FILE + String.fromCharCode(0)); + socket.output.flush(); + return; + } if (StringTools.startsWith(str, "GET")) { connection = new NekoWebConnection(socket, Request); } else { @@ -65,7 +81,7 @@ class Session { } private function onConnectionEvent(event:ConnectionEvent):Void { - L.d('Session', '${event}'); + L.d(TAG, '${event}'); } public function onRequest(request:Request):Void { diff --git a/tasks/neko.js b/tasks/neko.js index 0033911..5ff1e42 100644 --- a/tasks/neko.js +++ b/tasks/neko.js @@ -10,12 +10,12 @@ class Neko { this.tag = 'Neko'; } - run() { + run(...args) { let stream = null; const bufferContents = (file, enc, callback) => { log(this.tag, colors.cyan("run"), colors.magenta(file.path)); - exec('.', ['neko', file.path].join(' ')) + exec('.', ['neko', file.path].concat(args).join(' ')) .then(() => { stream.emit('end'); callback();