Tuesday 12 May 2015

Debian 7 - install Sentry log system

1.Install soft

#You should be able to use any of the listed mirrors by adding a line to your /etc/apt/sources.list like this:

add-apt-repository "deb http://ftp.de.debian.org/debian sid main" 

apt-get -f install
apt-get autoremove

#insall nginx-full

apt-get install nginx-full
iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
iptables-save

update-rc.d nginx defaults

#Instructions - [[http://sentry.readthedocs.org/en/latest/quickstart/index.html#dependencies]]

#install Python

apt-get install python2.7 -y

#install dependencies

apt-get install -y python-setuptools  python-pip  python-dev libxslt1-dev libxml2-dev libz-dev libffi-dev libssl-dev

#install postgresql

#add to /etc/apt/sources.list
add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main" 

apt-get install wget ca-certificates -y
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-get update -y
apt-get upgrade -y
apt-get install postgresql-9.4 pgadmin3 postgresql-server-dev-9.4 -y

#Install Redis
apt-get install build-essential
apt-get autoremove

apt-get install tcl8.5
cd /tmp
wget http://download.redis.io/releases/redis-2.8.9.tar.gz

tar xzf redis-2.8.9.tar.gz
cd redis-2.8.9

make

make test

make install

mkdir /etc/redis
mkdir /var/redis
cd /tmp/redis-2.8.9
cp utils/redis_init_script /etc/init.d/redis_6379
#change REDIS_PORT if need
cp redis.conf /etc/redis/6379.conf
mkdir /var/redis/6379

#nano /etc/redis/6379.conf
#Set daemonize to yes (by default it is set to no).
#Set the pidfile to /var/run/redis_6379.pid (modify the port if needed).
#Change the port accordingly. In our example it is not needed as the default port is already 6379.
#Set your preferred loglevel.
#Set the logfile to /var/log/redis_6379.log
#Set the dir to /var/redis/6379 (very important step!)

sed -i 's/daemonize no/ daemonize yes/g' /etc/redis/6379.conf
sed -i 's/pidfile \/var\/run\/redis.pid/ pidfile \/var\/run\/redis_6379.pid/g' /etc/redis/6379.conf
sed -i 's/logfile ""/ logfile "\/var\/log\/redis_6379.log"/g' /etc/redis/6379.conf
sed -i 's/dir .\// dir \/var\/redis\/6379/g' /etc/redis/6379.conf

update-rc.d redis_6379 defaults
/etc/init.d/redis_6379 start

# Install Sentry
pip install -U virtualenv
virtualenv /www/sentry/
source /www/sentry/bin/activate

pip install -U sentry
pip install -U sentry[postgres]
Edit

1. Config Sentry

sentry init /etc/sentry.conf.py
nano /etc/sentry.conf.py
# setttings
# ~/.sentry/sentry.conf.py

# for more information on DATABASES, see the Django configuration at:
# https://docs.djangoproject.com/en/1.6/ref/databases/
DATABASES = {
    'default': {
        # We suggest PostgreSQL for optimal performance
        'ENGINE': 'django.db.backends.postgresql_psycopg2',

        # Alternatively you can use MySQL
        #'ENGINE': 'django.db.backends.mysql',

        'NAME': 'sentry',
        'USER': 'sentry',
        'PASSWORD': 'PASS_TO_DB',
        'HOST': '127.0.0.1',
        'PORT': '',
    }
}

# No trailing slash!
SENTRY_URL_PREFIX = 'http://sentry.example.com'

SENTRY_WEB_HOST = '0.0.0.0'
SENTRY_WEB_PORT = 9000
SENTRY_WEB_OPTIONS = {
    'workers': 3,  # the number of gunicorn workers
    #'secure_scheme_headers': {'X-FORWARDED-PROTO': 'https'},  # detect HTTPS mode from X-Forwarded-Proto header
}

#Redis
SENTRY_REDIS_OPTIONS = {
    'hosts': {
        0: {
            'host': '127.0.0.1',
            'port': 6379,
            'timeout': 3,
            #'password': 'redis auth password'
        }
    }
}

#Configure Outbound Mail
EMAIL_HOST = 'localhost'
EMAIL_HOST_PASSWORD = ''
EMAIL_HOST_USER = ''
EMAIL_PORT = 25
EMAIL_USE_TLS = False
#Install DB
su - postgres
createdb -E utf-8 sentry
createuser --superuser sentry
psql
\password sentry
#set PASS_TO_DB
\q 
source /www/sentry/bin/activate
sentry --config=/etc/sentry.conf.py upgrade
# create a new user
sentry --config=/etc/sentry.conf.py createuser
mkdir /root/.sentry/
cp -v /etc/sentry.conf.py /root/.sentry/
#CONFIGURE Nginx
    location / {
      proxy_pass         http://localhost:9000;
      proxy_redirect     off;

      proxy_set_header   Host              $host;
      proxy_set_header   X-Real-IP         $remote_addr;
      proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
      proxy_set_header   X-Forwarded-Proto $scheme;
    }

#Start test and go http://IP/
sentry --config=/etc/sentry.conf.py start
#Install Supervisor launcher
pip install supervisor --pre
echo_supervisord_conf > /etc/supervisord.conf
mkdir  /var/log/supervisord
nano /etc/supervisord.conf

#Add
[program:sentry-web]
directory=/www/sentry/
command=/www/sentry/bin/sentry --config=/etc/sentry.conf.py start
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/supervisord/sentry-web.log
stderr_logfile=/var/log/supervisord/sentry-web-err.log

[program:sentry-worker]
directory=/www/sentry/
command=/www/sentry/bin/sentry --config=/etc/sentry.conf.py celery worker -B
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/supervisord/sentry-worker.log
stderr_logfile=/var/log/supervisord/sentry-worker-err.log
#init supervisord
supervisord
#start / stop
#/www/sentry/bin/supervisorctl stop all
#/www/sentry/bin/supervisorctl start all

#add auto clear for 30 days
crontab -e
#add this line: 0 3 * * * sentry cleanup --days=30

Sunday 3 May 2015

Disable some built-in functionality in Sails.js

Original post,  thanks for sgress454!

You'll need to disable several hooks, and also some middleware. First, in your .sailsrcfile, set:
"hooks": {
  "session": false,
  "sockets": false,
  "pubsub": false,
  "views": false,
  "csrf": false,
  "i18n": false,
  "blueprints": false
}
Then in your config/https.js:
middleware: {
  order: [
    'startRequestTimer',
    // 'cookieParser',
    // 'session',
    'bodyParser',
    'handleBodyParserError',
    'compress',
    'methodOverride',
    'poweredBy',
    '$custom',
    'router',
    // 'www',
    // 'favicon',
    '404',
    '500'      
  ]
}

Saturday 2 May 2015