bugy / script-server

Web UI for your scripts with execution management
Other
1.59k stars 247 forks source link

Autostart Scripts after script-server start? #712

Open klauweg opened 11 months ago

klauweg commented 11 months ago

Is it possible to start scripts automatically after starting launcher.py?

bugy commented 11 months ago

Hi @klauweg , unfortunately it's not :(

MNeill73 commented 11 months ago

Can you edit the script to be a wrapper, and check for it's own "last run date" (via a touch file or similar mechanism)? Then, if it hasn't run since "x", run.

Then you could schedule that job to run frequently enough to catch a restart.

For that matter... Bugy, is there a place to look for "Scriptserver's last start time"? You could then compare the last script run to SS's last start, and run if SS restarted since the last run. And then schedule as above.

On Fri, Nov 3, 2023, 2:16 AM Iaroslav Shepilov @.***> wrote:

Hi @klauweg https://github.com/klauweg , unfortunately it's not :(

— Reply to this email directly, view it on GitHub https://github.com/bugy/script-server/issues/712#issuecomment-1791936999, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3HBI3X6KUWCXAHHHUNJLPDYCSD2PAVCNFSM6AAAAAA633WYJWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJRHEZTMOJZHE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

MNeill73 commented 11 months ago

Or, leave the script itself alone, except for adding said touchfile, and then schedule a separate watchdog that does the SS-vs-script-last-run comparison, and runs the scripts behind itself if SS has restarted since last runs.

On Fri, Nov 3, 2023, 11:40 AM Mark Neill @.***> wrote:

Can you edit the script to be a wrapper, and check for it's own "last run date" (via a touch file or similar mechanism)? Then, if it hasn't run since "x", run.

Then you could schedule that job to run frequently enough to catch a restart.

For that matter... Bugy, is there a place to look for "Scriptserver's last start time"? You could then compare the last script run to SS's last start, and run if SS restarted since the last run. And then schedule as above.

On Fri, Nov 3, 2023, 2:16 AM Iaroslav Shepilov @.***> wrote:

Hi @klauweg https://github.com/klauweg , unfortunately it's not :(

— Reply to this email directly, view it on GitHub https://github.com/bugy/script-server/issues/712#issuecomment-1791936999, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3HBI3X6KUWCXAHHHUNJLPDYCSD2PAVCNFSM6AAAAAA633WYJWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJRHEZTMOJZHE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

bugy commented 11 months ago

@MNeill73 unfortunately there is no simple way to find out the last start time. The only way is to read server.log

MNeill73 commented 11 months ago

That's a relatively trivial task, though...in bashlike form...

SSStartLog=grep "*some identifiable start string from the log*" /path/to/server.log | awk "{print *$the $fields $that $are $the $date*}" SSStart=date --date="${SSStartLog}" %+"%s"

And now you have Scriptserver's start time in epoch format. Then...

TouchfileTime=stat -c %y */path/to/touchfile* # File last modification date in human-readable form TouchfileLast= date --date="${TouchfileTime}" %+"%s"

And that's the touchfile's last modification in the same form. Compare the two, run if ${SSStart} > ${TouchfileLast}.

Message ID: @.***>

klauweg commented 11 months ago

Hm, i thought about some tricks with the scheduling feature already. It would be easy if there where an option to prevent a script from running with multiple Instances. But it would be a bit poor anyway.

klauweg commented 11 months ago

Maybe it could be feasible to create scheduling entries by a wrapper for script-server before starting it. Every configured script with enabled scheduling gets a one-shot entry let's say for one minute later. Afters starting script-server all prepared scripts will be started with a little delay.

Of course i would prefer to have a button on script-server webinterface to start them itself ;-).

polzy commented 8 months ago

Hello, The script works great, thank you very much. The idea of automatically launching a script at script-server startup is a fantastic one. In my organization, we have servers that shut down at night to manage energy consumption, and we need scripts to run when the server restarts. The problem is that I cannot schedule the time. Some servers start as soon as someone arrives first and badges in the morning at the building.