Skip to content

Commit

Permalink
update setup
Browse files Browse the repository at this point in the history
  • Loading branch information
POPPIN-FUMI committed Oct 19, 2023
1 parent 6940741 commit 0784e79
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 36 deletions.
14 changes: 11 additions & 3 deletions src/cli/check/ensureMountAndFiles.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { DEFAULT_FILE_SYSTEM, SOLANA_ACCOUNT_ROOT } from '@/config'
import {
DEFAULT_FILE_SYSTEM,
SECOND_FILE_SYSTEM,
SOLANA_ACCOUNT_ROOT,
} from '@/config'
import { spawnSync } from 'child_process'

const ramLine = `tmpfs ${SOLANA_ACCOUNT_ROOT} tmpfs rw,size=300G,user=solv 0 0`

export const ensureFstabEntries = (fileSystem = DEFAULT_FILE_SYSTEM) => {
export const ensureFstabEntries = (
fileSystem = DEFAULT_FILE_SYSTEM,
fileSystem2 = SECOND_FILE_SYSTEM
) => {
const mtLine = `${fileSystem} /mt ext4 auto 0 0`
const lines = [ramLine, mtLine]
const mtLine2 = `${fileSystem2} /mnt ext4 auto 0 0`
const lines = [mtLine, mtLine2, ramLine]
const output = spawnSync(`cat /etc/fstab`, {
shell: true,
encoding: 'utf8',
Expand Down
4 changes: 2 additions & 2 deletions src/cli/mt/getLargestUnmountedDisks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type DiskInfo = {
size: number
}

export function getLargestUnmountedDisks(): DiskInfo[] {
export function getLargestUnmountedDisks(): string[] {
const commandOutput = execSync('lsblk -l -b -o NAME,SIZE,MOUNTPOINT', {
encoding: 'utf8',
})
Expand All @@ -26,5 +26,5 @@ export function getLargestUnmountedDisks(): DiskInfo[] {
unmountedDisks.sort((a, b) => b.size - a.size)

// Return only the two largest disks
return unmountedDisks.slice(0, 2)
return unmountedDisks.slice(0, 2).map((disk) => disk.name)
}
5 changes: 0 additions & 5 deletions src/cli/mt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,4 @@ export const mountCommands = () => {
const disks = getLargestUnmountedDisks()
console.log(disks)
})

program
.command('mount')
.description('Mount all unmounted disks')
.action(() => {})
}
10 changes: 2 additions & 8 deletions src/cli/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@ import { program } from '@/index'
import { setup } from './setup'
import { startValidator } from './startValidator'
import chalk from 'chalk'
import { DEFAULT_FILE_SYSTEM, VALIDATOR_STARTUP_SCRIPT } from '@/config'
import { VALIDATOR_STARTUP_SCRIPT } from '@/config'

export const setupCommands = async () => {
program
.command('setup')
.description('Setup Solana Validator All-in-One')
.option('--sh', 'Update Validator StartUp Bash Script', false)
.option('--swap', 'Setup Swap', false)
.option(
'-p, --path <path>',
'Path to Solana Directory',
DEFAULT_FILE_SYSTEM
)
.action((options) => {
if (options.sh) {
console.log(chalk.white(`Generating ${VALIDATOR_STARTUP_SCRIPT} ...`))
startValidator()
} else {
console.log(chalk.white('Setting up Solana Validator ...'))
setup(options)
setup()
}
})
}
2 changes: 1 addition & 1 deletion src/cli/setup/makeServices.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setupSystemd } from '@/template/setupSystemd'
import { setupSystemd } from '@/cli/setup/setupSystemd'
import { setupLogrotate } from './setupLogrotate'
import { setupSolvService } from './setupSolvService'

Expand Down
12 changes: 6 additions & 6 deletions src/cli/setup/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import { setupSwap } from './setupSwap'
import { startValidator } from './startValidator'
import { Logger } from '@/lib/logger'
import chalk from 'chalk'
import { DEFAULT_FILE_SYSTEM, MOUNT_ROOT } from '@/config'
import { MOUNT_ROOT } from '@/config'
import { makeServices } from './makeServices'
import { getLargestUnmountedDisks } from '../mt/getLargestUnmountedDisks'

export const setup = (
options = { swap: false, fileSystem: DEFAULT_FILE_SYSTEM }
) => {
export const setup = () => {
try {
if (!isSolanaInstalled()) {
Logger.normal(
Expand All @@ -20,14 +19,15 @@ export const setup = (
)
return
}
const disks = getLargestUnmountedDisks()
setupSwap(disks[0], disks[1])
setupDirs()
const chown = `sudo chown -R solv:solv ${MOUNT_ROOT} && sudo chmod -R 755 ${MOUNT_ROOT}`
spawnSync(chown, { shell: true, stdio: 'inherit' })
makeServices()
startValidator()
setupDirs()
setupKeys()
spawnSync(chown, { shell: true, stdio: 'inherit' })
if (options.swap) setupSwap(options.fileSystem)
const cmds = [
'sudo systemctl daemon-reload',
'sudo systemctl enable solv',
Expand Down
6 changes: 4 additions & 2 deletions src/cli/setup/setupLogrotate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SOL_LOGROTATE_PATH } from '@/config'
import { logRotates } from '@/template/logRotates'
import { writeFileSync, existsSync } from 'fs'
import { existsSync } from 'fs'
import { execSync } from 'child_process'

export function setupLogrotate(): void {
console.log('Creating logrotate configuration for solana')
Expand All @@ -11,7 +12,8 @@ export function setupLogrotate(): void {
)
} else {
const body = logRotates()
writeFileSync(SOL_LOGROTATE_PATH, body)
// Use sudo tee to write the file with superuser privileges
execSync(`echo "${body}" | sudo tee ${SOL_LOGROTATE_PATH} > /dev/null`)
console.log('Logrotate configuration created.')
}
}
6 changes: 4 additions & 2 deletions src/cli/setup/setupSolvService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SOL_SERVICE_PATH } from '@/config'
import { solvService } from '@/template/solvService'
import { writeFileSync, existsSync } from 'fs'
import { existsSync } from 'fs'
import { execSync } from 'child_process'

export function setupSolvService(): void {
console.log('Creating solvService configuration for solana')
Expand All @@ -11,7 +12,8 @@ export function setupSolvService(): void {
)
} else {
const body = solvService()
writeFileSync(SOL_SERVICE_PATH, body)
// Use sudo tee to write the file with superuser privileges
execSync(`echo "${body}" | sudo tee ${SOL_SERVICE_PATH} > /dev/null`)
console.log('solv.service configuration created.')
}
}
22 changes: 18 additions & 4 deletions src/cli/setup/setupSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,40 @@ import { checkMemoryAndSwap } from '../check/checkMemoryAndSwap'
import { ensureFstabEntries } from '../check/ensureMountAndFiles'
import { formatDisk } from './formatDisk'
import { mkdirSync } from 'fs'
import { DEFAULT_FILE_SYSTEM, SOLANA_ACCOUNT_ROOT, SWAP_PATH } from '@/config'
import {
DEFAULT_FILE_SYSTEM,
MOUNT_ROOT,
SECOND_FILE_SYSTEM,
SOLANA_ACCOUNT_ROOT,
SWAP_PATH,
} from '@/config'

export const setupSwap = (fileSystem = DEFAULT_FILE_SYSTEM) => {
export const setupSwap = (
fileSystem = DEFAULT_FILE_SYSTEM,
fileSystem2 = SECOND_FILE_SYSTEM
) => {
try {
formatDisk(fileSystem)
formatDisk(fileSystem2)
if (!execSync(SOLANA_ACCOUNT_ROOT)) {
mkdirSync(SOLANA_ACCOUNT_ROOT, { recursive: true })
}
if (!execSync(MOUNT_ROOT)) {
mkdirSync(MOUNT_ROOT, { recursive: true })
}

const cmds = [
`sudo swapoff ${SWAP_PATH}`,
`sudo mount ${fileSystem} ${MOUNT_ROOT}`,
`sudo mount -t tmpfs -o rw,size=300G,user=solv 0 0 tmpfs ${SOLANA_ACCOUNT_ROOT}`,
`sudo swapoff ${SWAP_PATH}`,
`sudo dd if=/dev/zero of=${SWAP_PATH} bs=1MiB count=250KiB`,
`sudo mkswap ${SWAP_PATH}`,
`sudo chmod 600 ${SWAP_PATH}`,
`sudo swapon ${SWAP_PATH}`,
`sudo swapon --all --verbose`,
]
if (!checkMemoryAndSwap()) {
ensureFstabEntries(fileSystem)
ensureFstabEntries(fileSystem, fileSystem2)
}
console.log(chalk.white('Setting up swap...\n'))
const spinner = Logger.syncSpinner('This may take a while...')
Expand Down
10 changes: 7 additions & 3 deletions src/template/setupSystemd.ts → src/cli/setup/setupSystemd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
SOL_SYSTEM_CONFIG21_PATH,
} from '@/config'
import { execSync } from 'child_process'
import { existsSync, writeFileSync } from 'fs'
import { existsSync } from 'fs'

export function setupSystemd(): void {
if (!existsSync(SOL_SYSTEM_CONFIG21_PATH)) {
Expand All @@ -30,7 +30,9 @@ fs.nr_open = 1000000
`

// Write sysctl configuration
writeFileSync(SOL_SYSTEM_CONFIG21_PATH, sysctlConfig)
execSync(
`echo "${sysctlConfig}" | sudo tee ${SOL_SYSTEM_CONFIG21_PATH} > /dev/null`
)

// Apply sysctl configuration
execSync(`sudo sysctl -p ${SOL_SYSTEM_CONFIG21_PATH}`)
Expand All @@ -41,6 +43,8 @@ fs.nr_open = 1000000
)

// Write nofiles configuration
writeFileSync(SOL_NOFILES_CONF_PATH, nofilesConfig)
execSync(
`echo "${nofilesConfig}" | sudo tee ${SOL_NOFILES_CONF_PATH} > /dev/null`
)
}
}

0 comments on commit 0784e79

Please sign in to comment.