You are not logged in.
I've coded a script that checks if a /dev file is present, and possibly mounts it.
Done this way because I've tried other automount possibilities with no success, and the only solution that
worked fine to mount my Android smartphone was the command "go-mtpfs".
Since I wanted this to be automatized, created a timer unit for systemd that every 5 seconds runs the script.
This fails the mounting, but I've checked that:
- the timer unit actually runs the script
- when runned by hand, it performs the mount
What could prevent it from working? I wonder if it's a similar problem to the fact that mount commands can't be
run directly from udev rules.
Last edited by edriv (2017-09-02 18:09:14)
Offline
Paste the script, the service file and timer, and the relevant journal output.
See How To Ask Questions The Smart Way.
Moving to NC...
Offline
The script: ~/.android_automounter.sh
#!/bin/sh
#udev creates this file when my device is connected
ANDROID_DEVFILE=/dev/android_adb
#lock variable to avoid mounting multiple times
IPC_VARIABLE=/tmp/android_ismounted
if [ -e $ANDROID_DEVFILE ]
then
echo "FILE FOUND"
if [ -e $IPC_VARIABLE ]
then
ANDROID_MOUNTED=`cat $IPC_VARIABLE`
else
ANDROID_MOUNTED=0
echo "0" > $IPC_VARIABLE
fi
if [ $ANDROID_MOUNTED -eq 0 ]
then
echo "MOUNTING"
go-mtpfs /mnt/android &
echo "1" > $IPC_VARIABLE
fi
else
echo "FILE NOT FOUND"
if [ -e $IPC_VARIABLE ]
then
ANDROID_MOUNTED=`cat $IPC_VARIABLE`
else
ANDROID_MOUNTED=0
echo "0" > $IPC_VARIABLE
fi
if [ $ANDROID_MOUNTED -eq 1 ]
then
fusermount -u /mnt/android
echo "0" > $IPC_VARIABLE
fi
fiThe units:
/etc/systemd/user/android.timer
[Unit]
Description=Checks and optionally mounts a virtual fs
[Timer]
OnBootSec=1min
OnUnitActiveSec=5
[Install]
WantedBy=timers.target/etc/systemd/user/android.service
[Unit]
Description=Mounts a specific device
[Service]
ExecStart=~/.android_automounter.shSome tests:
[elda@PCCASA ~]$ echo 0 > /tmp/android_ismounted
(after 10 secs)
[elda@PCCASA ~]$ cat /tmp/android_ismounted
1
[elda@PCCASA ~]$ ls /mnt/android
[elda@PCCASA ~]$
[elda@PCCASA ~]$ echo 0 > /tmp/android_ismounted
(before 5 secs)
[elda@PCCASA ~]$ sh .android_automounter.sh
FILE FOUND
MOUNTING
[elda@PCCASA ~]$ 2017/09/01 12:45:48 FUSE mountedI explain the first two commands as testing if the script has been run; "ls" gives that the device
has not actually been mounted, in the following commands I manually run the script with success.
Offline
What happens if you use the 'Type=forking' for android.service ?
I have doubts about the 'go-mtpfs /mnt/android &' line in the script: do you know why go-mtpfs is run in background?
Offline
ExecStart=~/.android_automounter.shThere is no such file as ~/.android_automounter.sh
There are (at least) 2 reasons this fails: 1) ExecStart needs a file to Exec when it Starts. The tilde is not an actual path, it is a feature of the shell, but you are not telling systemd to run a shell, so there is nothing to expand that tilde into your home directory. 2) even if you did tell systemd to run a shell, the tilde would not be expanded to your home directory, but rather to /root/ as systemd services run as root.
Use the full path to the script.
I'd not be surprised if there are yet other problems. Mounting from within a script launched by systemd may or may not work at all as all subprocesses end up killed and cleaned up after. But at very least, fixing the 2 above will allow you to find out.
Last edited by Trilby (2017-09-01 15:14:13)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
What happens if you use the 'Type=forking' for android.service ?
I have doubts about the 'go-mtpfs /mnt/android &' line in the script: do you know why go-mtpfs is run in background?
With this adjustment it works fine.
@Tribly: you're right, but actually I had edited the code to hide my computer's username without having this in mind.
Offline