Install on Synology NAS

isotopicgas
Posts: 1
Joined: 28 Dec 16 21:23

Install on Synology NAS

Postby isotopicgas » 29 Dec 16 9:08

For anyone who wants to run PhotoSupreme on a Synology NAS _without_ installing another version of Postgresql, these instructions should help. I did this on a NAS running DSM 5.2. Much of the information here is based on a couple of other threads in this forum which I found really helpful. So thank you to the giants shoulders I have been able to stand on to get this working.

Initially we do all the configuration on the standard postgresql port of 5432 as photosupreme doesn't seem to like configuring things when on the non-default port. Once the database and its tables have been created by photosupreme, we change the port.

Before attempting these instructions, make sure you can login over ssh to your Synology NAS and that you know the location you wish to store the new database cluster. You also need to be able to edit files using vi or another text file editor available from the command line. Also note, using these instructions you can create multiple independent database catalogues on the same NAS - just use additional port numbers.

Note: Lines beginning with "-->" below are actual commands either for the NAS command line or in psql. Also that the instructions include information on checking certain things and the output, so it looks like a longer process of steps than it is in reality. I've used "code" entries for those outputs to make them easier to distinguish.

Login to your NAS over SSH as the root user.
Change the directory to the location you wish to create the database cluster in.
--> cd /volume1/@database
Create a folder called "photosup" - or whatever name you wish (but if you change this, make sure you use the same name in the rest of the instructions below!)
--> mkdir photosup
Change the owner and group on the folder to postgres
--> chown postgres.postgres photosup
Change the read/write permissions on the folder
--> chmod 700 photosup

Duplicate the Synology pgsql.conf startup script:
--> cp /etc/init/pgsql.conf /etc/init/photosup.conf
--> chmod 700 /etc/init/photosup.conf
Edit the startup script:
--> vi /etc/init/photosup.conf
Change the description to "start photosup"
Change the database folder from /var/services/pgsql to the correct database folder - /volume1/@database/photosup
Save the changes

Switch from the root user to the postgres user:
--> su - postgres
Create the new database cluster:
--> initdb -D /volume1/@database/photosup -T english --encoding=utf8
(generates some errors about not being able to read from some files, but does work!)

Edit the new postgresql.conf:
--> cd /volume1/@database/photosup
--> vi postgresql.conf
Modify the following (as per advice for photosupreme)
listen_addresses = '*'
shared_buffers = 1024Mb (25% of NAS memory)
effective_cache_size = 2048Mb (50% of NAS memory)
Save the changes

Edit the new pg_hba.conf
--> cd /volume1/@database/photosup
--> vi pg_hba.conf
Add the following line to the bottom of the file.
host all postgres,photosupreme,admin,idimager_main samenet md5
Save the changes

Return to the root login from postgres login:
--> exit
Check you are root
--> id
(Should show your id as root)

Stop the default database (to temporarily free up port 5432):
--> synoservicectl --status pgsql
--> synoservicectl --stop pgsql
--> synoservicectl --status pgsql

Start the new database cluster:
--> synoservicectl --start photosup
--> synoservicectl --status photosup

Login to the new cluster and configure it:
--> su - postgres
--> psql
--> CREATE ROLE photosupreme SUPERUSER CREATEDB CREATEROLE LOGIN PASSWORD 'photosupreme';
--> \q

--> psql -U photosupreme postgres
--> \dF

Code: Select all

 List of text search configurations
   Schema   |  Name  |     Description
------------+--------+----------------------
 pg_catalog | simple | simple configuration
(1 row)


--> CREATE TEXT SEARCH CONFIGURATION pg_catalog.english (COPY = pg_catalog.simple);

==> \dF

Code: Select all

     List of text search configurations
   Schema   |  Name   |     Description
------------+---------+----------------------
 pg_catalog | english |
 pg_catalog | simple  | simple configuration
(2 rows)

--> \q
--> exit

Open the Synology interface in your browser on your computer and configure the firewall to allow connections for ports 5432 and 5433.
Login to the Synology interface and go to ...
Control Panel ... Security ... Firewall
Create ...
Ports (Custom) ... Destination port, tcp, from 5432 to 5433 [ok]
Source IP (Specific) ... Subnet 192.168.1.0 Mask 255.255.255.0 (Note your subnet and mask may be different to this)
Action: Allow
Save

If you want to check if the firewall is showing the right ports, you can do so as follows:
Login as root over ssh into your NAS box.
--> iptables -L -n |grep 543

Code: Select all

    ACCEPT     tcp  --  192.168.1.0/24       0.0.0.0/0            multiport dports 5432:5433
    ACCEPT     tcp  --  192.168.1.0/24       0.0.0.0/0            multiport dports 5432:5433

(note your subnet range will probably be different)

Now install and run photosupreme on your laptop (for the first time)
When prompted: Enter the IP address of your NAS, and port 5432
Username and password is 'photosupreme' 'photosupreme'
The photosupreme database tables should now be created.

If get an error about 'english'. Select to Cancel.

Correct this as follows:
Login as root on the NAS
--> su - postgres -c 'psql -p5432 photosupreme photosupreme'
--> \dF

Code: Select all

     List of text search configurations
   Schema   |  Name   |     Description
------------+---------+----------------------
 pg_catalog | simple  | simple configuration
(1 row)


--> CREATE TEXT SEARCH CONFIGURATION pg_catalog.english (COPY = pg_catalog.simple);
--> \dF

Code: Select all

     List of text search configurations
   Schema   |  Name   |     Description
------------+---------+----------------------
 pg_catalog | english |
 pg_catalog | simple  | simple configuration
(2 rows)


--> \q

Try connecting to the new cluster and see if it creates the new data tables with the 'english' error this time.

Once the database tables have been created close down photosupreme wait ten seconds and then restart it
Try connecting to the database again. This time using the "normal" credentials.
Server name: IP Address and Port 5432
Database: photosupreme
User name: admin and password you were given when the database was created by photosupreme.

If all is well you should see the main photosupreme screen.

BUT WAIT - there is something else to do which is vitally important for the health of your NAS ...

Close photosupreme down on your computer.
Login to your NAS over ssh as root user.

Stop the photosupreme database cluster:
--> synoservicectl --stop photosup
Edit its postgresql.conf
--> vi /volume1/@database/photosup/postgresql.conf
Change the port to 5433 from 5432 (and uncomment the line!)
Save the change
Restart the photosupreme database cluster:
--> synoservicectl --start photosup
Now start the normal postgresql service (this is the important thing for the NAS health!)
--> synoservicectl --status pgsql
--> synoservicectl --start pgsql
Check if both running ...
--> netstat -plant | grep 543

Code: Select all

tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      10141/postgres
tcp        0      0 127.0.0.1:5433          0.0.0.0:*               LISTEN      10170/postgres


Now Run photosupreme on your computer.
When prompted: Enter the IP address of your NAS, and port 5433 [The new port]
Database: photosupreme
User name: admin and password you were given when the database was created by photosupreme.

You should connect ok to the database and be able to use photosupreme.

I have not yet looked at backing up the database, but that is another story!

Hope this helps someone, somewhere as it worked for me.

Return to “Photo Supreme”