Debian Jessie start rpcbind and nfs-common at boot with systemd

autofsbootdebiannfssystemd

On my Raspbian (based on Debian Jessie), I need to start at boot rpcbind and nfs-common services because I need them to start autofs at boot for a NFS mount.

Since Debian Jessie now has moved to systemd, I want to know the best way to start those 3 services (rpcbind, nfs-commond, autofs) in the correct order to avoid issues.

If I manually mount the NFS share it works. And it also works when using the autofs service with rpcbind and nfs-common already up and running.

autofs uses a systemd unit script. About the other 2 services, should I make init.d scripts or do I have to create systemd unit files? How can I write them?

Best Answer

The reason for the problem is the lack of systemd configuration files. Base on a post by Matt Grant on debian-devel these are the steps you need to perform.

1. Create /etc/systemd/system/nfs-common.service

cat >/etc/systemd/system/nfs-common.service <<\EOF
[Unit]
Description=NFS Common daemons
Wants=remote-fs-pre.target
DefaultDependencies=no

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/init.d/nfs-common start
ExecStop=/etc/init.d/nfs-common stop

[Install]
WantedBy=sysinit.target
EOF

2. Create /etc/systemd/system/rpcbind.service

cat >/etc/systemd/system/rpcbind.service <<\EOF
[Unit]
Description=RPC bind portmap service
After=systemd-tmpfiles-setup.service
Wants=remote-fs-pre.target
Before=remote-fs-pre.target
DefaultDependencies=no

[Service]
ExecStart=/sbin/rpcbind -f -w
KillMode=process
Restart=on-failure

[Install]
WantedBy=sysinit.target
Alias=portmap
EOF

3. Create /etc/tmpfiles.d/rpcbind.conf

cat >/etc/tmpfiles.d/rpcbind.conf <<\EOF
#Type Path        Mode UID  GID  Age Argument
d     /run/rpcbind 0755 root root - -
f     /run/rpcbind/rpcbind.xdr 0600 root root - -
f     /run/rpcbind/portmap.xdr 0600 root root - -
EOF

4. Configure the services to run at startup

systemctl enable rpcbind.service
systemctl enable nfs-common
Related Question