systemd script does not start at system start up

Asked by ealthuis on 2018-02-07

I am using NFS to provide files from the server to other computers.
The scrips involved are "autonfs.sh" and "nfs_automount.service"
On one system both work if I start nfs_automount.service manually, either as root or as user, but nfs_automount.service does not start automatically as on the other systems.

Can anybody come up with a reason?

I have looked at permissions, they are the same on both scripts, and it makes no difference if that is "root" or user, syntax errors and timing, none seem to be the problem.

I am stuck

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu libreoffice Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:

Can you please cat the files out and give their permissions and file locations.

Thanks

ealthuis (ealthuis) said : #2

The locations are above each file, The permissions for both files are root:root

 cat /lib/systemd/system/nfs_automount.service
[Unit]
Description=Automatically mount, unmount, and remount NFS shares
After=syslog.target
After=network.target

[Service]
Type=simple
Restart=on-failure
ExecStart=/usr/local/bin/autonfs.sh

[Install]
WantedBy=multi-user.target
ea@seanix:~$

ea@seanix:~$ cat /usr/local/bin/autonfs.sh
#!/bin/bash

# AutoNFS v.1.1
#
# 2010-09-02 Jeroen Hoek <email address hidden>:
# * Update script with helpful contributions from other users.
# * Stop using logger, simply echo and let the system log it in /var/log/upstart.
# 2012-07-23 Martin Seener:
# * Use rpcinfo instead of ping to check the status of the NFS server daemon, rather
# than just the server being up.
# * Add some useful mount options for a stable NFS mount.
# 2012-03-12 tobcro:
# * Allow local and remote mountpoint to be different.
# 2010-01-24 Jeroen Hoek <email address hidden>:
# * Initial script.

# Configuration parameters.

# The hostname or IP-address of the fileserver:
FILESERVER="192.168.0.103"

# Mount Options (see mount man pages for info).
MOUNTOPTS="-o rw,hard,intr,tcp,actimeo=3"

# Check every X seconds (60 is a good default):
INTERVAL=60

# Delimeter used for separating fileserver/client shares below:
DELIMETER="|"

# The shares that need to be mounted. If the local and remote mount point
# differ, write something like "/media/remoteshare|/media/localshare", where "|" is
# the delimeter configured above. If the mount points are the same, you can also use
# the short-hand "/media/share".
MOUNTS=( "/export/mass|/media/mass" "/export/mass1|/media/mass1" "/export/mass2|/media/mass2" )

# Logging. Set to true for debugging and testing; false when everything works. Logs
# are written to /var/log/upstart/autonfs.log.
LOG=false

# End of configuration

function log {
    if $LOG; then
        echo $1
    fi
}

log "Automatic NFS mount script started."

