Very Secure

Setting up trinque's logbot on centos 6 with sbcl, quicklisp, swank, and postgres

While this guide goes over how to setup logbot, it should be a useful reference for anyone who wants to start a sbcl process on a remote machine and then be able to interact with that process through their local repl1 - connecting / disconnecting and firing off subthreads at will.

I. Install SBCL 1.4.14

Connect to your centos6 VM as root. You can download sbcl 1.4.14 from my new codeshelf.2

wget http://ztkfg.com/wp-content/uploads/codeshelf/logbot_on_centos6/sbcl-1.4.14-x86-64-linux-binary.tar.bz2
keksum sbcl-1.4.14-x86-64-linux-binary.tar.bz2
3ed51048236e419fb0d0321a1dd71f33da7fa2055682824cb07a2bda2053b3d3925510d34fcae3e9727f24bf3398bbc342b6c2fd86d12ceb7b94eeba0e0c57a0

bzip2 -cd sbcl-1.4.14-x86-64-linux-binary.tar.bz2 | tar xvf -
cd sbcl-1.4.14-x86-64-linux
./install.sh

II. Install quicklisp and swank.

Create and ssh into the user that will be running your program.3
Then download quicklisp either from quicklisp.org or from my codeshelf.

wget http://ztkfg.com/wp-content/uploads/codeshelf/logbot_on_centos6/quicklisp.lisp
keksum quicklisp.lisp
f71b197472043b0bf7cce9e44437e75b485ca3d6f32eb3e7da5687d94964b535aadc059e4cf34ad42927cb18de044aa2ac93894193d2e5ffec5ceabde948c25a

Load quicklisp, then inside the repl: install quicklisp, set (load "~/quicklisp/setup.lisp") to run when you start sbcl, then install slime so that you can start a swank server.

sbcl --load quicklisp.lisp

(quicklisp-quickstart:install)
(ql:add-to-init-file)
(ql:quickload "quicklisp-slime-helper")
(quit)

III. Start and connect to the swank server.

Make a file named start_swank.lisp, with the following contents:4

(defvar *alive* t)
(load "~/quicklisp/setup.lisp")
(ql:quickload :swank)
(swank:create-server)
(loop (sleep 10000) (if (not *alive*) (quit)))

then start the server.

nohup sbcl --script start_swank.lisp &

Now you have a swank server running. If you have a local emacs with slime installed, you can connect by using a terminal to start an ssh tunnel

ssh -L 4005:localhost:4005 USER@123.123.123.1235

and then within emacs run slime-connect to connect to the swank-server on localhost with port 4005

m-x slime-connect; ret; ret;

If you enter

*alive*

into the repl and get back T, you are connected!

IV. Grab trinque's source.

UPDATE: If you want to connect to multiple channels, you'll want ben_vulple's vpatch logbot-multiple-channels-correct

The vpatches that constitute trinque's code can be found here. Some of the vpatches use keccak for hashing, some use sha512sum. So you will need two versions of V, or a V that can handle both forms of hashing, to press everything.

Once you've grabbed the sources place them in the

~/quicklisp/local-projects/

directory of the user that will be running the swank server.

V. Install & Setup Postgres 9.4

ssh into root. First you will download the repository information to be able to install postgres94 with yum. I mirrored the repository rpm on my codeshelf.6

wget http://ztkfg.com/wp-content/uploads/codeshelf/logbot_on_centos6/pgdg-redhat-repo-latest.noarch.rpm
keksum pgdg-redhat-repo-latest.noarch.rpm
1d9c48fb19d05368b87a9c1bc0287c02f89653adbd0dc820be9b77c733c7ce6b1a07c146d6e98219c38a5bace3d42f192519f356e2f95f9062def849363cf2be

rpm -ivh pgdg-redhat-repo-latest.noarch.rpm
yum install postgresql94 postgresql94-server postgresql94-contrib

Now that postgres v9.4 is installed init the db

/etc/init.d/postgresql-9.4 initdb

That command will have created a conf file

/var/lib/pgsql/9.4/data/pg_hba.conf

Edit this file changing

# IPV4 local connections
host all all 127.0.0.1/32 ident

to

# IPV4 local connections
host all all 127.0.0.1/32 md57

Now start the db, and set it to start on boot.

/etc/init.d/postgresql-9.4 start
chkconfig postgresql-9.4 on

Then hop in the postgres shell.

su postges
psql

Once inside the postgres shell, run the following commands, changing the values in capital letters as appropriate. Note that the
NONROOTUSER needs to be the same as the name of the user created in step II. that will run logbot / the swank server.:

create database logbotdb;
create user NONROOTUSER with encrypted password 'THEPASSWORD';
grant all privileges on schema public to NONROOTUSER;
\q

Reconnect into the logbotdb and create the necessary extensions.

psql logbotdb

create extension if not exists plpgsql;
create extension if not exists pgcrypto;
create extension if not exists "uuid-ossp";

These last three create extension commands are in trinque's logbot.sql file that we are about to run. However, I had to run these manually in the shell while su'd to postgres. The NONROOTUSER does not have permission to create the extensions.

Now ssh into the NONROOTUSER and edit logbot.sql removing those three lines above.

--- create extension if not exists plpgsql;
--- create extension if not exists pgcrypto;
--- create extension if not exists "uuid-ossp";

Then run

psql -f logbot.sql logbotdb;

You're done! If you run

psql logbotdb;

and then in the postgres shell:

\dt

You should see two tables log and outbox. If everything looks good you can refer to the instructions at the end of step 3 to start the swank server that will run logbot. Once the swank server is running connect your local slime repl and then follow the logbot instructions.

---

Future steps to improve the setup process:

1. Slime and postgres9.4 and all related packages should be stored on a codeshelf.
2. Quicklisp, slime, and eventually sbcl should be signed.
3. There may be a better way to create/run the start_swank.lisp script.
4. It may be worth creating a vpatch removing logbot.sql create extensions lines and then adding the instructions on how to create the extensions while root to logbot's INSTALL file.

  1. Well the "r", "p", and "l" are local. The evaluation happens on the VM. []
  2. Note: I tried other versions of sbcl to no avail. The default version installed with yum has an asdf version incompatible with the libraries used by logbot. The most recent versions of sbcl on sbcl.org wouldn't compile on my machine. I found this version of sbcl on sourceforge. []
  3. On digitalocean you will need to allow your newly created user to accept connections from your machine by copying over the authorized_keys from root. While inside root run:

    adduser newuser
    mkdir /home/newuser/.ssh
    cp ~/.ssh/authorized_keys /home/newuser/.ssh/authorized_keys
    
    chown newuser /home/newuser/.ssh
    chown newuser /home/newuser/.ssh/authorized_keys

    []

  4. The infinite loop that sleeps for 10,000 seconds each iteration to keep the process running works well, but I do not think it's the right way to do what I want. I tried to run the script without the infinte loop with sbcl --load start_swank.lisp. However this did not work with nohup because of the way nohup redirects stdin/stdout. Using --load may work with screen, but screen does not come preinstalled on centos 6. []
  5. replace USER and 123.123.123.123 accordingly []
  6. This is put on the codeshelf for convenience. The rpm file is not the source, but rather the file that contains the location of the source. []
  7. This will allow you to later be able to connect to the database via cl's postgres library with the "encrypted" (i.e. hashed) password. []

One Response to “Setting up trinque's logbot on centos 6 with sbcl, quicklisp, swank, and postgres”

  1. [...] 1. Setting up Trinque's Logbot on Centos 6 With SBCL Quiclisp, Swank, and Postgres [...]

Leave a Reply