Erlang boss_db hello world? - postgresql
Recently I tried to install and run a demo of boss_db ORM for Erlang.
Here is what I did:
clone the repository
cd boss_db/
rebar get-deps
put a simple mydb.erl file into src/:
-module(mydb).
-compile(export_all).
start() ->
DBOptions = [{adapter, pgsql},
{db_host, "localhost"},
{db_port, 5432},
{db_username, "postgres"},
{db_password, "mypass"},
{cache_enable, false},
{cache_exp_time, 0}],
boss_db:start(DBOptions).
rebar compile
cd ebin/
run erl
mydb:start()
Here is what I get:
** exception exit: shutdown
Whatam I doing wrong here? How is it supposed to be run?
P.S. I tried to run application:start(boss_db) as well, but the result is the same.
P.P.S. I have read the documentation twice, but I still have no idea how to run the whole thing.
You are not adding dependencies to the code path. That's why an exception is thrown when they are not found. Don't cd into ebin and erl. Instead run
erl -pa ebin -pa deps/*/ebin
from the current directory.
Btw this is not a good way to do this kind of stuff. Instead create a new empty app using rebar. Add boss_db as a dependency to your app in rebar.config. Put your own source files under src. And then
rebar get-deps compile
erl -pa ebin -pa deps/*/ebin
git clone git://github.com/evanmiller/boss_db.git
cd boss_db/
rebar get-deps
emacs src/mydb.erl
rebar compile
erl -pa ./ebin ./deps/*/ebin
These steps worked for me. code:is_loaded() will not work right after you run erl. Only when the module is invoked, the code is loaded.
I do get an application shutdown, but it is because the code is trying to connect to a Postgres DB and can't connect to it.
Erlang R15B02 (erts-5.9.2) [source] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.2 (abort with ^G)
1> mydb:start().
** exception exit: shutdown
=ERROR REPORT==== 9-Oct-2012::12:13:07 ===
** Generic server <0.35.0> terminating
** Last message in was {'EXIT',<0.34.0>,
{{badmatch,
{error,
{{badmatch,
{error,
{{badmatch,{error,econnrefused}},
[{pgsql_sock,init,1,
[{file,"src/pgsql_sock.erl"},{line,51}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}}},
[{boss_db_controller,init,1,
[{file,"src/boss_db_controller.erl"},{line,31}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}}},
[{poolboy,new_worker,2,
[{file,"src/poolboy.erl"},{line,348}]},
{poolboy,prepopulate,4,
[{file,"src/poolboy.erl"},{line,370}]},
{poolboy,init,2,
[{file,"src/poolboy.erl"},{line,74}]},
{gen_fsm,init_it,6,
[{file,"gen_fsm.erl"},{line,361}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}}
** When Server state == {state,
{<0.35.0>,poolboy_sup},
simple_one_for_one,
[{child,undefined,boss_db_controller,
{boss_db_controller,start_link,
[[{size,5},
{max_overflow,10},
{adapter,pgsql},
{db_host,"localhost"},
{db_port,5432},
{db_username,"postgres"},
{db_password,"mypass"},
{cache_enable,false},
{cache_exp_time,0}]]},
temporary,brutal_kill,worker,
[boss_db_controller]}],
{set,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[],[]}}},
0,1,[],poolboy_sup,
{boss_db_controller,
[{size,5},
{max_overflow,10},
{adapter,pgsql},
{db_host,"localhost"},
{db_port,5432},
{db_username,"postgres"},
{db_password,"mypass"},
{cache_enable,false},
{cache_exp_time,0}]}}
** Reason for termination ==
** {{badmatch,
{error,
{{badmatch,
{error,
{{badmatch,{error,econnrefused}},
[{pgsql_sock,init,1,
[{file,"src/pgsql_sock.erl"},{line,51}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}}},
[{boss_db_controller,init,1,
[{file,"src/boss_db_controller.erl"},{line,31}]},
{gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}}},
[{poolboy,new_worker,2,[{file,"src/poolboy.erl"},{line,348}]},
{poolboy,prepopulate,4,[{file,"src/poolboy.erl"},{line,370}]},
{poolboy,init,2,[{file,"src/poolboy.erl"},{line,74}]},
{gen_fsm,init_it,6,[{file,"gen_fsm.erl"},{line,361}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]}
Related
Runing mix new app_first failed on CentOS
I also encounter the problem: Runing mix new app_first failed in Elixir. It runs on centos. This is the message: The erlang version is normal : github#localhost:$ erl Erlang/OTP 24 [erts-12.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] The elixir version is normal github#localhost:~/elixir-otp-24$ bin/elixir --version Erlang/OTP 24 [erts-12.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] Elixir 1.14.0 (compiled with Erlang/OTP 24) But the mix is abnormal github#localhost:~/elixir-otp-24$ bin/mix {"init terminating in do_boot",{badarg,[{erlang,apply,[{'Elixir.Kernel.CLI.Config',[],<<".">>,[],true,[],[],false},update_commands,[#Fun<Elixir.Kernel.CLI.18.41400255>]],[{error_info,#{module=>erl_erts_errors}}]},{'Elixir.Kernel.CLI',process_argv,2,[{file,"lib/kernel/cli.ex"},{line,191}]},{'Elixir.Kernel.CLI',main,1,[{file,"lib/kernel/cli.ex"},{line,14}]},{init,start_em,1,[]},{init,do_boot,3,[]}]}} init terminating in do_boot ({badarg,[{erlang,apply,[{_},update_commands,[_]],[{_}]},{Elixir.Kernel.CLI,process_argv,2,[{_},{_}]},{Elixir.Kernel.CLI,main,1,[{_},{_}]},{init,start_em,1,[]},{init,do_boot,3,[]}]}) Crash dump is being written to: erl_crash.dump...done I have tried many ways, such as building from source. But it always failed.
I find the anwer: it should be setting environment variables. PATH=/data/github/elixir-otp-24/bin:$PATH Put it in .bashrc Source .bashrc It works github#localhost:~$ mix ** (Mix) "mix" with no arguments must be executed in a directory with a mix.exs file Usage: mix [task]
How to debug program compilation when Perl module fails
I'm trying to compile Slic3r 1.2.9 (Git 65a23b) on Raspbian, and running sudo perl Build.PL --verbose fails while building the Perl module Time-HiRes-1.9754: ... --> Working on Time::HiRes Fetching http://www.cpan.org/authors/id/J/JH/JHI/Time-HiRes-1.9754.tar.gz ... OK Configuring Time-HiRes-1.9754 ... FAIL ! Timed out (> 60s). Use --verbose to retry. ! Configure failed for Time-HiRes-1.9754. See /root/.cpanm/work/1520227993.988/build.log for details. The log file shows a little more information, but I've never worked with Perl and I don't know where to start debugging: $ tail /root/.cpanm/work/1520234788.2186/build.log Looking for clock_getres()... found. Looking for clock_nanosleep()... found. Looking for clock()... found. Looking for working futimens()... found. Looking for working utimensat()... found. You seem to have subsecond timestamp setting. Looking for stat() subsecond timestamps... Trying struct stat st_atimespec.tv_nsec...-> FAIL Timed out (> 60s). Use --verbose to retry. -> N/A -> FAIL Configure failed for Time-HiRes-1.9754. See /root/.cpanm/work/1520234788.2186/build.log for details. I've posted an issue with Slic3r on GitHub, but I haven't had any suggestions yet - presumably it's not actually a problem with Slic3r itself. What should I do next to work out what's going wrong?
Not able to compile PJSIP on Ubuntu for Blackberry 10
I am trying to compile PJSIP on Ubuntu according to this document: http://supportforums.blackberry.com/t5/Native-Development/Porting-PJSIP-PJMEDIA-and-PJLIB-to-BlackBerry-10/ta-p/2085751 When I am executing this command: ./buildpjsip (it's on number 8 in document), it is showing these errors: cp: cannot create regular file /x86/lib': No such file or directory /home/ahsish/bb10-pjsipdemo-master/pjbuildscripts/pjsip-build /home/ahsish/bb10-pjsipdemo-master/pjbuildscripts /home/ahsish/bb10-pjsipdemo-master/pjbuildscripts/pjsip-build/trunk /home/ahsish/bb10-pjsipdemo-master/pjbuildscripts/pjsip-build /home/ahsish/bb10-pjsipdemo-master/pjbuildscripts Makefile:1: build.mak: No such file or directory Makefile:2: build/host-.mak: No such file or directory make: *** No rule to make target `build/host-.mak'. Stop. checking build system type... i686-pc-linux-gnu checking host system type... i486-pc-nto-qnx8.0.0 checking target system type... i486-pc-nto-qnx8.0.0 checking for i486-pc-nto-qnx8.0.0-gcc... no checking for gcc... gcc checking whether the C compiler works... no aconfigure: error: in `/home/ahsish/bb10-pjsipdemo-master/pjbuildscripts/pjsip-build/trunk': aconfigure: error: C compiler cannot create executables See `config.log' for more details Makefile:1: build.mak: No such file or directory Makefile:2: build/host-.mak: No such file or directory make: *** No rule to make target `build/host-.mak'. Stop. Makefile:1: build.mak: No such file or directory Makefile:2: build/host-.mak: No such file or directory make: *** No rule to make target `build/host-.mak'. Stop. /home/ahsish/bb10-pjsipdemo-master/pjbuildscripts/pjsip-build /home/ahsish/bb10-pjsipdemo-master/pjbuildscripts adding: libopencore-amrwb.a (deflated 67%) adding: libopencore-amrnb.a (deflated 70%) /home/ahsish/bb10-pjsipdemo-master/pjbuildscripts*
I also encountered the issue before and solved it successfully. I think what results in the issue is that, after you executed the step 4 in the document: Execute bbndk-env.bat or bbndk-env.sh from the root of your installation of the Native SDK. You shouldn't close the command prompt or open a new terminal. I mean you should execute the rest steps in the same terminal, then you will build the library successfully. Also, you had better ensure your gcc is the newest version. Good luck for you.
You could try first: $ cd bb10-pjsipdemo/pjbuildscripts/pjsip-checkout/trunk $ ./configure $ touch pjlib/include/pj/config_site.h $ make dep $ make Reference: http://www.pjsip.org/pjlib/docs/html/pjlib_build_sys_pg.htm And then run bb10-pjsipdemo/pjbuildscripts/buildpjsip
How to set node path for nodejs (Ubuntu)
I'm trying to setup nodejs to access a postgres database. What I've done so far is the following (https://gist.github.com/579814): echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc . ~/.bashrc mkdir ~/local mkdir ~/node-latest-install cd ~/node-latest-install curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1 ./configure --prefix=~/local make install # ok, fine, this step probably takes more than 30 seconds... curl http://npmjs.org/install.sh | sh then git clone git://github.com/isaacs/npm.git make make install so far, so good. However, when I try to install the postgres driver npm install pg I get the following: node-waf configure build || true Checking for program g++ or c++ : /usr/bin/g++ Checking for program cpp : /usr/bin/cpp Checking for program ar : /usr/bin/ar Checking for program ranlib : /usr/bin/ranlib Checking for g++ : ok Checking for node path : not found Checking for node prefix : ok /usr/local Checking for program pg_config : /usr/bin/pg_config 'configure' finished successfully (0.066s) Waf: Entering directory `/home/christian/node_modules/pg/build' [1/2] cxx: src/binding.cc -> build/default/src/binding_1.o ../src/binding.cc:3:25: fatal error: node_events.h: No such file or directory compilation terminated. Waf: Leaving directory `/home/christian/node_modules/pg/build' Build failed: -> task failed (err #1): {task: cxx binding.cc -> binding_1.o} I've been looking around for setting the node path, although haven't found anything of help so far - probably also because I'm totally new to nodejs, so I'd be happy about any hint.
Now, you have NodeJS installed in your Ubuntu. You should set /etc/environment and load nodeJS path that can be executed by another users. For example: NODE="/home/ubuntu/local/node" NODE_PATH="/usr/local/lib/node_modules" PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$NODE/bin:$NODE/lib/node_modules" #PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
Do this in bash: echo 'export NODE_PATH=~/local/:~/local/node_modules' >> ~/.bashrc
before things are fixed you must use node 0.5.1 (you can use gitk to revert the tree to this version) Auteur: Ryan Dahl <ry#tinyclouds.org> 2011-07-19 10:46:38 Auteur du commit: Ryan Dahl <ry#tinyclouds.org> 2011-07-19 10:46:38 Parent: 0a3fc1d9c8becc32c63ae736ca2b3719a3d03c5b (Remove StatWatcher's dep on C++ EventEmitter) Enfant: 061ce7b0ac370c8a5ae93d95ab7da171cbd488f0 (net_uv: Fix simple/test-http-expect-continue.js) Branche: master, remotes/origin/master Suit: v0.5.1 Précède: v0.5.2 Finally remove node::EventEmitter
I had the same problem. The issue was that I was specifying a old version of PG in my package.js After I removed the old version dependancy I was able to install PG without issue.
Unable to install node-mongodb-driver
I'm trying to make the node-mongodb-native driver from git, but when i try and install it i keep on getting this error: :node-mongodb-native $ make make -C ./external-libs/bson rm -rf build .lock-wscript bson.node node-waf configure build Checking for program g++ or c++ : /usr/bin/g++ Checking for program cpp : /usr/bin/cpp Checking for program ar : /usr/bin/ar Checking for program ranlib : /usr/bin/ranlib Checking for g++ : ok Checking for node path : not found Checking for node prefix : ok /Users/name/local/node 'configure' finished successfully (0.087s) Waf: Entering directory `/Users/name/Sites/git/node-mongodb-native/external-libs/bson/build' [1/9] cxx: bson.cc -> build/default/bson_1.o [2/9] cxx: long.cc -> build/default/long_1.o [3/9] cxx: objectid.cc -> build/default/objectid_1.o [4/9] cxx: binary.cc -> build/default/binary_1.o [5/9] cxx: code.cc -> build/default/code_1.o [6/9] cxx: dbref.cc -> build/default/dbref_1.o [7/9] cxx: timestamp.cc -> build/default/timestamp_1.o [8/9] cxx: local.cc -> build/default/local_1.o [9/9] cxx_link: build/default/bson_1.o build/default/long_1.o build/default/objectid_1.o build/default/binary_1.o build/default/code_1.o build/default/dbref_1.o build/default/timestamp_1.o build/default/local_1.o -> build/default/bson.node Waf: Leaving directory `/Users/name/Sites/git/node-mongodb-native/external-libs/bson/build' 'build' finished successfully (1.935s) node.js:183 throw e; // process.nextTick error, or 'error' event on first tick ^ Error: dlopen(/Users/name/Sites/git/node-mongodb-native/external-libs/bson/build/default/bson.node, 1): Symbol not found: _ev_rt_now Referenced from: /Users/name/Sites/git/node-mongodb-native/external-libs/bson/build/default/bson.node Expected in: flat namespace in /Users/name/Sites/git/node-mongodb-native/external-libs/bson/build/default/bson.node at Object..node (module.js:472:11) at Module.load (module.js:339:31) at Function._load (module.js:298:12) at require (module.js:367:19) at Object.<anonymous> (/Users/name/Sites/git/node-mongodb-native/external-libs/bson/test_bson.js:5:10) at Module._compile (module.js:427:26) at Object..js (module.js:466:10) at Module.load (module.js:339:31) at Function._load (module.js:298:12) at Array.<anonymous> (module.js:479:10) make[1]: *** [all] Error 1 make: *** [build_native] Error 2 (some lines broken up for easier readability) The suspicious part to me is this line: Checking for node path : not found I have this as my NODE_PATH in my ~/.bash_profile: export NODE_PATH=/usr/local/lib/node_modules::/usr/local/lib/node when I ls both of those directories, this is what i get: $ ls /usr/local/lib/node wafadmin -> ../../Cellar/node/0.4.8/lib/node/wafadmin $ ls /usr/local/lib/node_modules npm I even just tried this as my NODE_PATH: export NODE_PATH=/usr/local/lib/node_modules:/usr/local/lib/node:$HOME/local/node/lib/node_modules:$HOME/local/node/lib/node which I don't think might be the best path b/c it has node installed in two locations which could lead to varying versions, but that's beside the point. has anyone else had issues installing this driver?
NPM is the best choice to manage node related packages. If you already have npm, you just run npm install -g mongodb. It will install the node mongo driver into your global node_modules directory. If you download and install node from its official website, npm will come by default.
Which version of node are you running? I was using v0.5.0-pre and I had this exact same error. Once I downgraded to v0.4.8 it worked. brew install node Or download v0.4.8 here