:: krowemoh

Thursday | 13 MAR 2025
Posts Links Other About Now

previous
next

Adding Restart to SERAPHIM

2025-02-15
seraphim, basic, pick

While working on Hypermedia, I ended up on a side quest to make it easier to develop web applications with SERAPHIM. Currently it requires restarting SERAPHIM manually which means that I need to trigger a kill and then a RUN.

I used to have a restart end point for SERAPHIM's predecessor but I took it out when SERAPHIM became more general purpose. This is because SERAPHIM, once it was generalized, didn't know what application was calling it. This ultimately didn't matter as I only worked on my BLOG.SERVER and I also created different accounts for each project.

While working through the book is when I wanted to have multiple projects in the same account and I had removed the restart logic earlier. I found the restart logic and added it back in. I also added some code to pass in the calling programs into SERAPHIM by using the @USER2 variable. The @USER2 variable in pick systems lets you pass parameters without having to explicitly pass them into subroutines.

This way I could set @USER2 in WAVE.SERVER which then calls SERAPHIM. SERAPHIM could then check @USER2 to call the right program when it restarts.

      CALLING.PROGRAM = @USER2<1,1>
* 
      CASE REQUEST.URL = '/restart'
         DONE = TRUE
*
         RESPONSE(RESPONSE.STATUS.ATTRIBUTE) = 200
         RESPONSE(RESPONSE.CONTENT.ATTRIBUTE) = 'Restarting server.'
         GOSUB SEND.HTTP.RESPONSE
*
         $IFDEF DATABASE.D3
            %CLOSESOCKET(FD)
            %CLOSESOCKET(SOCKET)
         $ENDIF
*
         $IFDEF DATABASE.QM
            CLOSE.SOCKET FD
            CLOSE.SOCKET SOCKET
         $ENDIF
*
         $IFDEF DATABASE.UV
            CODE = closeSocket(FD)
            CODE = closeSocket(SOCKET)
         $ENDIF
*
         CHAIN CALLING.PROGRAM
*

Once I had the restart logic in SERAPHIM, the next step is to call in when a file changes.

This required writing a script in bash and it uses inotify to watch for file events. This could be done with BASIC but I wrote a quick and dirty script for now.

#!/usr/bin/env bash

FILE="/home/user/BP/WAVE.APP"

while true; do
    inotifywait -e close_write "$FILE"
    curl "http://192.168.12.11:7122/restart" 
done

This script watches for changes to WAVE.APP and will then trigger the restart endpoint when there is a change.

The script as is would be trivial to make it a BASIC program but I would like to build a proper WATCH command in BASIC that can watch a set of files and run a set of commands.

For now though, this is definitely going to speed up development while I work through the book.

Another longer term goal is to have some sort of javascript related reload function, that way saving a file will cause the web page to automatically refresh. This is a larger project however as this requires monitoring both the application and the template files.