1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/huginn_ynh.git synced 2024-09-03 19:26:13 +02:00

Inital commit

This commit is contained in:
aurel 2015-11-18 02:16:34 +01:00
commit 4b4fc3d7a7
7 changed files with 384 additions and 0 deletions

1
LICENSE Normal file
View file

@ -0,0 +1 @@
File containning the license of your package.

33
README.md Normal file
View file

@ -0,0 +1,33 @@
# YunoHost Huginn app #
##Notes
- Work only on root-domain
- No SSO auto login
- Eveything is compiled from source, may take a while to install.
##Tested on :
- Debian 7.9 inside Docker
##Config Post Install
Change the Unicorn config if needed, the [requirements.md](https://github.com/cantino/huginn/blob/master/doc/manual/requirements.md#unicorn-workers) has a section explaining the suggested amount of unicorn workers:
# Increase the amount of workers if you expect to have a high load instance.
# 2 are enough for most use cases, if the server has less then 2GB of RAM
# decrease the worker amount to 1
sudo -u huginn -H editor config/unicorn.rb
##Files
`unicorn.rb` and `.env` are located in :
/home/hugin/hugin
**Note:** You have to re-export the init script every time you change the configuration in `.env` or your `Procfile`!
sudo rake production:export
#More information:
https://github.com/cantino/huginn

50
conf/Procfile Normal file
View file

@ -0,0 +1,50 @@
###############################
# DEVELOPMENT #
###############################
# Procfile for development using the new threaded worker (scheduler, twitter stream and delayed job)
#web: bundle exec rails server -b0.0.0.0
#jobs: bundle exec rails runner bin/threaded.rb
# Old version with separate processes (use this if you have issues with the threaded version)
# web: bundle exec rails server
# schedule: bundle exec rails runner bin/schedule.rb
# twitter: bundle exec rails runner bin/twitter_stream.rb
# dj: bundle exec script/delayed_job run
###############################
# PRODUCTION #
###############################
# You need to copy or link config/unicorn.rb.example to config/unicorn.rb for both production versions.
# Have a look at the deployment guides, if you want to set up huginn on your server:
# https://github.com/cantino/huginn/doc
# Using the threaded worker (consumes less RAM but can run slower)
web: bundle exec unicorn -c config/unicorn.rb
jobs: bundle exec rails runner bin/threaded.rb
# Old version with separate processes (use this if you have issues with the threaded version)
# web: bundle exec unicorn -c config/unicorn.rb
# schedule: bundle exec rails runner bin/schedule.rb
# twitter: bundle exec rails runner bin/twitter_stream.rb
# dj: bundle exec script/delayed_job run
###############################
# Multiple DelayedJob workers #
###############################
# Per default Huginn can just run one agent at a time. Using a lot of agents or calling slow
# external services frequently might require more DelayedJob workers (an indicator for this is
# a backlog in your 'Job Management' page).
# Every uncommented line starts an additional DelayedJob worker. This works for development, production
# and for the threaded and separate worker processes. Keep in mind one worker needs about 300MB of RAM.
#
#dj2: bundle exec script/delayed_job -i 2 run
#dj3: bundle exec script/delayed_job -i 3 run
#dj4: bundle exec script/delayed_job -i 4 run
#dj5: bundle exec script/delayed_job -i 5 run
#dj6: bundle exec script/delayed_job -i 6 run
#dj7: bundle exec script/delayed_job -i 7 run
#dj8: bundle exec script/delayed_job -i 8 run
#dj9: bundle exec script/delayed_job -i 9 run
#dj10: bundle exec script/delayed_job -i 10 run

45
conf/nginx.conf Normal file
View file

@ -0,0 +1,45 @@
location YNH_WWW_PATH {
# Path to source
root /home/huginn/huginn/public;
## @huginn is a named location for the upstream fallback, see below.
try_files $uri $uri/index.html $uri.html @huginn;
# Include SSOWAT user panel.
#include conf.d/yunohost_panel.conf.inc;
}
location @huginn {
## If you use HTTPS make sure you disable gzip compression
## to be safe against BREACH attack.
gzip off;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass http://unix:/home/huginn/huginn/tmp/sockets/unicorn.socket;
}
## Enable gzip compression as per rails guide:
## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
location ~ ^/(assets)/ {
root /home/huginn/huginn/public;
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}

63
manifest.json Normal file
View file

@ -0,0 +1,63 @@
{
"name": "Huginn",
"id": "huginn",
"description": {
"en": " Build agents that monitor and act on your behalf. Your agents are standing by!"
},
"licence": "MIT",
"maintainer": {
"name": "aurel",
"email": "aurel@grudu.ovh",
"url": "https://github.com/onde2rock/huginn_ynh"
},
"multi_instance": "false",
"arguments": {
"install" : [
{
"name": "domain",
"ask": {
"en": "Choose a domain for huginn"
},
"example": "example.com"
},
{
"name": "path",
"ask": {
"en": "Choose a path for huginn"
},
"example": "/example",
"choices": ["/"],
"default": "/"
},
{
"name": "admin",
"ask": {
"en": "Choose an admin user"
},
"example": "johndoe"
},
{
"name": "password",
"ask": {
"en": "Choose an admin password"
},
"example": "supersecretpassword"
},
{
"name": "invitation",
"ask": {
"en": "Choose an invitation code for new users"
},
"example": "invitationcode"
},
{
"name": "is_public",
"ask": {
"en": "Is it a public application ?"
},
"choices": ["Yes", "No"],
"default": "No"
}
]
}
}

162
scripts/install Executable file
View file

@ -0,0 +1,162 @@
#!/bin/bash
old_pwd=$(pwd)
APP=huginn
# Retrieve arguments
domain=$1
path=$2
admin=$3
admin_pwd=$4
invitation=$5
is_public=$6
# Save APP settings
sudo yunohost app setting $APP admin -v "$admin"
sudo yunohost app setting $APP is_public -v "$is_public"
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $APP
if [[ ! $? -eq 0 ]]; then
exit 1
fi
#Import node.js repository (can be skipped on Ubuntu and Debian Jessie):
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
# Install dependencies
sudo apt-get update -qq
sudo 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 -qq
#Remove the old Ruby versions if present:
sudo apt-get remove -y ruby1.8 ruby1.9 -qq
#Download Ruby and compile it:
mkdir /tmp/ruby && cd /tmp/ruby
curl -L --silent 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 > /dev/null
make -j -s `nproc`
sudo make install
#Install the bundler and foreman gems:
sudo gem install bundler foreman --no-ri --no-rdoc
#Create a user for Huginn:
sudo adduser --disabled-login --gecos 'Huginn' huginn
#Install the database packages
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev -qq
# Initialize database and store mysql password for upgrade
db_pwd=$(sudo yunohost app initdb huginn -d huginn_production)
sudo yunohost app setting huginn mysqlpwd -v $db_pwd
# Delete db and user if exit with an error
function exit_properly
{
set +e
root_pwd=$(sudo cat /etc/yunohost/mysql)
mysql -u root -p$root_pwd -e "DROP DATABASE huginn_production ; DROP USER $APP@localhost ;"
sudo userdel $APP
sudo rm -rf /home/huginn
exit 1
}
trap exit_properly ERR
# We'll install Huginn into the home directory of the user "huginn"
cd /home/huginn
# Clone Huginn repository
sudo sudo -u huginn -H git clone https://github.com/cantino/huginn.git -b master huginn
# Go to Huginn installation folder
cd /home/huginn/huginn
# Copy the example Huginn config
sudo sudo -u huginn -H cp .env.example .env
# Create the log/, tmp/pids/ and tmp/sockets/ directories
sudo 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 sudo -u huginn -H chmod o-rwx .env
# Copy the example Unicorn config
sudo sudo -u huginn -H cp config/unicorn.rb.example config/unicorn.rb
#Install Gems
sudo sudo -u huginn -H bundle install --deployment --without development test
#rake secret
RAKE_SECRET=$(sudo sudo -u huginn -H rake secret)
#Edit .env
sudo sudo -u huginn -H sed -i "s/\(DATABASE_PASSWORD *= *\).*/\1\"$db_pwd\"/" .env
sudo sudo -u huginn -H sed -i "s/\(DATABASE_USERNAME *= *\).*/\1\"huginn\"/" .env
sudo sudo -u huginn -H sed -i "s/\(DATABASE_NAME *= *\).*/\1huginn_production/" .env
sudo sudo -u huginn -H sed -i "s/\(APP_SECRET_TOKEN *= *\).*/\1$RAKE_SECRET/" .env
sudo sudo -u huginn -H sed -i "s/\(INVITATION_CODE *= *\).*/\1$invitation/" .env
#uncomment RAILS_ENV
sudo sudo -u huginn -H sed -i '/# RAILS_ENV=production/s/^# //' .env
# Create the database
sudo sudo -u huginn -H bundle exec rake db:create RAILS_ENV=production
# Migrate to the latest version
sudo sudo -u huginn -H bundle exec rake db:migrate RAILS_ENV=production
# Create admin user and example agents
sudo sudo -u huginn -H bundle exec rake db:seed RAILS_ENV=production SEED_USERNAME=$admin SEED_PASSWORD=$admin_pwd
# Compile Assets
sudo sudo -u huginn -H bundle exec rake assets:precompile RAILS_ENV=production
#Edit the `Procfile`
cd $old_pwd
sudo cp ../conf/Procfile /home/huginn/huginn/
cd /home/huginn/huginn/
#Export the init scripts:
sudo rake production:export
### Setup Logrotate
sudo cp deployment/logrotate/huginn /etc/logrotate.d/huginn
# Modify Nginx configuration file and copy it to Nginx conf directory
cd $old_pwd
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$APP.conf
# If APP is public, add url to SSOWat conf as skipped_uris
if [ "$is_public" = "Yes" ];
then
# unprotected_uris allows SSO credentials to be passed anyway.
sudo yunohost app setting $APP unprotected_uris -v "/"
fi
#don't know where to desactivate the default in nginx, so i just delete it
sudo rm /usr/share/nginx/html/index.html
# Restart services
sudo service nginx reload
sudo yunohost app ssowatconf

30
scripts/remove Executable file
View file

@ -0,0 +1,30 @@
#!/bin/bash
app=huginn
# Retrieve arguments
domain=$(sudo yunohost app setting $app domain)
path=$(sudo yunohost app setting $app path)
admin=$(sudo yunohost app setting $app admin)
is_public=$(sudo yunohost app setting $app is_public)
cd /home/huginn/huginn/
sudo rake production:stop
# Remove sources
sudo rm -rf /home/$app
root_pwd=$(sudo cat /etc/yunohost/mysql)
mysql -u root -p$root_pwd -e "DROP DATABASE huginn_production ; DROP USER $APP@localhost ;"
sudo userdel huginn
# Remove configuration files
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
# Restart services
sudo service nginx reload
sudo yunohost app ssowatconf