skynet環境構築
3828 ワード
0 x 00ウォームアップ
使用するlinux環境はubuntu 16.04です.
0 x 01構成開始
1.1環境をダウンロードする
1.2 skynetのコンパイル
0 x 02カスタムサービスのロード
2.1 skynetディレクトリの下で作成 myexamples/e 1フォルダ.configファイルの作成
2.2 server 1.luaの作成
2.3 main.luaの作成
2.4起動
以下のメッセージが表示され、自分で作成したserverが起動したことを示します.
2.5 skynetの終了
まずskynetが実行されているかどうかを確認します
ps aux | grep skynet
2.5.1使用指令終了
kill 81250
skynet端子を実行してこの情報を表示します
2.5.2 スクリプトを使用するモード
使用するlinux環境はubuntu 16.04です.
0 x 01構成開始
1.1環境をダウンロードする
sudo apt-get install autoconf
sudo apt-get install libreadline-dev
git clone https://github.com/cloudwu/skynet.git
1.2 skynetのコンパイル
cd skynet
sudo make linux
0 x 02カスタムサービスのロード
2.1 skynetディレクトリの下で作成 myexamples/e 1フォルダ.configファイルの作成
root = "./"
thread = 8
logger = nil
logpath = "."
harbor = 1
address = "127.0.0.1:2526"
master = "127.0.0.1:2013"
start = "main" -- main script
bootstrap = "snlua bootstrap" -- service/bootstrap.lua
standalone = "0.0.0.0:2013"
luaservice = root.."service/?.lua;"..root.."myexample/e1/?.lua"
lualoader = root .. "lualib/loader.lua"
lua_path = root.."lualib/?.lua;"..root.."lualib/?/init.lua"
lua_cpath = root .. "luaclib/?.so"
-- preload = "./example1/preload.lua" -- run preload.lua before every lua service run
snax = root.."example1/?.lua;"..root.."test/?.lua"
-- snax_interface_g = "snax_g"
cpath = root.."cservice/?.so"
-- daemon = "./skynet.pid"
2.2 server 1.luaの作成
-- , skynet
local skynet = require "skynet"
--
skynet.start(function()
print("==========Service1 Start=========")
-- , skynet.dispatch ( )
end)
2.3 main.luaの作成
l skynet = require "skynet"
-- ( )
skynet.start(function()
-- Skynet API
print("======Server start=======")
-- skynet.newservice(name, ...) Lua ( )
skynet.newservice("service1")
--
-- skynet.exit 。 , coroutine 。
skynet.exit()
end)
2.4起動
./skynet ./myexamples/e1/config
以下のメッセージが表示され、自分で作成したserverが起動したことを示します.
[:01000004] connect from 127.0.0.1:46904 4
[:01000006] LAUNCH harbor 1 16777221
[:01000004] Harbor 1 (fd=4) report 127.0.0.1:2526
[:01000005] Waiting for 0 harbors
[:01000005] Shakehand ready
[:01000007] LAUNCH snlua datacenterd
[:01000008] LAUNCH snlua service_mgr
======Server start=======
==========Service1 Start=========
[:01000009] LAUNCH snlua main
[:0100000a] LAUNCH snlua myserver
[:01000009] KILL self
[:01000002] KILL self
2.5 skynetの終了
まずskynetが実行されているかどうかを確認します
ps aux | grep skynet
reacher@ubuntu:~/skynet/myexamples/e1$ ps aux|grep skynet
reacher 81191 0.1 4.3 595028 43508 ? Sl 19:55 0:00 gedit /home/reacher/skynet/myexamples/e1/main.lua
reacher 81250 3.2 1.6 135464 16820 pts/4 Sl+ 20:07 0:00 ./skynet ./myexamples/e1/config
reacher 81263 0.0 0.0 14228 944 pts/20 S+ 20:07 0:00 grep --color=auto skynet
2.5.1使用指令終了
kill 81250
Terminated
skynet端子を実行してこの情報を表示します
2.5.2 スクリプトを使用するモード
#! /bin/bash
MY_USERNAME=`whoami`
MY_PID=`ps -u ${MY_USERNAME} | grep skynet| awk '{print $1}'`
if [ -z $MY_PID ]; then
echo " ..."
exit 1;
fi
kill -10 $MY_PID
echo " skynet "