Changes

From Amahi Wiki
Jump to: navigation, search
4,911 bytes added ,  07:37, 5 August 2013
Added description of an updated version of the script to allow apache to write to locally mounted shares to facilitate easier use for apps
{{Code|rm S-1*}}
 
== Updated script for Greyhole users ==
 
 
 
Some apps used by Amahi are used to download files etc. Often we want these files to end up in our shares. Let's say that SickBeard is used to download TV episodes. You then have to configure SickBeard to place your new episode somewhere. A logical place is to save to the landing zone of your Greyhole share which could be ''/var/hda/files/TV''. There are two downsides to this though.
 
* Greyhole is not notified of the fact that a file is added and only discovers it and makes it available in your share after a ''fsck''
* Files deleted through apps in this folder don't register a ''delete'' event that Greyhole can pick up and thus only the symlink in the landing zone is removed. The actual file copies remain in disc. Similarly users running Plex Media Server for example will have issues if the clients are allowed to ''delete contents'' and the server is configured to work on the landing zone. I described this issue when packaging Plex a long time ago here: https://wiki.amahi.org/index.php/Plex_Media_Server
 
 
Since Greyhole uses Samba as a layer between the user and itself we would like to keep our writes and deletes to the shares and not the actual landing zone. But since apps (most of them) run as the users ''apache'' it will not be able to access ''/mnt/samba'' which is the default mount point if you set up ''mount_shares_locally''. This following script retains the function of the original script but also adds a second mount point under ''/mnt/apache'' where the ''apache'' user will have read and write access. I have kept it simple and it will use the same credentials as the ''main'' mount. So only shares available to that user will ea available for apache.
 
By doing this apache will now have a place where it is allowed to read and write files to your shares and SickBeard can thus be configured to place the new episode in ''/mnt/apache/TV'' which is the instantly picked up by Greyhole and file copies distributed to the discs in your pool as configured.
 
Note that this script is based of the Greyhole original one and uses ''/etc/samba/smb.conf'' as the source of your shares and does not load the shares from the database like the old HDA version of the script did. If that behaviour is desired that can be easily added by replacing the lines
 
testparm -s /etc/samba/smb.conf 2>/dev/null | grep "^\[" | grep -v "\[global\]" | grep -v "\[homes\]" | awk -F'[' '{print $2}' | awk -F']' '{print $1}' | xargs -d "\n" mkdir -p
 
with
 
mysql -u root -phda -e "select comment from shares" hda_production | grep -v "^comment$" | xargs -d "\n" mkdir -p
 
 
 
### BEGIN INIT INFO
# Provides: mount_shares_locally
# Required-Start: $network $local_fs $remote_fs smb mysqld
# Required-Stop: $network $local_fs $remote_fs smb
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: mount Samba shares locally
### END INIT INFO
username="YOURUSERHERE"
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
fi
start () {
uid=`id -u $username`
gid=`id -g $username`
echo -n $"Mounting Samba shares locally: "
mkdir -p /mnt/samba/
mkdir -p /mnt/apache/
cd /mnt/apache/
testparm -s /etc/samba/smb.conf 2>/dev/null | grep "^\[" | grep -v "\[global\]" | grep -v "\[homes\]" | awk -F'[' '{print $2}' | awk -F']' '{print $1}' | xargs -d "\n" mkdir -p
cd /mnt/samba/
testparm -s /etc/samba/smb.conf 2>/dev/null | grep "^\[" | grep -v "\[global\]" | grep -v "\[homes\]" | awk -F'[' '{print $2}' | awk -F']' '{print $1}' | xargs -d "\n" mkdir -p
sleep 5
ls -1 | while read d; do
/sbin/mount.cifs "//127.0.0.1/$d" "$d" -o credentials=/home/${username}/.smb_credentials,uid=${uid},gid=${gid},file_mode=0660,dir_mode=0770,nobrl,hard,_netdev,iocharset=utf8,noserverino,mfsymlinks
/sbin/mount.cifs "//127.0.0.1/$d" "/mnt/apache/$d" -o credentials=/home/${username}/.smb_credentials,uid=`id -u apache`,gid=`id -g apache`,file_mode=0777,dir_mode=0777,nobrl,hard,_netdev,iocharset=utf8,noserverino,mfsymlinks
done
touch /var/lock/subsys/mount_shares_locally
success $"$base startup"
echo
return 0
}
stop () {
echo -n $"Unmounting locally mounted Samba shares: "
/bin/umount -l /mnt/samba/*
/bin/umount -l /mnt/apache/*
rm -f /var/lock/subsys/mount_shares_locally
success $"$base shutdown"
echo
return 0
}
restart () {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $?
24

edits