Skip to content
Snippets Groups Projects
Select Git revision
  • a3ff6c50756e21796e17371cee43d06c30a96834
  • master default protected
  • devel-db
  • devel
4 results

user_instance.pp

Blame
  • user_instance.pp 2.03 KiB
    # @summary Configures an mpd instance for the specified user
    #
    # Only works on systems which uses systemd, and already has a user
    # systemd unit for mpd.
    #
    # @param user
    #   User to run as, as well as owner of files
    # @param group
    #   Group for created files
    # @param user_home
    #   Home directory for user. Used in figuring out where to put
    #   configuation files.
    # @param xdg_config_home
    #   XDG configuration directory for user, used in figuring out where
    #   to put configuration files.
    # @param config_dir
    #   User specific configuration directory for mpd.
    # @param config_file
    #   User specific configuration file for mpd.
    # @param manage_dir
    #   Should the config_dir be managed by us.
    # @param mpd_conf
    #   Settings passed along to mpd::conf
    # @param service_name
    #   Name of the user (system) service
    define mpd::user_instance (
      String $user = $name,
      String $group = $user,
      String $user_home = "/home/${user}",
      String $xdg_config_home = "${user_home}/.config",
      String $config_dir = "${xdg_config_home}/mpd",
      String $config_file = "${config_dir}/mpd.conf",
      Boolean $manage_dir = true,
      Hash[String, Any] $mpd_conf = {},
      String $service_name = 'mpd',
    ) {
      if $manage_dir {
        file { $config_dir:
          ensure => directory,
          owner  => $user,
          group  => $group,
        }
      }
    
      $conf_defaults = {
        'mpd_home' => $config_dir,
      }
    
      mpd::config { "MPD instance for ${user}":
        config_file => $config_file,
        user        => undef,
        owner       => $user,
        group       => $group,
        *           => $conf_defaults + $mpd_conf,
      } ~> Exec["Restart user ${user} mpd instance"]
    
      exec { "Enable user ${user} mpd instance":
        command => "systemctl enable --machine=${user}@.host --now --user ${service_name}",
        creates => "${xdg_config_home}/systemd/user/default.target.wants/mpd.service",
        path    => ['/bin', '/usr/bin'],
      }
    
      exec { "Restart user ${user} mpd instance":
        command     => "systemctl restart --machine=${user}@.host --user ${service_name}",
        refreshonly => true,
        path        => ['/bin', '/usr/bin'],
      }
    }