File: install-tutorial.rst

package info (click to toggle)
bepasty 1.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 844 kB
  • sloc: python: 2,978; javascript: 1,468; makefile: 172; sh: 30
file content (117 lines) | stat: -rw-r--r-- 3,034 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

=====================================================
Installation tutorial with Debian, NGinx and gunicorn
=====================================================

preliminary packages:

::

  apt-get install build-essential nginx supervisor python-dev git-core python-pip python-virtualenv


commands to run

::

  # add user bepasty to system
  adduser bepasty
  # change to user bepasty
  sudo su - bepasty
  # clone repository from github
  git clone https://github.com/bepasty/bepasty-server.git repo
  # create folder for storage
  mkdir storage
  # create folder for logs
  mkdir logs
  # create virtualenv
  virtualenv .
  # activate virtualenv
  . bin/activate
  cd repo
  # install bepasty and requirements
  pip install -e .
  # add gunicorn and gevent for hosting
  pip install gunicorn gevent

config file for bepasty -- ``/home/bepasty/bepasty.conf``:

Copy ``src/bepasty/config.py`` to ``/home/bepasty/bepasty.conf`` first,
remove the ``class Config`` and remove all indents in the file.
The comments can be removed too, if you feel the need to.
At last modify these two configs variables:

::

  STORAGE = 'filesystem'
  STORAGE_FILESYSTEM_DIRECTORY = '/home/bepasty/storage/'


add this content to ``/home/bepasty/bin/gunicorn_bepasty``:

::

  #!/bin/bash

  NAME="bepasty"
  HOME=/home/bepasty
  SOCKFILE=$HOME/gunicorn.sock  # we will communicate using this unix socket
  PIDFILE=$HOME/gunicorn.pid
  NUM_WORKERS=3                 # how many worker processes should Gunicorn spawn
  export BEPASTY_CONFIG=$HOME/bepasty.conf

  source $HOME/bin/activate

  cd $HOME/repo

  exec gunicorn bepasty.wsgi \
    --name $NAME \
    --workers $NUM_WORKERS \
    --log-level=info \
    --bind=unix:$SOCKFILE \
    --pid $PIDFILE \
    -k gevent

Make it executable: ``chmod +x ~/bin/gunicorn_bepasty``

A nginx configuration i.e. in ``/etc/nginx/conf.d/bepasty.conf``:

::

  upstream pasty_server {
    server unix:/home/bepasty/gunicorn.sock fail_timeout=0;
  }

  server {
    listen 80;
    #listen [::]:80; #uncomment this if your server supports IPv6
    server_name paste.example.org;  # <-- add your domainname here

    access_log /home/bepasty/logs/nginx-access.log;
    error_log /home/bepasty/logs/nginx-error.log;

    client_max_body_size 32M;

    location / {
        proxy_set_header Host $http_host;
        proxy_pass http://pasty_server;
    }

    location /static/ {
        alias /home/bepasty/repo/src/bepasty/static/;
    }
  }

Now reload your nginx configuration: `service nginx reload`.  

Supervisord config i.e. in ``/etc/supervisor/conf.d/bepasty.conf``:

::

  [program:bepasty]
  command = /home/bepasty/bin/gunicorn_bepasty                  ; Command to start app
  user = bepasty                                                ; User to run as
  stdout_logfile = /home/bepasty/logs/gunicorn_supervisor.log   ; Where to write log messages
  redirect_stderr = true                                        ; Save stderr in the same log

Finally reload supervisor: `service supervisor reload`