diff --git a/README.md b/README.md index 90fd923..01f9de8 100644 --- a/README.md +++ b/README.md @@ -98,10 +98,9 @@ tmpfs /var/log/nginx tmpfs rw,user 0 0 As time syncronisation is important, you should configure ntp servers in `/etc/systemd/timesyncd.conf` and make them match with the entries in `/etc/rc.local` iptables configuration -To create all required tor and php instances run the following commands: +Enable the PHP-FPM default instance: ``` -for instance in a b c d e f g h i j k l m n o p q r s; do(tor-instance-create $instance) done -for instance in default a b c d e f g h i j k l m n o p q r s; do(systemctl enable php7.3-fpm@$instance;) done +systemctl enable php7.3-fpm@default ``` Edit `/etc/fstab` and add the `usrjquota=aquota.user,jqfmt=vfsv1` option to the /home mountpoint. Then initialize quota: diff --git a/var/www/setup.php b/var/www/setup.php index 1c923f3..b8bf96c 100644 --- a/var/www/setup.php +++ b/var/www/setup.php @@ -281,10 +281,28 @@ file_put_contents('/etc/nginx/streams-enabled/default', "server { proxy_pass unix:/var/run/mysqld/mysqld.sock; }"); exec('systemctl reload nginx'); -$stmt=$db->prepare('INSERT IGNORE INTO service_instances (id) VALUES (?);'); -foreach(SERVICE_INSTANCES as $key){ - $stmt->execute([$key]); +// add new php/tor instances if not yet existing +$check=$db->prepare('SELECT null FROM service_instances WHERE id = ?;'); +$stmt=$db->prepare('INSERT INTO service_instances (id) VALUES (?);'); +foreach(SERVICE_INSTANCES as $instance){ + $check->execute([$instance]); + if(!$check->fetch()){ + exec('useradd -d '.escapeshellarg("/var/lib/tor-instances/$instance").' -r -s /bin/false -M -U '.escapeshellarg("_tor-$instance")); + exec('install -Z -d -m 02700 -o '.escapeshellarg("_tor-$instance").' -g '.escapeshellarg("_tor-$instance").' '.escapeshellarg("/var/lib/tor-instances/$instance")); + exec('install -d '.escapeshellarg("/etc/tor/instances/$instance")); + rewrite_torrc($db, $instance); + exec("systemctl enable ".escapeshellarg("tor@$instance")); + exec("systemctl start ".escapeshellarg("tor@$instance")); + foreach(PHP_VERSIONS as $version){ + rewrite_php_config($db, $instance); + exec("systemctl enable ".escapeshellarg("php$version-fpm@$instance")); + exec("systemctl start ".escapeshellarg("php$version-fpm@$instance")); + } + $stmt->execute([$instance]); + echo "Successfully added new instance $instance. Don't forget to add _tor-$instance as allowed user to your firewall rules in /etc/rc.local"; + } } +// remove no longer enabled php/tor instances $stmt=$db->query('SELECT id FROM service_instances;'); $update_users=$db->prepare('UPDATE users SET instance = (SELECT id FROM service_instances WHERE id !=? ORDER BY RAND() limit 1) WHERE instance=?;'); $update_onions=$db->prepare('UPDATE onions SET instance = (SELECT id FROM service_instances WHERE id !=? ORDER BY RAND() limit 1) WHERE instance=?;');