Answering my own question…
Here’s what ended up working. This is heavily reliant on the manual install guide, just customized to be easier on a 1GB DigitalOcean droplet.
user-scripts shortcut:
I bundled as much of Huginn’s dependencies into a cloud-config script that you can add when spinning up the droplet, just paste this into the User-Script section of the droplet create form:
#cloud-config
users:
- name: huginn
groups: sudo
shell: /bin/bash
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh-authorized-keys:
- ssh-rsa YOURPUBLICKEYHERE
runcmd:
- apt-get update -y
- apt-get upgrade -y
- apt-get install -y runit build-essential git zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils pkg-config cmake nodejs graphviz nginx
- apt-get remove -y ruby1.8 ruby1.9
- mkdir /tmp/ruby && cd /tmp/ruby
- curl -L --progress http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.3.tar.bz2 | tar xj
- cd ruby-2.2.3
- ./configure --disable-install-rdoc
- make -j`nproc`
- sudo make install
- sudo gem install bundler foreman --no-ri --no-rdoc
- curl -X POST http://textbelt.com/text -d number=YOURPHONENUMBERHERE -d "message=Done initializing huginn"
users block: Creates a user huginn with sudo access, add your public key if you’d like to SSH in as huginn instead of root.
runcmd block: apt-get updates and upgrades your server, installs as many of the Huginn dependencies as possible in one go. We need Ruby 2.2.3, so we bypass the standard apt-get process and download, compile and install ruby directly from source. Finally bundler and foreman are installed via gem install.
All this is going to take a while, so I end the script with a neat little hack to send me a text message when it’s done! Replace YOURPHONENUMBERHERE
with your phone #.
Finish install
Once you get the text, SSH in as root and wrap up the install with the following commands:
Database
cd /home/huginn
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
sudo mysql_secure_installation
Follow mySQL prompts to set password, then follow the prompts to lock down the install by running mysql_secure_installation
. Login to mySQL with the password you just set and create the user huginn
with a unique password.
mysql -u root -p
CREATE USER 'huginn'@'localhost' IDENTIFIED BY 'SET-A-PASSWORD-HERE';
SET storage_engine=INNODB;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES ON `huginn_production`.* TO 'huginn'@'localhost';
\q
Clone huginn source from github
This differs slightly from the manual install guide, I planned on making some of my own changes to huginn, so I forked it on github and then cloned my fork instead of cloning the master.
# We'll install Huginn into the home directory of the user "huginn"
cd /home/huginn
# Clone your fork of the huginn repo
sudo -u huginn -H git clone https://github.com/YOUR-GITHUB-USERNAME/huginn.git -b master huginn
cd huginn
# add the original upstream so you can get updates
git remote add upstream https://github.com/cantino/huginn.git
# Copy the example Huginn config
sudo -u huginn -H cp .env.example .env
# Create the log/, tmp/pids/ and tmp/sockets/ directories
sudo -u huginn mkdir -p log tmp/pids tmp/sockets
# Make sure Huginn can write to the log/ and tmp/ directories
sudo chown -R huginn log/ tmp/
sudo chmod -R u+rwX,go-w log/ tmp/
# Make sure permissions are set correctly
sudo chmod -R u+rwX,go-w log/
sudo chmod -R u+rwX tmp/
sudo -u huginn -H chmod o-rwx .env
# Copy the example Unicorn config
sudo -u huginn -H cp config/unicorn.rb.example config/unicorn.rb
Configure Huginn in .env and config/unicorn.rb files
Open the .env config file in default editor
sudo -u huginn -H editor .env
Change, the secret token, set the mysql specs we just defined, set env=production:
APP_SECRET_TOKEN=...
DATABASE_ADAPTER=mysql2
DATABASE_RECONNECT=true
DATABASE_NAME=huginn_production
DATABASE_POOL=20
DATABASE_USERNAME=huginn
DATABASE_PASSWORD='$password'
#DATABASE_HOST=your-domain-here.com
#DATABASE_PORT=3306
#DATABASE_SOCKET=/tmp/mysql.sock
DATABASE_ENCODING=utf8mb4
RAILS_ENV=production
I also edited config/unicorn.rb to only run one worker_process, which is recommended when your server has less than 2GB RAM.
sudo -u huginn -H editor config/unicorn.rb
then edit the workerprocesses to 1_
worker_processes 1
Install Gems to run huginn in production mode
sudo -u huginn -H bundle install --deployment --without development test
Initialize Database
sudo -u huginn -H bundle exec rake db:create RAILS_ENV=production
sudo -u huginn -H bundle exec rake db:migrate RAILS_ENV=production
sudo -u huginn -H bundle exec rake db:seed RAILS_ENV=production
Compile Assets / Install Init / Logrotate
sudo -u huginn -H bundle exec rake assets:precompile RAILS_ENV=production
sudo -u huginn -H editor Procfile
in the Procfile, comment out the web:
and jobs:
lines in the development section, and uncomment them in the production section. Then export and setup logrotate:
sudo bundle exec rake production:export
sudo cp deployment/logrotate/huginn /etc/logrotate.d/huginn
Configure nginx
This assumes huginn is the only web app running on the server, copy the nginx config to /etc/nginx/sites-enabled
directory and remove the default config:
sudo cp deployment/nginx/huginn /etc/nginx/sites-available/huginn
sudo ln -s /etc/nginx/sites-available/huginn /etc/nginx/sites-enabled/huginn
sudo rm /etc/nginx/sites-enabled/default
If you have a domain pointing to this droplet, specify it on the server_name
line of the nginx config:
sudo editor /etc/nginx/sites-available/huginn
Finally test the new nginx config and restart if it passes:
sudo nginx -t
sudo service nginx restart
DONE!
Now you can go to your domain or IP address and login with credentials: admin
and password
and start using huginn!
If someone can figure out how to bundle everything into a cloud-init script that would be amazing.