export owner=minio

useradd -r ${owner} -s /sbin/nologin

chown ${owner}:${owner} /usr/bin/minio

mkdir -pv  /etc/minio /mnt/minio-data

chown ${owner}:${owner} /mnt/minio-data /etc/minio


cat > /etc/sysconfig/minio <<EOF
MINIO_ACCESS_KEY="minio"
MINIO_SECRET_KEY="minio8848"
#MINIO_VOLUMES=http://minio-1{1...4}/mnt/minio-data/{1...2}
MINIO_VOLUMES="/mnt/minio-data/"
MINIO_OPTS="-C /etc/minio --address 0.0.0.0:9000"
EOF


cat > /etc/systemd/system/minio.service<<EOF
[Unit]
Description=MinIO
Documentation=https://docs.min.io
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/bin/minio

[Service]
WorkingDirectory=/usr/bin

User=${owner}
Group=${owner}

EnvironmentFile=/etc/sysconfig/minio
ExecStartPre=/bin/bash -c "if [ -z \"\${MINIO_VOLUMES}\" ]; then echo \"Variable MINIO_VOLUMES not set in /etc/sysconfig/minio\"; exit 1; fi"
ExecStart=/usr/bin/minio server \$MINIO_OPTS \$MINIO_VOLUMES
# Let systemd restart this service always
Restart=always
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=infinity
SendSIGKILL=no

[Install]
WantedBy=multi-user.target

EOF

systemctl enable minio