declare -a MOUNTP
while true; do
    # Is the NFS daemon responding?
    rpcinfo -t "$FILESERVER" nfs &>/dev/null
    if [ $? -eq 0 ]; then
        # Fileserver is up.
        log "Fileserver is up."
        for MOUNT in ${MOUNTS[@]}; do
            # Split up the share into the remote and local mount point.
            MOUNTP=(`echo ${MOUNT//$DELIMETER/ }`)
            # The second part of the mount string is the local mount point.
            # If there is no second part, local and remote are mounted on
            # the same location.
            HERE=${MOUNTP[${#MOUNTP[@]}-1]}
            THERE=${MOUNTP[0]}
            if grep -qsE "^([^ ])+ ${HERE}" /proc/mounts; then
                log "$HERE is already mounted."
            else
                # NFS mount not mounted, attempt mount
                log "NFS share not mounted; attempting to mount ${HERE}:"
                mount -t nfs ${MOUNTOPTS} ${FILESERVER}:${THERE} ${HERE}
            fi
        done
    else
        # Fileserver is down.
        log "Fileserver is down."
        for MOUNT in ${MOUNTS[@]}; do
            # Split up the share into the remote and local mount point.
            MOUNTP=(`echo ${MOUNT//$DELIMETER/ }`)
            # The second part of the mount string is the local mount point.
            # If there is no second part, local and remote are mounted on
            # the same location.
            HERE=${MOUNTP[${#MOUNTP[@]}-1]}
            THERE=${MOUNTP[0]}
            if grep -qsE "^([^ ])+ ${HERE}" /proc/mounts; then
                # NFS mount is still mounted; attempt umount
                log "Cannot reach ${FILESERVER}, unmounting NFS share ${HERE}."
                umount -f ${HERE}
            fi
        done
    fi
    sleep $INTERVAL
done
ea@seanix:~$

Manfred Hampl (m-hampl) said : #3

Does you system use systemd or upstart? https://wiki.ubuntu.com/SystemdForUpstartUsers

Why have you put this into the question area for libreoffice on Ubuntu? I do not see any relationship to libreoffice here. Moving this to "systemd on Ubuntu" would be probably better.

ealthuis (ealthuis) said : #4

My system(s) use systemd, I checked the script with "systemd-analyze verify", no errors. The setup as shown above works in two other systems without fail as long as the "server" is running

As to the question area I am not aware that such specifics exist and I claim ignorance.

Now back to the problem, as I read in the "https://wiki.ubuntu.com/SystemdForUpstartUsers" document, the script is supposed to start at boot, what reason can there be for that not happening.

It starts by this command without fail: "sudo systemctl start nfs_automount" without the quotes.

In fact I just installed the above scripts on a new installation (ubuntu unity-remix version 18.04LTS) and it worked perfectly.

And before you ask why that version, I had 17.10 on that computer and it is worse than Windows, I had planned to go back to 16.o4 LTS, but found 18.04 LTS and it works just fine too.

Manfred Hampl (m-hampl) said : #5

1. Have you tried
sudo systemctl enable nfs_automount.service

2. How did you create this question document?
When creating a question in Launchpad and entering the details you see a selection

This question is about:
 Distribution Choose…
 Package Choose…
 Project Choose…

or something like that. It seems that you have selected libreoffice, although this question has nothing to do with that package.

ealthuis (ealthuis) said : #6

1 Yes , that command is part of the instructions I had on creating the script< I entered it a number of times , both with and without sudo.

2 I agree, it has nothing to do directly with Libreoffice, but that is where I was working before this question was started. I never realized it was incorrect. In future I will take your comments to heart.

I would like nothing better than to have this question moved to "systemd", just tell me how.

Back to systemd, what could stand in the way for the above command to have no effect? I will get system info for you in the next paragraph, i am not on the computer in question.

ealthuis (ealthuis) said : #7

ea@seanix:~$ uname -a
Linux seanix 4.4.0-112-generic #135-Ubuntu SMP Fri Jan 19 11:48:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
ea@seanix:~$

I found a log file with the reason for this problem:

Feb 6 06:43:25 seanix gnome-session[2064]: Fileserver is up.
Feb 6 06:43:25 seanix gnome-session[2064]: NFS share not mounted; attempting to mount /media/mass:
Feb 6 06:43:25 seanix gnome-session[2064]: mount: only root can use "--options" option
Feb 6 06:43:25 seanix gnome-session[2064]: NFS share not mounted; attempting to mount /media/mass1:
Feb 6 06:43:25 seanix gnome-session[2064]: mount: only root can use "--options" option
Feb 6 06:43:25 seanix gnome-session[2064]: NFS share not mounted; attempting to mount /media/mass2:
Feb 6 06:43:25 seanix gnome-session[2064]: mount: only root can use "--options" option

Now , how do I solve it, again I am not aware that I used anywhere the "--options" option

ealthuis (ealthuis) said : #8

I checked other logs, no such error messages. the script does have mount options so I will search for why root is not being used to run the script.

ealthuis (ealthuis) said : #9

ea@seanix:~$ uname -a
Linux seanix 4.4.0-112-generic #135-Ubuntu SMP Fri Jan 19 11:48:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
ea@seanix:~$ sudo systemctl enable nfs_automount
[sudo] password for ea:
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs_automount.service to /lib/systemd/system/nfs_automount.service.
ea@seanix:~$ sudo systemctl start nfs_automount
ea@seanix:~$ ls -l /media
total 52
drwxr-x---+ 2 root root 4096 Feb 3 08:06 ea
lrwxrwxrwx 1 root root 7 Dec 19 06:15 floppy -> floppy0
drwxr-xr-x 2 root root 4096 Dec 19 06:15 floppy0
drwxrwxrwx 57 ea ea 36864 Feb 3 07:47 mass
drwxr-xr-x 3 root root 4096 Oct 13 2014 mass1
drwxrwxrwx 16 ea ea 4096 Jan 15 09:36 mass2
ea@seanix:~$

Best Manfred Hampl (m-hampl) said : #10

Visit your question document on launchpad https://answers.launchpad.net/ubuntu/+source/libreoffice/+question/664156

In the header part there is:

"For:
Ubuntu libreoffice"

with a yellow pencil sign besides it.
Click on that icon and you can re-sort the document to another package or project.

And another remark:
Have you seen the paragraph

# Logging. Set to true for debugging and testing; false when everything works. Logs
# are written to /var/log/upstart/autonfs.log.
LOG=false

in your script?

If you need more information why something happens (or not), what do you think about enabling debug?

And the "--options" flag probably refers to the short form "-o rw,hard,intr,tcp,actimeo=3" that you have in the script.

ealthuis (ealthuis) said : #11

The script autonfs.sh has "mount options"...

After I used "sudo systenctl enable nfs_automount" I shut the system down and restarted and all files were mounted as required.

Yet on the other computer, the one with 18.04LTS both files are owned by ea:ea and it also works...

Once again I have to thank you for leading me into the right direction.

The problem is solved.

ealthuis (ealthuis) said : #12

Thanks Manfred Hampl, that solved my question.