nl_tokens: Copies all the saved arguments ( from saveArgs ) to the startup file so that when the box reboots the arguments are executed .
pl_tokens: function prepareArgsForReboot ( ) { const deferred = q . defer ( ) ; let startupScripts ; let startupCommands ; let startupCommandsChanged ; const STARTUP_DIR = '/config/' ; const STARTUP_FILE = ` ${ STARTUP_DIR } ` ; const REBOOT_SIGNAL = ipc . signalBasePath + signals . REBOOT ; if ( ! fs . existsSync ( STARTUP_DIR ) ) { logger . debug ( 'No /config directory. Skipping.' ) ; deferred . resolve ( ) ; return deferred . promise ; } try { startupCommands = fs . readFileSync ( STARTUP_FILE , 'utf8' ) ; } catch ( err ) { logger . warn ( 'Error reading starup file.' ) ; deferred . reject ( err ) ; return deferred . promise ; } try { startupScripts = fs . readdirSync ( REBOOT_SCRIPTS_DIR ) ; } catch ( err ) { logger . warn ( 'Error reading directory with reboot args.' ) ; deferred . reject ( err ) ; return deferred . promise ; } // Make sure there's a new line at the end in case we add anything startupCommands += EOL ; // If we just rebooted, make sure the REBOOT signal file is deleted // so scripts don't think we need to reboot again if ( startupCommands . indexOf ( REBOOT_SIGNAL ) === - 1 ) { startupCommandsChanged = true ; startupCommands += ` ${ REBOOT_SIGNAL } ${ EOL } ` ; } startupScripts . forEach ( ( script ) => { const fullPath = REBOOT_SCRIPTS_DIR + <mask> ; if ( startupCommands . indexOf ( fullPath ) === - 1 ) { startupCommandsChanged = true ; startupCommands += ` ${ fullPath } ${ EOL } ` ; startupCommands += ` ${ fullPath } ${ EOL } ` ; startupCommands += ` ${ EOL } ` ; startupCommands += EOL ; } } ) ; if ( startupCommandsChanged ) { try { fs . writeFileSync ( STARTUP_FILE , startupCommands ) ; } catch ( err ) { logger . warn ( 'Failed writing startup file' , STARTUP_FILE , err ) ; } } deferred . resolve ( ) ; return deferred . promise ; }