Changes between Version 26 and Version 27 of RB1100AHX4


Ignore:
Timestamp:
02/06/26 22:59:29 (11 days ago)
Author:
krit
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • RB1100AHX4

    v26 v27  
    461461
    462462}}}
     463
     464Set scheduler to run script after boot
     465{{{
     466[admin@MK53] /system/scheduler> print
     467Columns: NAME, START-TIME, INTERVAL, ON-EVENT, RUN-COUNT
     468# NAME               START-TIME  INTERVAL  ON-EVENT    RUN-COUNT
     4690 Run_Alpine_OnBoot  startup     0s        alpine_min          1
     470[admin@MK53] /system/scheduler> 
     471}}}
     472Here the '''apline_min''' script
     473{{{
     474:do {
     475    :delay 10s
     476    :log info "Script Run_Alpine_OnBoot after 10s from boot"
     477    # --- Certificate Cleanup ---
     478    :put "--- Starting Full Certificate Cleanup ---"
     479    # Find all certificates by their ID. The 'find' command returns a list of internal IDs.
     480    :local allCertIds [/certificate find]
     481 
     482    :if ([:len $allCertIds] > 0) do={
     483        :put ("Found " . [:len $allCertIds] . " certificates. Removing all...")
     484        # The 'remove' command can take a list of IDs directly.
     485        /certificate remove $allCertIds
     486        :put "All certificates have been removed."
     487    } else={
     488        :put "No certificates found to remove."
     489    }
     490    :put "--- Certificate Cleanup Complete ---"
     491    :delay 10s
     492    :log info "Waited 10 sec ... to clean Container"
     493 
     494    # --- Container Management ---
     495    :local cname "alpine"
     496    :put "Searching for existing container..."
     497    :local cid [/container find where name=$cname]
     498 
     499    :if ($cid != "") do={
     500        :put ("Found existing container. Stopping and removing: " . $cname)
     501        #/container stop $cid
     502        #:delay 2s
     503        /container remove $cid
     504        :delay 5s
     505    } else={
     506        :put ("No existing container found: " . $cname)
     507    }
     508 
     509    :put "Creating new alpine container..."
     510    :log info "Creating new alpine container..."
     511    /container add \
     512        name=$cname \
     513        file=alpine-arm64.tar \
     514        interface=veth1 \
     515        root-dir=ram \
     516        logging=yes
     517 
     518    :delay 10s
     519 
     520    :local newcid [/container find where name=$cname]
     521    :if ($newcid = "") do={
     522        :error "FATAL: Container was not created. Check logs for details."
     523        :put "FATAL: Container was not created"
     524        :log warning "FATAL: Container was not created"
     525    }
     526 
     527    :put ("Starting alpine container... ". $cname)
     528    /container start $cname
     529    :delay 10s
     530 
     531    # --- Verify Container is Running ---
     532    :put $cname
     533    :local status [/container print count-only where name=$cname and running=yes ]
     534    :if ($status != 1) do={
     535        :error ("FATAL: Container failed to start. Current status: " . $status)
     536        :log warning "FATAL: Container failed to start"
     537    }
     538 
     539    :put "Container is running. Proceeding with package installation..."
     540    :log info "Container is running"
     541 
     542    # --- Setup Inside Container ---
     543    #:put "Installing packages (update, wget, python3...)"
     544    #/container shell $newcid cmd="apk update"
     545    #:delay 5s
     546    #/container shell $newcid cmd="apk add --no-cache python3 tzdata inetutils-telnet busybox-extras"
     547    #:delay 5s
     548    /container shell $newcid cmd="ln -s /usr/share/zoneinfo/Asia/Bangkok /etc/localtime"
     549    :delay 3s
     550 
     551    #:put "Downloading .profile..."
     552    #/container shell $newcid cmd="wget -O /root/.profile http://188.166.217.51/~krit/dot_profile"
     553 
     554    :put "---"
     555    :put "Alpine container setup complete and running successfully!"
     556    :put "---"
     557}
     558 
     559}}}