danb35 / freenas-iocage-nextcloud

Script to create an iocage jail on FreeNAS for the latest Nextcloud 28 release, including Caddy, MariaDB or PostgreSQL, and Let's Encrypt
GNU General Public License v3.0
250 stars 71 forks source link

[Suggestion] Add section on rebuilding/reinstalling (done?) #191

Open Aephir opened 2 years ago

Aephir commented 2 years ago

I've tried adding a part about "reinstalling" for the README.md, but please let me know if I'm missing something.

I'm not sure if I need to do anything with the database passwords I've saved, or just keep them in case I need to manually edit the databases? Feel free to add a sentence on that.

### Rebulding jail
You might want to rebuild the jail in case you want to upgrade packages, or something is wrong. This script makes this process extremely easy.

To do so, make sure you save:
* Your database passwords (created during the first install, and found in your `nextcloud.log` produced by the install script. Located in the `freenas-iocage-nextcloud` directory (wherever you first `git clone`d this to). The "nextcloud" user is also found in your config.php (but the admin password is not!).
* Your `nextcloud-config` that you created for the first install (assuming you need the same parameters), which is also located in the `freenas-iocage-nextcloud` directory.
* Your Nextcloud `config.php` (located inside the jail in `/usr/local/www/nextcloud/config`), although if you set this up the first time so this is on a different dataset, it should just load automatically after the rebuild.

NOTE: If you have upgraded Nextcloud beyong what this script installs, it might not work. But you can try just adding the version, e.g. (for NExtcloud 24) `NEXTCLOUD_VERSION="24"` to the `nextcloud-config`.

To rebuild:

* Delete jail from TrueNAS UI (OBS! For peace of mind, you can instead stop it, disable autostart, and rename the jail. Then only delete once the new jail is working).
* Delete your `freenas-iocage-nextcloud` directory and do a new `git clone https://github.com/danb35/freenas-iocage-nextcloud` to ensure you have the newest version.
* Follow the [initial install instructions from here](#Installation)
  * Remember to copy in your old `nextcloud-config` if needed.

With the above, everything should be as before the re-install. The only thing you won't get again, should not have saved during the first install, is your database admin password.
deneb84 commented 1 year ago

I tried a reinstall today. The only thing I did differently from your approach is that I didn't remove the old jail but I simply renamed it, the idea was to delete it after. Renaming the jail make the roll back simpler, but I could achieve the same with snapshots. I would add take snapshots before deleting the jail at least.

Feedback for the script owner: when reinstalling I saw the script was taking a long time to

+ mkdir -p /mnt/mydisk/apps/nextcloud/files
+ chown -R 80:80 /mnt/mydisk/apps/nextcloud/files

Not sure if this step is needed during reinstall

Finally I am not sure how robust is this script for reinstallation. After the script finished I went to my domain and I got:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

Looking at the installation log I found

+ iocage exec nextcloud su -m www -c 'php -f /usr/local/www/nextcloud/cron.php'
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory in /usr/local/www/nextcloud/lib/private/DB/Connection.php:142
Stack trace:
#0 /usr/local/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1531): OC\DB\Connection->connect()
#1 /usr/local/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1029): Doctrine\DBAL\Connection->getWrappedConnection()
#2 /usr/local/www/nextcloud/lib/private/DB/Connection.php(264): Doctrine\DBAL\Connection->executeQuery('SELECT * FROM `...', Array, Array, NULL)
#3 /usr/local/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\DB\Connection->executeQuery('SELECT * FROM `...', Array, Array)
#4 /usr/local/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(280): Doctrine\DBAL\Query\QueryBuilder->execute()
#5 /usr/local/www/nextcloud/lib/private/AppConfig.php(417): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /usr/local/www/nextcloud/lib/private/AppConfig.php(183): OC\AppConfig->loadConfigValues()
#7 /usr/local/www/nextcloud/lib/private/AppConfig.php(373): OC\AppConfig->getApps()
#8 /usr/local/www/nextcloud/lib/private/legacy/OC_App.php(976): OC\AppConfig->getValues(false, 'installed_versi...')
#9 /usr/local/www/nextcloud/lib/private/Server.php(729): OC_App::getAppVersions()
#10 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(171): OC\Server->OC\{closure}(Object(OC\Server))
#11 /usr/local/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#12 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(138): Pimple\Container->offsetGet('OC\\Memcache\\Fac...')
#13 /usr/local/www/nextcloud/lib/private/ServerContainer.php(171): OC\AppFramework\Utility\SimpleContainer->query('OC\\Memcache\\Fac...', true)
#14 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(65): OC\ServerContainer->query('OC\\Memcache\\Fac...')
#15 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(193): OC\AppFramework\Utility\SimpleContainer->get('OC\\Memcache\\Fac...')
#16 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(171): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(OC\Server))
#17 /usr/local/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#18 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(138): Pimple\Container->offsetGet('OCP\\ICacheFacto...')
#19 /usr/local/www/nextcloud/lib/private/ServerContainer.php(171): OC\AppFramework\Utility\SimpleContainer->query('OCP\\ICacheFacto...', true)
#20 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(65): OC\ServerContainer->query('OCP\\ICacheFacto...')
#21 /usr/local/www/nextcloud/lib/private/Server.php(1108): OC\AppFramework\Utility\SimpleContainer->get('OCP\\ICacheFacto...')
#22 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(171): OC\Server->OC\{closure}(Object(OC\Server))
#23 /usr/local/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#24 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(138): Pimple\Container->offsetGet('OCP\\Lock\\ILocki...')
#25 /usr/local/www/nextcloud/lib/private/ServerContainer.php(171): OC\AppFramework\Utility\SimpleContainer->query('OCP\\Lock\\ILocki...', true)
#26 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(65): OC\ServerContainer->query('OCP\\Lock\\ILocki...')
#27 /usr/local/www/nextcloud/lib/private/Server.php(2063): OC\AppFramework\Utility\SimpleContainer->get('OCP\\Lock\\ILocki...')
#28 /usr/local/www/nextcloud/lib/private/Files/View.php(119): OC\Server->getLockingProvider()
#29 /usr/local/www/nextcloud/lib/private/Server.php(464): OC\Files\View->__construct()
#30 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(171): OC\Server->OC\{closure}(Object(OC\Server))
#31 /usr/local/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#32 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(138): Pimple\Container->offsetGet('OC\\Files\\Node\\H...')
#33 /usr/local/www/nextcloud/lib/private/ServerContainer.php(171): OC\AppFramework\Utility\SimpleContainer->query('OC\\Files\\Node\\H...', true)
#34 /usr/local/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(65): OC\ServerContainer->query('OC\\Files\\Node\\H...')
#35 /usr/local/www/nextcloud/lib/private/Server.php(1465): OC\AppFramework\Utility\SimpleContainer->get('OC\\Files\\Node\\H...')
#36 /usr/local/www/nextcloud/lib/base.php(623): OC\Server->boot()
#37 /usr/local/www/nextcloud/lib/base.php(1164): OC::init()
#38 /usr/local/www/nextcloud/cron.php(43): require_once('/usr/local/www/...')
#39 {main}
Command: su -m www -c php -f /usr/local/www/nextcloud/cron.php failed!

It seems mysql is not running

# ps aux
USER    PID %CPU %MEM    VSZ   RSS TT  STAT STARTED    TIME COMMAND
root  41357  0.0  0.0  12896  2816  -  SsJ  13:22   0:00.00 /usr/sbin/syslogd -c -ss
redis 41413  0.0  0.1  34756  9640  -  SsJ  13:22   0:00.13 redis-server: /usr/local/bin/redis-server unixsocket:/var/run/redis/redis.sock (redis-server)
root  41417  0.0  0.3 260880 48984  -  SsJ  13:22   0:00.01 php-fpm: master process (/usr/local/etc/php-fpm.conf) (php-fpm)
www   41418  0.0  0.3 264016 58040  -  IJ   13:22   0:00.09 php-fpm: pool www (php-fpm)
www   41419  0.0  0.3 260880 49012  -  IJ   13:22   0:00.00 php-fpm: pool www (php-fpm)
root  41438  0.0  0.3 751640 49904  -  SJ   13:22   0:00.05 /usr/local/bin/caddy run --pingback 127.0.0.1:18908 --config /usr/local/www/Caddyfile --adapter caddyfile --pidfile /var/run/caddy/caddy.pid
root  41453  0.0  0.0  12940  2540  -  IsJ  13:22   0:00.00 /usr/sbin/cron -J 15 -s
root  41535  0.0  0.0  13676  3400  0  SJ   13:24   0:00.02 /bin/sh
root  41597  0.0  0.0  13552  3076  0  R+J  13:27   0:00.00 ps aux

what I tried after was:

# service mysql-server start
Please merge existing /var/db/mysql/my.cnf file with /usr/local/etc/mysql/conf.d/server.cnf
/usr/local/etc/rc.d/mysql-server: WARNING: failed precmd routine for mysql

# mv /var/db/mysql/my.cnfcat /var/db/mysql/my.cnf.bk

I merged /var/db/mysql/my.cnf.bk in /usr/local/etc/mysql/conf.d/server.cnf and then

# service mysql-server start
Starting mysql.
# service mysql-server status
mysql is not running.

So it didn't work at the end. And just as a final note: trying to start mysql on the new jail changes something on the db data, and I had to rollback the db data as well to be able to make the old jail work again

I think the problem is that I am on mariadb103-server-10.3.27 now while the script is using mariadb106. And that require a bit of work. Like what I jsut read on this comment

deneb84 commented 1 year ago

I retried modifying the script to install mariadb103 and it worked, so we need to at least be sure that the documentation takes these kind of problems into the account.