def change_privilege(user, group=user)
      Wakame.log.info("Changing process privilege to #{user}:#{group}")

      uid, gid = Process.euid, Process.egid
      target_uid = Etc.getpwnam(user).uid
      target_gid = Etc.getgrnam(group).gid

      if uid != target_uid || gid != target_gid
        if pid_file && File.exist?(pid_file) && uid == 0
          File.chown(target_uid, target_gid, pid_file)
        end

        # Change process ownership
        Process.initgroups(user, target_gid)
        Process::GID.change_privilege(target_gid)
        Process::UID.change_privilege(target_uid)
      end
    rescue Errno::EPERM => e
      Wakame.log.error("Couldn't change user and group to #{user}:#{group}: #{e}")
    end
def change_privilege(user, group=user)
      Wakame.log.info("Changing process privilege to #{user}:#{group}")

      uid, gid = Process.euid, Process.egid
      target_uid = Etc.getpwnam(user).uid
      target_gid = Etc.getgrnam(group).gid

      if uid != target_uid || gid != target_gid
        if pid_file && File.exist?(pid_file) && uid == 0
          File.chown(target_uid, target_gid, pid_file)
        end

        # Change process ownership
        Process.initgroups(user, target_gid)
        Process::GID.change_privilege(target_gid)
        Process::UID.change_privilege(target_uid)
      end
    rescue Errno::EPERM => e
      Wakame.log.error("Couldn't change user and group to #{user}:#{group}: #{e}")
    end
Change privileges of the process
 to the specified user and group.