diff --git a/setup/file-hosting-bw.py b/setup/file-hosting-bw.py new file mode 100644 index 0000000000..dbc9cb3222 --- /dev/null +++ b/setup/file-hosting-bw.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8 +from __future__ import (unicode_literals, division, absolute_import, + print_function) + +__license__ = 'GPL v3' +__copyright__ = '2014, Kovid Goyal ' + +import os, subprocess, socket + +BASE = '/srv/download/bw' + +def main(): + if not os.path.exists(BASE): + os.makedirs(BASE) + os.chdir(BASE) + + for name in 'hours days months top10 summary'.split(): + subprocess.check_call(['vnstati', '--' + name, '-o', name + '.png']) + + html = '''\ + + + Bandwidth usage for {host} + + +

Bandwidth usage for {host}

+
+

Summary

+ +
+
+

Hours

+ +
+
+

Days

+ +
+
+

Months

+ +
+
+

Top10

+ +
+ + + '''.format(host=socket.gethostname()) + + with open('index.html', 'wb') as f: + f.write(html.encode('utf-8')) + +if __name__ == '__main__': + main() diff --git a/setup/file_hosting_servers.rst b/setup/file_hosting_servers.rst index a1e9776a92..02c3aeabf2 100644 --- a/setup/file_hosting_servers.rst +++ b/setup/file_hosting_servers.rst @@ -9,14 +9,19 @@ service ssh restart hostname whatever Edit /etc/hosts and put in FQDN in the appropriate places, for example:: 127.0.0.1 download.calibre-ebook.com download - 46.28.49.116 download.calibre-ebook.com download + 46.28.49.116 download.calibre-ebook.com download echo "Asia/Kolkata" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata && ntpdate ntp.ubuntu.com apt-get update -apt-get install vim nginx zsh python-lxml python-mechanize iotop htop smartmontools mosh git ntp +apt-get install vim nginx zsh python-lxml python-mechanize iotop htop smartmontools mosh git ntp vnstat vnstati chsh -s /bin/zsh mkdir -p /root/staging /root/work/vim /srv/download /srv/manual +Edit /etc/vnstat.conf and change the default interface to whatever the interface for +the server is and change the max bandwidth to 1024 + +service vnstat restart + export server=whatever scp ~/.zshrc ~/.vimrc $server: scp -r ~/work/vim/zsh-syntax-highlighting $server:work/vim @@ -28,6 +33,7 @@ echo '#!/bin/sh\ncd /usr/local/calibre && git pull -q' > /usr/local/bin/update-c Add the following to crontab:: @hourly /usr/bin/python /usr/local/calibre/setup/plugins_mirror.py @hourly /usr/local/bin/update-calibre + @hourly /usr/bin/python /usr/local/calibre/setup/file-hosting-bw.py If the server has a backup hard-disk, mount it at /mnt/backup and edit /etc/fstab so that it is auto-mounted. Then, add the following to crontab:: @@ -43,6 +49,7 @@ ssh $server cat /etc/nginx/mime.types > /etc/nginx/mime.types rsync -avz $server:/srv/ /srv/ service nginx start + Services ---------