Cannot write to content dirs('events','images')...

Forum for questions and support relating to the 1.30.x releases only.
Locked
atmarx
Posts: 3
Joined: Wed Apr 18, 2018 4:20 pm

Cannot write to content dirs('events','images')...

Post by atmarx »

Howdy -- first time installing ZoneMinder, so please pardon my ignorance of any errata. I've searched through the forums, and have done everything I can see to do. This is on CentOS 7, up to date, running 1.30.4 straight from RPMFusion.

The server as initially set up works fine. When I try to then mount a storage drive (20TB, formatted ext4), I mount it via fstab as:
/dev/sdb1 /mnt/camera ext4 defaults 0 2
/mnt/camera/zm/events /var/lib/zoneminder/events none defaults,bind 0 2
/mnt/camera/zm/images /var/lib/zoneminder/images none defaults,bind 0 2

ls -la /mnt/camera shows
drwxr-xr-x. 4 apache apache 4096 Apr 18 12:16 zm

and within zm,
drwxr-xr-x. 2 apache apache 4096 Apr 18 12:16 events
drwxr-xr-x. 2 apache apache 4096 Apr 18 12:16 images

If I remove the mounts and let ZM go straight to the original locations, everything works fine. It's only when I include he mounts that the log goes red and these flood in. I've stopped and started zoneminder appropriately before and after making changes.

In the logs, I'm also seeing:
[timestamp] zma_m1 12678 FAT Can't symlink '1' to 'Server Room Entrance': Permission denied zm_monitor.cpp 495
[timestamp] zma_m1 12750 ERR Can't make events/1: Permission denied zm_monitor.cpp 488

Any ideas? AFAICT, I've followed the steps laid out in README.Redhat7 and on the web, and if I remove the storage, all works fine.
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Cannot write to content dirs('events','images')...

Post by rockedge »

permissions on the mounted drive and the "events" folder for example, need to be for the Apache user.....are these in correct on your installation?
atmarx
Posts: 3
Joined: Wed Apr 18, 2018 4:20 pm

Re: Cannot write to content dirs('events','images')...

Post by atmarx »

/dev/sdb1 is mounted to /mnt/camera
within that is a folder called zm with events and images in that. I set perms via
chown -R apache:apache zm

ls -la /mnt/camera gives
drwxr-xr-x. 4 root root 4096 Apr 18 12:16 .
drwxr-xr-x. 3 root root 20 Apr 18 11:22 ..
drwx------. 2 root root 16384 Apr 18 12:12 lost+found
drwxr-xr-x. 4 apache apache 4096 Apr 18 12:16 zm

ls -la /var/lib/zoneminder/ gives
drwxr-xr-x. 7 apache apache 70 Apr 18 12:17 .
drwxr-xr-x. 31 root root 4096 Apr 18 11:06 ..
drwxr-xr-x. 2 apache apache 4096 Apr 18 12:16 events
drwxr-xr-x. 2 apache apache 4096 Apr 18 12:16 images
drwxr-xr-x. 2 apache apache 23 Apr 18 12:28 sock
drwxr-xr-x. 2 apache apache 6 Jul 25 2017 swap
drwxr-xr-x. 2 apache apache 6 Jul 25 2017 temp
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Cannot write to content dirs('events','images')...

Post by rockedge »

can you try to have the events directory named like the default? same directory structure...only on the mounted drive? What if you renamed the directory from "zm" to "zoneminder" on the mounted drive?
bbunge
Posts: 2930
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Cannot write to content dirs('events','images')...

Post by bbunge »

Search around for the procedure to mount an external drive with systemd. There is a procedure for Ubuntu but I don't remember where the one for Centos is located. Will solve a lot of your problems!
bbunge
Posts: 2930
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Cannot write to content dirs('events','images')...

Post by bbunge »

Here is the one written for Centos which I used to develop the Ubuntu procedure:



Collect Information
We need to know the following before we get started:

Find the ZoneMinder events and images folders on your filesystem
Determine the name of the web account user
For local volumes, determine the device name of the volume
For local volumes, determine the uuid of the volume
For remote volumes, determine the sharing protocol to be used e.g. nfs, smb, etc
For remote volumes, determine the share name


The location of the events and images folder will vary by Linux distro. You are looking for an actual folder, NOT a symlink! Redhat distros tend to put these folders under /var/lib/zoneminder while Debian distros prefer /var/cache/zoneminder. These folder locations are chosen by each distros' packaging guidelines.

On most Linux distros, you can view the uuid of each of your volumes like so:

ls -l /dev/disk/by-uuid

On my system, the items above are as follows:

/var/lib/zoneminder
apache
/dev/zm
6028c127-5d99-4860-981f-2984b4c10fd9

Your configuration will be different.

Migrate existing data
I'm not going to get into the details of this since the necessary steps will vary with each system. What you need to do is migrate whatever happens to be in the ZoneMinder events and images folders over to the new partition, disk, or network share. You do this by mounting the target from the command line via the normal fashion to a temporary folder, issue the appropriate move commands, and finally unmount the target.

Do that now.

Create the first Systemd Mount Unit
You will be creating a total of three mount units. The first mount unit mounts the drive or partition to your system. To do that create a new folder. I prefer to put mount points under /mnt and give the name of the subfolder the same name as the device or share. In my case, that would be zm.

