Towards the creation of newLISP on Rockets installation scripts...


Post #: 73
Post type: Blog post
Date: 2012-12-12 15:07:52.000
Author: Rocket Man

I'm now starting to use Rockets for projects at work, so I need a way to create the user database from scratch. Anyone wanting to start using the newLISP on Rockets Blog source code will need to do the same thing. So our desires align!

I've created a simple installation script called setup-rockets.lisp. It needs to be run from the command line:

sudo newlisp setup-rockets.lisp

This will ask you a few questions (database, name, password, etc) and set up a new database for you with the right tables and create an admin user. Obviously you never want this to be run by someone else over the web, so make sure that it can't be viewed over your web server (either by permissions, or by using my Apache .htaccess directive that excludes all files ending in .lisp from being viewed (.lsp files are fine though!)


# Prevent framework source from being accessed
<Files ~ "\.lisp$">
Order allow,deny
Deny from all
</Files>

# Prevent database files from being accessed
<Files ~ "\.db$">
Order allow,deny
Deny from all
</Files>


Once the database is created (it will append the ".db" extension as well... you notice I've excluded those files so that you can't download the database from the web or via wget) you need to make sure it has the permissions to read and write by the owner:


chown www-data:www-data DATABASENAME.db
chmod 755 DATABASENAME.db


and you should be ready to go!


xerxes on 2012-12-16 04:54:47.000

Hello Rocket-man

After using rockets-setup, checking database ok, & changing permissions, I get:

ERR: value expected in function / : total-posts

In the past, I have tried using "trace" as shown in the newLISP user guide, but without success, & I can't figure out from the source code from which module total-posts is being called ... do you have any quick guess what I have done wrong?

Rocket Man on 2012-12-17 15:28:38.000

Ah, this might be an issue of not having any blog posts, and thus the code:


; get all existing posts
(set 'total-posts (int (first (first (query (string "SELECT Count(*) FROM Posts WHERE PostType='Blog post'"))))))

(set 'total-pages (/ total-posts Blog:posts-per-page))


in rockets-main.lsp is expecting to turn the number of posts into an int, and it's returning nil, so it can't divide. Alternatively, if there are blog posts, and it's missing the variable Blog:posts-per-page (set in the file /partials/rockets-common-functions.lsp) then it would also have problems dividing, but I think it's most likely the first problem. :)

What I'll do is modify setup-rockets.lisp to create a single blog post, so hopefully that will work!

Rocket Man on 2012-12-17 15:40:48.000

Okay, I've updated setup-rockets.lisp and pushed it to GitHub. Please download the new setup script and see if that works!

Rocket Man on 2012-12-17 16:09:16.000

Oh, make sure you delete the old database file first before you re-run setup-rockets.lisp. I'm not sure if that's completely necessary, but it's what I did when I was testing. :)

xerxes on 2012-12-18 05:35:19.000

Ok, I thought it was something like that. I'll do as you suggest (including deleting the current database), thanks.

xerxes on 2012-12-18 10:14:36.000

Well, I deleted the old database, ran the script again, checked there is a post in it, did the permissions, but I still get exactly the same error on loading localhost/rockets-main.lsp.

I'll pore through the code tonight, to see if there's somewhere else that it could be looking for that.

xerxes on 2012-12-18 13:24:45.000

Didn't have time: but did test the query from rockets-main.lsp:
//
"SELECT Count(*) FROM Posts WHERE PostType='Blog post'"
//
in SQLiteMan, which does indeed return 1, so the first assignment to total-posts should be fine. It must be something further down


Rocket Man on 2012-12-18 13:42:19.000

It might not be loading the partial file /partials/rockets-common-functions.lsp . Check the permissions on that file (you might have to chmod 755) If it can't load the file, (display-partial) silently fails which means it just doesn't load all the stuff, including the variable Blog:posts-per-page.

xerxes on 2012-12-20 13:50:41.000

Ok. Checked permissions, & while doing so, found I do not have some dependencies: datepicker,js & .css. Have downloaded them now. Will place them in their folders tomorrow, though I don't think that will make a difference. I am still getting the exact same error.

Soldier on ...

Rocket Man on 2012-12-21 00:16:58.000

The CSS and JS stuff shouldn't be throwing that error.. I'll come up with some test code for you to try so we can see what the actual issue is. You may also have to chown the subdirectory /partials/, I'm not sure.

xerxes on 2012-12-21 09:20:34.000

Thanks, I have chowned the partials subdirectory, checked each file afer listing with <code>ls -al</code>and the same with all the rockets files on the main /var/www directory. I suppose I should have put these in a separate site folder, but I guess things are fine for experimenting in /var/www for now.

solvalou on 2012-12-23 02:35:32.000

i`m a bit offtopic but if you don`t know it please look how the python framework web2py.com builds default users db and all the rest. maybe it becomes more of a RAD than a framework but it sure seems well thought up. compliments for your very promising project

Rocket Man on 2012-12-24 16:02:13.000

Thanks, solvalou! I will check that out. You're right, Rockets is more designed for rapid application development. That aligns with my purposes for it--I want to be able to develop applications really quickly.

xerxes on 2013-01-03 02:23:15.000

Will email about some login problems ...

xerxes on 2013-01-03 02:25:26.000

Of course, now it's behaving - yesterday, I assumed it was something to do with our proxy or something, because I got a message saying "Comment not requested", or something like that. Today, the message went through.

Rocket Man on 2013-01-03 16:10:37.000

There is a bug (intermittent) that I've experienced before. Very rarely when posting a new comment to an existing thread it says "Sorry! No post was requested". This code executes if the post item page (the one that displays a single blog item and comments) doesn't have a value for post ID (usually it has a value because you've posted and it redirected back to the same page)

If you return to the page and enter the comment again it usually goes through. I'll be looking at this bug and trying to figure out why it happens.


Rocket Man on 2013-01-08 17:34:46.000

Okay, I installed Rockets clean from GitHub in a blank directory, and I'm getting exactly the same error (ERR: value expected in function / : total-posts) that you got. So I should be able to debug this now and finally give you a proper answer!

Rocket Man on 2013-01-08 19:22:41.000

Okay, I think I figured it out!

There was a bug in setup-rockets.lisp where I failed to close the database at the end of the script. On my earlier tests, there wasn't a problem, but when I tried it on a blank directory it simply failed to create the database. When you ran rockets-main.lsp, it tried to open a blank database and that's why it failed with that error.

I've uploaded the new setup-rockets.lsp to GitHub: https://github.com/newlisponrockets/newLISP-on-Rockets so please download the new version and try it out!

There's still an error when I try to log in, but I'll be fixing that soon, hopefully!


Rocket Man on 2013-01-08 21:51:05.000

Okay, I fixed the error in logging in, and it kind of exposed a bigger problem with the database and naming.

The setup script lets you name the database anything you want. However, the files for each page in Rockets all assume a database called "ROCKETS-BLOG.db". So I have to change the code so that the database name is stored in a config file and that file is updated via setup-rockets.lisp.

But for now, if you are having problems with the sample code, just make sure you name the database "ROCKETS-BLOG" (the .db is added automatically) and if you didn't, rename it to ROCKETS-BLOG.db and all should be well.

xerxes on 2013-01-09 06:30:28.000

I discovered the ROCKETS-BLOG problem when I found a database which I had named BLOG.db with 0 bytes on the folder, then went through the source code again, where I found ROCKETS prepended everywhere. Opting to rename it this way made all run smoothly.

Notwithstanding you saying that setup-rockets is very rudimentary, I find it very, very useful, thanks!



View this post in the forums

Views: 6288