ErnWong / dotfiles

Let's start from fresh again
2 stars 0 forks source link

gdrive mount service not automatically starting #23

Closed ErnWong closed 4 months ago

ErnWong commented 4 months ago

Status after reboot is:


○ gdrive-mount.service - Mount Google Drive
     Loaded: loaded (/home/ernwong/.config/systemd/user/gdrive-mount.service; enabled; preset: enabled)
     Active: inactive (dead)

But I can always manually start it up with

systemctl start --user gdrive-mount 

Things I've tried:

Changing the startServices option to true ("legacy"), commenting startServices out. No luck.

Perhaps it's because it's failing in some way when it is being shutdown, and this failure makes systemd not try to re-start it the next time? Not sure.

I've also tried commenting out the failing ExecStop script as unmounting was failing:

May 11 21:59:10 kaiki systemd[2687]: Stopping Mount Google Drive...
░░ Subject: A stop job for unit UNIT has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A stop job for unit UNIT has begun execution.
░░ 
░░ The job identifier is 9287.
May 11 21:59:10 kaiki fusermount[128471]: /nix/store/0291b6wgg0kk83zn84lhfaf5g8jqg33c-fuse-2.9.9/bin/fusermount: failed to unmount /home/ernwong/gdrive: Operation not permitted

however we still get a failure when stopping the service even without that ExecStop step:

May 11 22:35:17 kaiki systemd[2693]: Stopping Mount Google Drive...
░░ Subject: A stop job for unit UNIT has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A stop job for unit UNIT has begun execution.
░░ 
░░ The job identifier is 1257.
May 11 22:35:17 kaiki rclone[13737]: ERROR : /home/ernwong/gdrive: Unmounted rclone mount
May 11 22:35:17 kaiki systemd[2693]: gdrive-mount.service: Main process exited, code=exited, status=143/n/a
ErnWong commented 4 months ago

Right, seems to be intentional that it returns a non-zero exit code unless it is manually unmounted using fusermount as we were trying to with our ExecStop step: https://forum.rclone.org/t/non-zero-exit-status-from-rclone-mount-even-with-clean-unmount/38884

ErnWong commented 4 months ago

I wonder if it's because I tried using the fusermount binary from the nixpkg directly, rather than from the installed folder which would have the setuid flags and stuff? https://discourse.nixos.org/t/fusermount-systemd-service-in-home-manager/5157/3

ErnWong commented 4 months ago

And that seems to have fixed the failures:

May 11 22:54:55 kaiki systemd[2696]: Starting Mount Google Drive...
░░ Subject: A start job for unit UNIT has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A start job for unit UNIT has begun execution.
░░ 
░░ The job identifier is 1439.
May 11 22:54:56 kaiki systemd[2696]: Started Mount Google Drive.
░░ Subject: A start job for unit UNIT has finished successfully
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A start job for unit UNIT has finished successfully.
░░ 
░░ The job identifier is 1439.
May 11 22:55:00 kaiki systemd[2696]: Stopping Mount Google Drive...
░░ Subject: A stop job for unit UNIT has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A stop job for unit UNIT has begun execution.
░░ 
░░ The job identifier is 1452.
May 11 22:55:00 kaiki systemd[2696]: Stopped Mount Google Drive.
░░ Subject: A stop job for unit UNIT has finished
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A stop job for unit UNIT has finished.
░░ 
░░ The job identifier is 1452 and the job result is done.

Now let's see if this allows the service to automatically start after reboot.

ErnWong commented 4 months ago

Hmmm, unfortunately even though https://github.com/ErnWong/dotfiles/commit/7ff90c6f612001e04f54c792e94ee9b22ca848d9 helped remove the failures when stopping the service, it did not make the service automatically start up.

ErnWong commented 4 months ago

Perhaps it's because multi-user.target is a system level target but we are trying to set up a user level target? https://unix.stackexchange.com/questions/698463/service-in-systemd-user-mode-inactive-dead

I see home manager examples use default.target as well, so maybe I should give that a try.

ErnWong commented 4 months ago

And this seems to be it. Nixos rebuild now starts up the service it looks like!

~/dotfiles> sudo nixos-rebuild switch --flake .#kaiki                                                                                         05/11/2024 11:02:30 PM
[sudo] password for ernwong: 
warning: Git tree '/home/ernwong/dotfiles' is dirty
building the system configuration...
warning: Git tree '/home/ernwong/dotfiles' is dirty
updating GRUB 2 menu...
activating the configuration...
setting up /etc...
reloading user units for ernwong...
restarting sysinit-reactivation.target
restarting the following units: home-manager-ernwong.service
the following new units were started: home-ernwong-gdrive.mount, sysinit-reactivation.target, systemd-tmpfiles-resetup.service