sudo mkdir /mnt/zm

When creating mount units with systemd, the filename describing the mount point has to be named in a specific manner.

Since the folder I just created is at /mnt/zm, one has to name the mount unit mnt-zm.mount.
Create that file in the /etc/systemd/system folder, then add the following contents, changing the path and uuid to match that of your system:

mkdir /etc/systemd/system/mnt-zm.mount

mount -t cifs -o username=zm,password=mko098,uid=33,gid=33 //192.168.50.4/zm /mnt/zm

nano /etc/systemd/system/mnt-zm.mount
# systemd mount unit for ZoneMinder event storage

[Unit]
Description=systemd mount unit for ZoneMinder event storage
Before=zoneminder

[Mount]
What=//192.168.50.4/zm
Where=/mnt/zm
Type=
Options=username=zm,password=mko098,uid=33,gid=33

[Install]
WantedBy=multi-user.target

Now enable and start the unit:

sudo systemctl enable mnt-zm.mount
sudo systemctl start mnt-zm.mount

Set Folder Permissions
We've created our primary mount point, but we aren't done yet. First, let's create some folders and set the correct permissions:

sudo su
mkdir -p /mnt/zm/zoneminder/events
mkdir -p /mnt/zm/zoneminder/images
not needed chmod -R www-data:www-data /mnt/zm/zoneminder
exit

Remember that, if you are not running a Redhat distro, the web user account might be named something other than apache on your system.

Create three Systemd Bind Mount Units
With the events and images folders created, we want to create two mount units, which bind mount those folders into the desired places.

Create the file /etc/systemd/system/var-cache-zoneminder-events.mount then add the following content to it:


# systemd bind mount unit for ZoneMinder event storage

[Unit]
Description=systemd bind mount unit for ZoneMinder event storage
After=mnt-zm.mount
Requires=mnt-zm.mount

[Mount]
What=/mnt/zm/zoneminder/events
Where=/var/cache/zoneminder/events
Type=none
Options=bind

[Install]
WantedBy=local-fs.target
Now enable and start the unit:

sudo systemctl enable var-cache-zoneminder-events.mount
sudo systemctl start var-cache-zoneminder-events.mount

We now need to do the same thing to the images folder. Create the file /etc/systemd/system/var-lib-zoneminder-images.mount then add the following content to it:


# systemd bind mount unit for ZoneMinder image storage

[Unit]
Description=systemd bind mount unit for ZoneMinder image storage
After=zm.mount
Requires=zm.mount

[Mount]
What=/mnt/zm/zoneminder/images
Where=/var/lib/zoneminder/images
Type=none
Options=bind

[Install]
WantedBy=local-fs.target
Now enable and start the unit:

sudo systemctl enable var-cache-zoneminder-images.mount
sudo systemctl start var-cache-zoneminder-images.mount

Create the file /etc/systemd/system/var-cache-zoneminder-temp.mount then add the following content to it:


# systemd bind mount unit for ZoneMinder event storage

[Unit]
Description=systemd bind mount unit for ZoneMinder event storage
After=mnt-zm.mount
Requires=mnt-zm.mount

[Mount]
What=/mnt/zm/zoneminder/temp
Where=/var/cache/zoneminder/temp
Type=none
Options=bind

[Install]
WantedBy=local-fs.target


Now enable and start the unit:

sudo systemctl enable var-cache-zoneminder-temp.mount
sudo systemctl start var-cache-zoneminder-temp.mount

Now reboot and verify all three mount points were successful:

df -a

That's it!

Bonus Points. Leverage the Power of Systemd
If you recall, I mentioned that using systemd to manage your mount points has an advantage over the previous method. With your mount points configured with systemd, you can easily prevent ZoneMinder from starting, should the mount point fail for any reason. Anyone who has ever started ZoneMinder without realizing there was a problem reading from the events folder can tell you what happens when this occurs. You lose all your events, and yes this is by design.

To prevent that from happening we need to modify our zoneminder service file. First, make a copy of it:

sudo cp /usr/lib/systemd/system/zoneminder.service /etc/systemd/system/

Then open the copy and add "Requires=mnt-zm.mount" under the [unit] block:
?
1
2
3
4
5
6
7
8

# ZoneMinder systemd unit file for CentOS 7

[Unit]
Description=ZoneMinder CCTV recording and security system
After=network.target mariadb.service httpd.service
After=zfs.target zfs-mount.service zfs-share.service
Requires=mariadb.service httpd.service
Requires=mnt-zm.mount
Now issue a daemon reload to tell systemd to pick up the change:

sudo systemctl deamon-reload

Should the mount point fail during startup, systemd will prevent the ZoneMinder service from starting with a message stating a failed dependency. Your events are saved from deletion!
atmarx
Posts: 3
Joined: Wed Apr 18, 2018 4:20 pm

Re: Cannot write to content dirs('events','images')...

Post by atmarx »

Son of a g... Perms were fine -- it was SELinux. I temporarily disabled it initially, but forgot to disable it permanently. Everything works fine until httpd tries to write to the mounted storage... As soon as I disabled it, it started working perfectly.

Thanks for the pointers -- I'll add those services in soon. Just wanted to make sure the system worked first.
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Cannot write to content dirs('events','images')...

Post by rockedge »

:D
Locked