Announcement

Collapse
No announcement yet.

Systemd geniuses wanted - login and logout functions with systemd and root access

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Systemd geniuses wanted - login and logout functions with systemd and root access

    As an experiment I am attempting to have some bind mounts created when a user logs in and then unmounted on log out. I have a working set of scripts but I would like to learn how to use systemd to control the actions.

    My goal is to have all users have a set of private folders bind-mounted to their home at log in (not at boot-up) and disconnected when they log out. I used to be able to do this with X but since we're moving away from X soon to Wayland and systemd is new and powerful, I'd like to figure this one out. I've read dozens of pages and forums but nothing is complete or on-target.

    Here's the systemd.service I tried:

    Code:
    [FONT=monospace][COLOR=#5454FF][B]/etc/systemd/system[/B][/COLOR][COLOR=#000000]$ cat bindmounts.service  [/COLOR]
    [Unit]
    Description = Mount bindmounts  
    After=network.target
    
    [Service]
    User=root
    Type=oneshot
    RemainAfterExit=true
    StandardOutput=journal
    ExecStart = /etc/systemd/user/bindin.sh
    Execstop = /etc/systemd/user/bindout.sh
    
    [Install]
    WantedBy=default.target
    
    [/FONT]
    I really have no clue what I'm doing.

    Please Read Me

    #2
    Apparently it doesn't work?
    "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
    – John F. Kennedy, February 26, 1962.

    Comment


      #3
      Nope. I'm not even close. My scripts have mount in them so must be run as root, but no environmental variables are passed to the script (I need $USER or $LOGNAME in the script). None of the tips on how to pass variables work. I either get a blank or "root" passed, but no username.

      I tried

      Environment="ONE=${USER}" as suggested by the man pages, but what gets passed is $USER not the value of $USER.

      I tried running the service as a user then setting "User=root" and that gets me to the same place. Either the mount fails because of lack of permission or the mount fails because it tries to mount to /home//Documents instead of /home/$USER/Documents.

      Please Read Me

      Comment


        #4
        From "man systemd.unit" is the following:
        Code:
               |"%u"      │ User name                   │ This is the name of the     │
               │          │                             │ user running the service    │
               │          │                             │ manager instance. In case   │
               │          │                             │ of the system manager this  │
               │          │                             │ resolves to "root".         │
               ├──────────┼─────────────────────────────┼─────────────────────────────┤
               │"%U"      │ User UID                    │ This is the numeric UID of  │
               │          │                             │ the user running the        │
               │          │                             │ service manager instance.   │
               │          │                             │ In case of the system       │
               │          │                             │ manager this resolves to    │
               │          │                             │ "0".                        │
               ├──────────┼─────────────────────────────┼─────────────────────────────┤
               │"%h"      │ User home directory         │ This is the home directory  │
               │          │                             │ of the user running the     │
               │          │                             │ service manager instance.   │
               │          │                             │ In case of the system       │
               │          │                             │ manager this resolves to    │
               │          │                             │ "/root".
        What's needed is an "after=login.target", but I couldn't find one. Maybe write one?
        Last edited by GreyGeek; May 23, 2018, 09:41 PM.
        "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
        – John F. Kennedy, February 26, 1962.

        Comment


          #5
          I'm going to call this "ABANDONDED" as I don't think systemd is suited for this.

          Turns out there is functionality called "pam_mount" which is designed for just this purpose.

          Please Read Me

          Comment

          Working...
          X