package slurm import ( "crypto/sha256" "encoding/hex" "fmt" ) // Accounting: slurmdbd on the controller, keeping the jobs' records in a // MariaDB beside it that answers this machine alone. slurmdbd takes MySQL or // MariaDB only, so it is not the cluster's PostgreSQL. Since 23.11 Slurm // cannot run without it well: its main scheduler passes every job by as // InvalidAccount, and backfill starts it a pass later. const ( // DbdPort is slurmdbd's, which slurmctld and sacct reach. DbdPort = 6819 // DbdConfPath is slurmdbd's file, readable by the slurm user alone: it // holds the database's password. DbdConfPath = ConfDir + "/slurmdbd.conf" // AcctDB and AcctUser are the database and its user. AcctDB = "slurm_acct_db" AcctUser = "slurm" ) // DbdPassword is the database user's password, made from the munge key: // every controller the cluster has gets the same one, and nothing new is // kept anywhere. func DbdPassword(mungeKey []byte) string { h := sha256.New() h.Write([]byte("llmgw slurmdbd password\x00")) h.Write(mungeKey) return hex.EncodeToString(h.Sum(nil))[:40] } // DbdConf is slurmdbd.conf for the controller host, named as `hostname -s` // says, which slurmdbd checks it runs on. func DbdConf(host, password string) string { return header + fmt.Sprintf(`AuthType=auth/munge DbdHost=%s DbdPort=%d SlurmUser=slurm LogFile=%s/slurmdbd.log PidFile=/run/slurmdbd.pid StorageType=accounting_storage/mysql StorageHost=localhost StorageUser=%s StoragePass=%s StorageLoc=%s # Kept a year; older records are purged, a month at a time. PurgeEventAfter=12months PurgeJobAfter=12months PurgeResvAfter=12months PurgeStepAfter=12months PurgeSuspendAfter=12months PurgeTXNAfter=12months PurgeUsageAfter=24months `, host, DbdPort, LogDir, AcctUser, password, AcctDB) } // MariaDBConf is the database server's settings: this machine alone, and // what Slurm's documentation asks of InnoDB. const MariaDBConf = `# Written by llmgw (BACKLOG P): the database of Slurm's accounting # (slurmdbd), on this machine alone. [mysqld] bind-address=127.0.0.1 skip-networking=0 innodb_buffer_pool_size=256M innodb_lock_wait_timeout=900 ` // AcctSQL makes the database and its user, and gives the user the password // again: run on every start of the controller's part, it changes nothing // that is already so. func AcctSQL(password string) string { return fmt.Sprintf(`CREATE DATABASE IF NOT EXISTS %[1]s; CREATE USER IF NOT EXISTS '%[2]s'@'localhost' IDENTIFIED BY '%[3]s'; ALTER USER '%[2]s'@'localhost' IDENTIFIED BY '%[3]s'; GRANT ALL ON %[1]s.* TO '%[2]s'@'localhost'; FLUSH PRIVILEGES; `, AcctDB, AcctUser, password) }