简体   繁体   中英

Start autofs after login with systemd

I want to mount remote shares into home/user folder with systemd. The problem is that autofs attempts to mount before the above mentioned user's folder gets mounted (because it's encrypted and requires login to mount). Autofs is resistant to not available remotes, but hangs somehow if target isn't available (never again attempts mounting). So I scripted simple service to restart autofs later in process. I tried several approaches which are visible in service's script. The only viable is to have delay. This works, however only if user logs in quickly. The script:

[Unit]
Description=delayedAutofs
After=network.target
RequiresMountsFor=/home/user

[Service]
User=root
ExecStart=/bin/bash -c "sleep 30;/bin/systemctl restart autofs.service"
Type=oneshot

[Install]
WantedBy=graphical.target

How should it be done to accomplish the task?

Replace line ExecStart=/bin/bash '/usr/bin/script.sh'

Create script.sh with check login in " while " cycle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM