rmed

blog

Installing Zoe in a VPS

2015-08-16 07:29

I recently acquired a VPS for... things? Obviously, one of the first things I did was installing Zoe, especially since I wanted to use the sysinfo agent. Here's how that went.

Installation

First things first: let's install the dependencies:

# apt-get install git python3 perl openjdk-7-jre

Easy. Now let's download the code into, let's say, /home/zoe:

# mkdir /home/zoe
# git clone https://github.com/voiser/zoe-startup-kit.git /home/zoe

Yes, I know perfectly well that I have executed all these commands using superuser permissions, we'll fix that soon. Given that the server will always be running (ideally, of course), we want Zoe to do so as well, but although we could run the process in background from our user, a more elegant approach would be to create a special user for Zoe:

# useradd -r zoe

This will also create the zoe group, so now we can fix the permissions of the /home/zoe directory:

# chown -R zoe:zoe /home/zoe

Done! Zoe has her own user, group and home directory.

By the way: don't forget to enable localhost access in your firewall!

Execution

Ideal scenario: Zoe should run automatically when the machine starts and there should be a way of stopping and restarting the process when needed. For the first point, we are going to create an extremely simple (and probably inefficient, because I'm not used to this kind of stuff) init script. The VPS runs on a Debian jessie and that means: yay/boo systemd.

Before creating that, I'm going to create a zoe script that simplifies the steps to run Zoe and will store it in /usr/local/bin/zoe. Note that there surely are better ways to do this:

#!/bin/bash
#/usr/local/bin/zoe

cd /home/zoe

function environ() {
    . etc/environment.sh
}

case "$1" in
  "server" )
    environ
    ./zoe.sh server
    ;;
  "start" )
    environ
    ./zoe.sh start
    ;;
  "stop" )
    ./zoe.sh stop
    ;;
  "status" )
    ./zoe.sh status
    ;;
  "restart" )
    ./zoe.sh restart
    ;;
  "launch-agent" )
    ./zoe.sh launch_agent "$2"
    ;;
  "stop-agent" )
    ./zoe.sh stop_agent "$2"
    ;;
  "restart-agent" )
    ./zoe.sh restart_agent "$2"
    ;;
  "python" )
    ./zoe.sh python
    ;;
  * )
    echo "usage: ./zoe.sh server | start | stop | status | restart | launch-agent <name> | stop-agent <name> | restart-agent <name> | python"
    ;;
esac

Great, now we can create the systemd init script which will be stored in /lib/systemd/system/zoe.service:

[Unit]
Description=Zoe assistant

[Service]
Type=forking
User=zoe
Group=zoe
ExecStart=/usr/local/bin/zoe start

[Install]
WantedBy=multi-user.target

That's it, the most important part is the Service section, in which we specify that the process will fork/create other processes, that it should be run by the zoe user in the zoe group and the command to execute. In order to have this service start automatically:

# systemctl enable zoe.service

And done! Now we can restart the server to see if Zoe starts or start it manually with:

# systemctl start zoe.service