Restart repo

This commit is contained in:
2023-12-30 22:30:42 +01:00
commit 1c4278a3d8
37 changed files with 3019 additions and 0 deletions

161
server/gitlist.rst Normal file
View File

@@ -0,0 +1,161 @@
..
Copyright (C) 2023 Jeremie Salvi.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU
Free Documentation License".
Installation de GitList
=======================
GitList est une interface web simple et légère écrite en PHP qui permet
de visionner l'ensemble de nos dépots git sur un serveur.
.. warning:: la version 2.0.0 contient un bug qui empèche de
parcourir les différents dépots, nous installeront donc la
version 1.1.1
.. note:: J'ai installé GitList sous Debian 11, pour d'autres distributions il
faudra adapter quelques paramètres, comme par exemple sous ArchLinux :
- l'utilisateur apache est ``http`` et non ``www-data``,
- le home directory de l'utilisateur apache est ``/srv/http`` et non ``/var/www``.
configuration d'apache
----------------------
On va configurer un simple vhost, en suivant les `recommendations
fournies par le développeur <https://github.com/klaussilveira/gitlist/wiki/Configuring-Gitlist-in-CENTOS7>`_.
On créer le vhost ``/etc/apache2/sites-available/gitlist.conf`` :
.. code-block:: apache
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@yourdomain.domain
ServerName gitlist.yourdomain.domain
DocumentRoot /var/www/gitlist
<Directory /var/www/gitlist/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/gitlist-error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# enable HTTP/2, if available
Protocols h2 http/1.1
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/gitlist.yourdomain.domain/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/gitlist.yourdomain.domain/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/gitlist.yourdomain.domain/chain.pem
</VirtualHost>
</IfModule>
Installation de gitlist
-----------------------
On se place dans notre repertoire root, on télécharge le zip, on l'extrait :
.. code-block:: bash
cd /var/www/gitlist
wget https://github.com/klaussilveira/gitlist/releases/download/1.1.1/gitlist-1.1.1.zip
unzip gitlist-1.1.1.zip
Configuration
-------------
Quand on ouvre notre navigateur, on fait face a plusieurs messages d'erreur.
Configurons notre serveur pour que tout fonctionne correctement :
on créer un dossier ``cache`` et on attribue les droits du répertoire racine à l'utilisateur
apache (``www-data``).
.. code-block:: bash
mkdir cache
chown -R www-data:www-data ./
On créer ensuite le fichier ``config.ini`` à partir du fichier ``config.ini-example`` fourni :
.. code-block:: bash
cp config.ini-example config.ini
vi config.ini
On modifie la ligne suivante pour indiquer le chemin des dépots :
.. code-block:: php
repositories[] = '/home/git/repositories/'
Et voilà, on à la liste de nos dépots. Il reste une erreur quand on essaye de
parcourir un dépot. cela est du au fait que l'utilisateur ``www-data`` qui utilise la
commande git n'as pas les droits sur le dossier du dépot. Git renvoie l'erreur suivante :
``fatal: detected dubious ownership in repository at '/home/git/repositories/doc.git' To add an exception for this directory, call: git config --global --add safe.directory /home/git/repositories/doc.git``.
La solution est dans le message, on execute la commande suivante pour chaque dépot :
.. code-block:: bash
sudo -u www-data git config --global --add safe.directory /home/git/repositories/doc.git
.. warning:: git créer un fichier .gitconfig dans le home directory pour stocker ces paramètres.
il faut s'assurer que l'utilisateur apache à bien accès en écriture à son home directory.
Sous debian, ``www-data`` utilise ``/var/www`` comme home directory. on le rend accessible en
écriture :
.. code-block:: bash
chown www-data:www-data /var/www
Rendre les dépots clonable par https (en téléchargement uniquement)
-------------------------------------------------------------------
Pour que git puisse cloner un dépot, il besoin de traitements spéciaux côté serveur.
Heureusement, git est foutni avec un binaire ``git-http-backend``, qui fait ce traitement.
Il suffit de le passer comme script cgi à apache.
On commence à activer les mods nécessaires pour apache :
.. code-block:: bash
a2enmod cgi alias env
On ajoute ensuite la configuration suivante à notre vhost :
.. code-block:: apache
SetEnv GIT_PROJECT_ROOT /data/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git /usr/lib/git-core/git-http-backend
<Directory "/usr/lib/git-core/">
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
</Directory>
Alias /git /data/git
Pour terminer, on ajouste le config.ini de notre site, notament le http_url_subdir.
.. code-block:: php
; http remote
show_http_remote = true ; display remote URL for HTTP
http_host = '' ; host to use for cloning via HTTP (default: none => uses gitlist web host)
use_https = true ; generate URL with https://
http_url_subdir = 'git/' ; if cloning via HTTP is triggered using virtual dir (e.g. https://example.com/git/repo.git)
; has to end with trailing slash
http_user = '' ; user to use for cloning via HTTP (default: none)
http_user_dynamic = false ; when enabled, http_user is set to $_SERVER['PHP_AUTH_USER']

330
server/rutorrent.rst Normal file
View File

@@ -0,0 +1,330 @@
..
Copyright (C) 2023 Jeremie Salvi.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU
Free Documentation License".
Installation de ruTorrent
=========================
Prérequis
---------
Pour l'installation de ruTorrent, il faut au minimum avoid les paquets suivants s'installés :
- apache 2.4.x
- rtorrent 0.9.7
- libtorrent 0.13.7
- ruTorrent 3.10
Installation de rtorrent
------------------------
Créer un home directory :
.. code-block:: bash
mkdir /data/rtorrent
cd /data/rtorrent
Configurer rtorrent avec le script du développeur : `<https://github.com/rakshasa/rtorrent/wiki/CONFIG-Template>`_
.. code-block:: bash
curl -Ls "https://raw.githubusercontent.com/wiki/rakshasa/rtorrent/CONFIG-Template.md" \
| sed -ne "/^######/,/^### END/p" \
| sed -re "s:/home/USERNAME:$HOME:" > ./.rtorrent.rc
Éditer la config :
.. code-block:: bash
## On modifie les chemins
method.insert = cfg.basedir, private|const|string, (cat,"/data/rtorrent/")
method.insert = cfg.watch, private|const|string, (cat,(cfg.basedir),"torrent/")
...
## Commenter les lignes suivantes
#execute.throw = sh, -c, (cat,\
# "mkdir -p \"",(cfg.download),"\" ",\
# "\"",(cfg.logs),"\" ",\
# "\"",(cfg.session),"\" ",\
# "\"",(cfg.watch),"/load\" ",\
# "\"",(cfg.watch),"/start\" ")
...
## Maxer l'utilisation de la ram
pieces.memory.max.set = 1000M
...
## Loguer les connexions RPC
log.xmlrpc = (cat, (cfg.logs), "xmlrpc.log")
...
## Umask pour du 755/644
system.umask.set = 0022
...
## On démarre le téléchargement pour tout les torrents déposés dans le dossier
## Add torrent
#schedule2 = watch_load, 11, 10, ((load.verbose, (cat, (cfg.watch), "*.torrent")))
## Add & download straight away
schedule2 = watch_start, 10, 10, ((load.start_verbose, (cat, (cfg.watch), "*.torrent")))
...
## On lance le socket unix pour la communication avec ruTorrent, en 777 pour qu apache puisse s'y connecter
#system.daemon.set = true
network.scgi.open_local = (cat,(session.path),rpc.socket)
execute.nothrow = chmod,777,(cat,(session.path),rpc.socket)
Créer les répertoires :
.. code-block:: bash
mkdir {download,log,.session,torrent}
Ajouter un utilisateur rtorrent :
.. code-block:: bash
adduser --disabled-login --disabled-password --home /data/rtorrent/ --system rtorrent
Affecter les bons droits :
.. code-block:: bash
chown -R rtorrent:www-data /data/rtorrent/
Lancer rtorrent pour tester la config :
.. code-block:: bash
sudo -u rtorrent rtorrent
Configuration d'apache
----------------------
On créer le vhost ``/etc/apache2/sites-available/rutorrent.conf`` :
.. code-block:: Apacheconf
<VirtualHost 192.168.1.100:8083>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
On ouvre le port dans ``/etc/apache2/ports.conf`` :
.. code-block:: Apacheconf
Listen 8083
On charge la configuration et on redémarre apache :
.. code-block:: bash
a2ensite rutorrent.conf
systemctl restart apache2
Installation de ruTorrent
-------------------------
On trouve la dernière version stable `ici <https://github.com/Novik/ruTorrent/releases>`_ :
.. code-block:: bash
cd /var/wwww
wget https://github.com/Novik/ruTorrent/archive/v3.10.zip
unzip v3.10.zip
mv ruTorrent-3.10/ html
rm v3.10.zip
chown -R www-data:www-data html
On modifie la configuration de rutorrent : ``conf/config.php`` :
.. code-block:: bash
// On commente le chemin socket ip, et on file le soket unix
//$scgi_port = 5000;
//$scgi_host = "127.0.0.1";
// For web->rtorrent link through unix domain socket
// (scgi_local in rtorrent conf file), change variables
// above to something like this:
//
$scgi_port = 0;
$scgi_host = "unix:///data/rtorrnet/.session/rpc.socket";
Améliorations
-------------
Si on veut mettre des limites de connection, on rajoute au ``.rtorrent.rc`` :
.. code-block:: bash
# Global upload and download rate in KiB.
# "0" for unlimited
throttle.global_down.max_rate.set_kb = 1000
throttle.global_up.max_rate.set_kb = 1000
Si on veut que rtorrent arrête le téléchargement en cas d'espace disque faible :
.. code-block:: bash
# Close torrents when disk-space is low.
schedule2 = low_diskspace,5,60,close_low_diskspace=5000M
Si on veut que le plugin mediainfo fonctionne :
.. code-block:: bash
apt install mediainfo
Si on veut que le plugin spectrogram fonctionne :
.. code-block:: bash
aptitude install sox
Si on veut que le pluggin unpack marche :
.. code-block:: bash
apt install unrar
Pour optimiser les downloads avec peu de seed :
.. code-block:: bash
## Tracker-less torrent and UDP tracker support
## (conservative settings for 'private' trackers, change for 'public')
dht.mode.set = on
# port for DTH (default 6881)
#dht.port.set = 6881
# Use peer exchange
protocol.pex.set = yes
# DTH use udp by default
trackers.use_udp.set = yes
Pour avoir le pays des peers, il faut installer GeoIP :
.. code-block:: bash
apt install php-geoip geoip-database
systemctl restart apache2.service
systemctl restart php7.3-fpm.service
Iptables
--------
On Ajoute les règles suivantes dans notre firewall :
.. code-block:: bash
ip6tables -A INPUT -i enp1s0 -p tcp --dport 50000 -j ACCEPT
ip6tables -A INPUT -i enp1s0 -p udp --dport 6881 -j ACCEPT
iptables -A INPUT -i enp1s0 -p tcp --dport 50000 -j ACCEPT
iptables -A INPUT -i enp1s0 -p udp --dport 6881 -j ACCEPT
Script de gestion
-----------------
Si on ne veut pas que rtorrent se lance automatiquement au démarrage via systemd,
on peut faire un script tout simple qui démarre rtorrent en mode daemon
et configure les règles iptables.
.. important:: Pour cela, il faut d'abord aller dans ``/data/rtorrent/.rtorrent.rc`` et modifier le paramètre : ``system.daemon.set = true``
Voici le script qui permet de démarrer ou arrêter rtorrent.
.. warning:: Attention, rtorrent met du temps à s'arrêter, il à beaucoup de connections à fermer.
.. code-block:: bash
#!/bin/bash
function start {
ps -elf | grep /usr/bin/rtorrent | grep -v "sudo\|grep"
if (( $? == 0 )); then
printf "rtorrent alerady started\n"
exit 1
fi
printf "starting rtorrent...\n"
sudo -u rtorrent nohup /usr/bin/rtorrent &
ip6tables -A INPUT -i enp1s0 -p tcp --dport 50000 -j ACCEPT
ip6tables -A INPUT -i enp1s0 -p udp --dport 6881 -j ACCEPT
iptables -A INPUT -i enp1s0 -p tcp --dport 50000 -j ACCEPT
iptables -A INPUT -i enp1s0 -p udp --dport 6881 -j ACCEPT
}
function stop {
ps -elf | grep /usr/bin/rtorrent | grep -v "sudo\|grep"
if (( $? == 1 )); then
printf "rtorrent alerady stoped\n"
exit 1
fi
printf "stoping rtorrent...\n"
kill $(cat /data/rtorrent/.session/rtorrent.pid)
ip6tables -D INPUT -i enp1s0 -p tcp --dport 50000 -j ACCEPT
ip6tables -D INPUT -i enp1s0 -p udp --dport 6881 -j ACCEPT
iptables -D INPUT -i enp1s0 -p tcp --dport 50000 -j ACCEPT
iptables -D INPUT -i enp1s0 -p udp --dport 6881 -j ACCEPT
}
function usage {
cat <<EOF
rtorrent.sh
start or stop rtorrent
-h --help : Print this help
-s --start : Start rtorrent
--stop : Stop rtorrent
EOF
exit 0
}
##################
# MAIN
##################
if [[ -z $1 ]]; then
usage
exit 1
fi
options=$(getopt -o sh -l start,stop,help -- "$@")
if [ $? != 0 ]
then
usage
exit 1
fi
eval set -- "$options"
while true; do
case "$1" in
-s|--start)
start
break
;;
--stop)
stop
break
;;
-h|--help)
usage
;;
*)
usage
shift
break
;;
esac
shift
done
exit 0;