onBoot in .replit file not working

Problem description

At the very top of my .replit file, I try to include an onBoot parameter, like this:

onBoot = "echo 'I'm awesome!'"

This seems visibly correct, and correct, according to the .replit docs, found here. But alas, it does not execute this in the console, nor the shell.

Expected behavior

When including an onBoot parameter in my .replit file, it should execute accordingly upon loading my repl.

Actual behavior

Including an onBoot parameter in my .replit file, does not execute accordingly.

Steps to reproduce

Add a onBoot parameter to the very top of a .replit file as follows:

onBoot = "echo 'I'm awesome!'"

Browser

Microsoft Edge

OS

Windows 11

Device if mobile

N/A

Plan

Core

I might be wrong, but I think the onBoot is run before the console/shell is even ready, so the output doesn’t end up anywhere usable.

1 Like

Hmm… good to note. I was using this as an example – in my real situation, I want to run a bash program that runs when the users loads into the repl, and it’s not working with onBoot

1 Like

try using the command touch test.txt as your onboot cmd and see if test.txt shows up

@python660 When I put touch test.txt as my onBoot command, test.txt is created successfully.

2 Likes

@python660 Any ideas on why running a bash program isn’t working?

How are you trying to run it?

@Firepup650 I’m doing bash test.bash.

Hm. Just to make sure, does it work when manually called from Shell?

1 Like

Yes, it does. The bash script is an infinite loop that uses inotifywait.

1 Like

I wonder if the onBoot cmd has a timelimit on it then, maybe it’s not allowed to run for long periods of time.

1 Like

try nohup or disown/detatch process?

1 Like

@python660 Sorry, not too experienced with this type of stuff — how would I do this?

1 Like

I made a test.sh:

while [ true ];
do
  echo $(date) > result.txt
  sleep 1
done

with onBoot = "bash test.sh"

Then kill 1 in the shell to restart the container
and it does continually update the result.txt file. Maybe you can simplify your script and debug it by writing out files in a similar way.

3 Likes

May I ask what this does?
My current makeFile.sh file has this contents:

#!/bin/bash

WATCH_DIR="./"

TEMPLATE="import java.awt.*;\n\npublic class FileName {\n\n}\n"

inotifywait -m -e create --format "%w%f" "${WATCH_DIR}" | while read NEW_FILE
do
    TEMP=${NEW_FILE%.*}
    
    if [[ "${TEMP}" == *.java ]]; then
        FILENAME=$(basename "${NEW_FILE}")
        CLASSNAME=$(echo "${FILENAME}" | sed "s/\.java.*$//") 
        # ./.Main.java -> .Main

        CLASSNAME="${CLASSNAME#.}"
        
        FILE_TEMPLATE=$(echo -e "${TEMPLATE}" | sed "s/FileName/${CLASSNAME}/g")
        TEMP_FILE="${NEW_FILE}.tmp"
    
        echo -e "$FILE_TEMPLATE$(cat "${NEW_FILE}")" > "${TEMP_FILE}"
        mv "${TEMP_FILE}" "${NEW_FILE}"
    
        fi
done

Here is the link to my repl:
JApplet - test by @RedCoder

Judging by your code, you are waiting for file creation events, and if it has a .java extension, then append the file template (import and public class) into the file.

1 Like

@python660 Yes, but why is this not running? Do you have any idea?

Tried to, but it still didn’t run it off the onBoot.