esl / MongoosePush

MongoosePush is a simple Elixir RESTful service allowing to send push notification via FCM and/or APNS.
Apache License 2.0
108 stars 24 forks source link

docker run not working #26

Closed jaspreet-android closed 7 years ago

jaspreet-android commented 7 years ago

I am trying to configure mod_push for mongooseIM server. I got some success but when I run docker its giving error. I am following this doc: https://mongooseim.readthedocs.io/en/latest/user-guide/Push-notifications/

My command looks like this :

docker run -v /home/ubuntu/MongooseIM/priv:/opt/app/priv -e PUSH_FCM_APP_KEY="AAAA5y_R5rA:APA91bGUmR7xsghMfgpudP64lt1JdJ2XBqxYLijGerdIaLI7Z4ZXqYfVRYjqKIUm6opCvEvS5H8m_KEtr9J_VRJlX9Ge7U-U5S2dasjjx0LtxQfjCSddhwxYXgR4goX8fBStIdoYikYM" -e PUSH_HTTPS_CERTFILE="/opt/app/priv/ssl/server.pem" -e PUSH_HTTPS_KEYFILE="/opt/app/priv/ssl/server.key" -it --rm mongooseim/mongoose-push:latest And I get error :

{"Kernel pid terminated",application_controller,"{application_start_failure,maru,{bad_return,{{'Elixir.Maru',start,[normal,[]]},{'EXIT',{#{'exception' => true,'struct' => 'Elixir.ArgumentError',message => <<\"could not start Cowboy adapter, the file /opt/app/priv/ssl/server.key required by SSL's :keyfile either does not exist, or the application does not have permission to access it\">>},[{'Elixir.Plug.Adapters.Cowboy',fail,1,[{file,\"lib/plug/adapters/cowboy.ex\"},{line,245}]},{'Elixir.Plug.Adapters.Cowboy',put_ssl_file,3,[{file,\"lib/plug/adapters/cowboy.ex\"},{line,222}]},{'Elixir.Enum','-reduce/3-lists^foldl/2-0-',3,[{file,\"lib/enum.ex\"},{line,1755}]},{'Elixir.Plug.Adapters.Cowboy',normalize_cowboy_options,2,[{file,\"lib/plug/adapters/cowboy.ex\"},{line,167}]},{'Elixir.Plug.Adapters.Cowboy',args,4,[{file,\"lib/plug/adapters/cowboy.ex\"},{line,49}]},{'Elixir.Plug.Adapters.Cowboy',child_spec,4,[{file,\"lib/plug/adapters/cowboy.ex\"},{line,137}]},{'Elixir.Maru','-start/2-fun-0-',4,[{file,\"lib/maru.ex\"},{line,32}]},{'Elixir.Enum','-reduce/3-lists^foldl/2-0-',3,[{file,\"lib/enum.ex\"},{line,1755}]}]}}}}}"} Kernel pid terminated (application_controller) ({application_start_failure,maru,{bad_return,{{'Elixir.Maru',start,[normal,[]]},{'EXIT',{#{'exception' => true,'struct' => 'Elixir.ArgumentError'

I have placed ssl in /opt/app/priv/ssl but still its not working.

rslota commented 7 years ago

Hi @jaspreet-android ,

Could you show result of ls -l /home/ubuntu/MongooseIM/priv/ssl? The issue seems very weird because locally I cannot reproduce it even without cert files / with cert files with incorrect permissions.

jaspreet-android commented 7 years ago

Hi @rslota /home/ubuntu/MongooseIM/priv/ssl is not a director in my system.

ssl are here /opt/app/priv/ssl

ubuntu@ip-172-31-36-120:/opt/app/priv/ssl$ ls -lth total 28K drwxr-xr-x 2 root root 4.0K Jul 16 04:10 priv -rw-r--r-- 1 root root 424 Jul 16 04:04 dhparam.pem -rw-rw-rw- 1 root root 3.2K Jul 15 17:13 server.key -rw-rw-rw- 1 root root 2.0K Jul 15 17:13 server.pem -rw-r--r-- 1 root root 1.7K Jul 15 16:47 rest_key.pem -rw------- 1 root root 4.7K Jul 5 19:14 rest_cert.pem

rslota commented 7 years ago

But is this a result on the docker container or your host machine?

jaspreet-android commented 7 years ago

@rslota It worked ! my successful command is ๐Ÿ‘

sudo docker run -v /home/ubuntu/MongooseIM/_build/prod/rel/mongooseim/priv/ssl:/opt/app/priv -e PUSH_FCM_APP_KEY="AAAA5y_R5rA:APA91bGUmR7xsghMfgpudP64lt1JdJ2XBqxYLijGerdIaLI7Z4ZXqYfVRYjqKIUm6opCvEvS5H8m_KEtr9J_VRJlX9Ge7U-U5S2dasjjx0LtxQfjCSddhwxYXgR4goX8fBStIdoYikYM" -e PUSH_HTTPS_CERTFILE="/opt/app/priv/server.pem" -e PUSH_HTTPS_KEYFILE="/opt/app/priv/server.key" -it --rm mongooseim/mongoose-push:latest

jaspreet-android commented 7 years ago

I am not getting push but, here are the logs logs on server :

{push_notifications,[<<"xxxx">>,[#{<<"last-message-body">> => <<"Text">>,<<"last-message-sender">> => <"923344988304@xxxx">,<<"message-count">> => <<"1">>}],#{<<"device_id">> => <<"f23Cb_HoIig:APA91bEIHafsOAVL1UH7V4lm01E0xWFT7ZJuI6OU1IHhLkhDuOVmR2nfWn87VXzRQzZuy3-MOJsCwdGaPvc__OPg7pAPZi1bNWuZMmph7UCfkyqO6N--0neyK8NrpqnYMseDBBZENjZ5">>,<<"service">> => <<"fcm">>}]} 2017-07-19 18:37:10.230 [error] <0.21389.0>@ejabberd_hooks:run_fold1:244 {function_clause,[{exml_query,cdata,[undefined],[{file,"/home/ubuntu/MongooseIM/_build/default/lib/exml/src/exml_query.erl"},{line,75}]},{mod_push,push_notification_iq,5,[{file,"/home/ubuntu/MongooseIM/_build/prod/lib/ejabberd/src/mod_push.erl"},{line,255}]},{mod_push,'-publish_message/3-fun-3-',6,[{file,"/home/ubuntu/MongooseIM/_build/prod/lib/ejabberd/src/mod_push.erl"},{line,178}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{mod_push,publish_message,3,[{file,"/home/ubuntu/MongooseIM/_build/prod/lib/ejabberd/src/mod_push.erl"},{line,176}]},{mod_push,filter_packet,1,[{file,"/home/ubuntu/MongooseIM/_build/prod/lib/ejabberd/src/mod_push.erl"},{line,124}]},{safely,apply,3,[{file,"/home/ubuntu/MongooseIM/_build/prod/lib/ejabberd/src/safely.erl"},{line,19}]},{ejabberd_hooks,hook_apply_function,5,[{file,"/home/ubuntu/MongooseIM/_build/prod/lib/ejabberd/src/ejabberd_hooks.erl"},{line,258}]}]} running hook: {filter_local_packet,[]}

rslota commented 7 years ago

The relevant error message seems to be several lines above the lines you provided. Could you post somewhere the full log file and link it here?

jaspreet-android commented 7 years ago

@rslota here is the log file.

rslota commented 7 years ago

Hi @jaspreet-android ,

Thank you for the logs. The issue here is that documentation in MongooseIM somehow wasn't updated during recent changes. In module mod_push_service_mongoosepush, option api_version has to be set to "v2". The "v1" version has been removed from implementation since it evolved during beta phase. This change should fix your issue.

rslota commented 7 years ago

Fix to the docs already waits for merge: esl/MongooseIM#1408

jaspreet-android commented 7 years ago

Thanks for helping @rslota That issue is gone now something else ๐Ÿ‘

2017-07-20 18:47:11.092 [error] <0.899.0>@mod_push_service_mongoosepush:http_notification:114 Unable to communicate to MongoosePush service due to econnrefused

rslota commented 7 years ago

Well, this is very environmental. Whatever you have set in http_connections -> mongoose_push_http -> server is not available. Test it manually, ensure that the port and host are correct.

jaspreet-android commented 7 years ago

sudo docker ps -s

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE 7c2631a42dbf mongooseim/mongoose-push:latest "/opt/app/bin/mongoo 35 hours ago Up 35 hours 8443/tcp hungry_mclean 6.727 kB This says service is running

but when I try to hit curl https://127.0.0.1:8443 I get curl: (7) Failed to connect to 127.0.0.1 port 8443: Connection refused

I checked 8443 PORT is enabled on TCP.

rslota commented 7 years ago

The 8443 should be open in your docker container, but you are trying to connect to localhost. If you want to connect via localhost, you need to add -p 8443:8443 option to your docker run command. But please note that this will not work on macOS if you are using "Docker Machine" instead of "Docker 4 Mac" (actually it will work differently, since it will forward the port to be available on Docker Machine interface). If you are using Docker 4 Mac on macOS or just Linux then this option will solve the issue.

jaspreet-android commented 7 years ago

Hey @rslota It finally worked ! Yes -p 8443:8443 done the trick. Thanks for all the help ๐Ÿ‘

deepakchaula commented 5 years ago

sudo docker ps -s

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE 7c2631a42dbf mongooseim/mongoose-push:latest "/opt/app/bin/mongoo 35 hours ago Up 35 hours 8443/tcp hungry_mclean 6.727 kB This says service is running

but when I try to hit curl https://127.0.0.1:8443 I get curl: (7) Failed to connect to 127.0.0.1 port 8443: Connection refused

I checked 8443 PORT is enabled on TCP.

I am getting this response for curl command: curl: (52) Empty reply from server