Hi everyone,
I have a personal Linux Server (Raspberry Pi running Rasbpian) and want to have a perpetually running Julia instance going on the server. My rationale behind this is to have the server execute some scripts I have written in Julia and not have to precompile the scripts every single time. My question is, is how would I best accomplish this?
DaemonMode.jl by @dmolina seems super promising but I am not sure how I could utilize the running Julia instance with a crontab set up for example. If that is even the way I should think to approach such an idea. Does anyone have any ideas on how to best accomplish what I want to do? Thanks everyone!
~ tcp
You could use FileWatching to watch a folder for new scripts, and the server will execute anything dropped in there, and then remove the script once finished. Then cron or whatever can drop scripts in this folder according to various events. You should also dump stdout+stderr to a log file somewhere, with a small header printed before executing each file.
3 Likes
Please note Iâve never used DaemonMode.jl, it does look interesting. What I would try is setup your crontab like:
@reboot julia --startup-file=no -e 'using DaemonMode; serve()'
0 1 * * * julia --startup-file=no -e 'using DaemonMode; runargs()' path/to/script1.jl <arguments>
0 2 * * * julia --startup-file=no -e 'using DaemonMode; runargs()' path/to/script2.jl <arguments>
0 3 * * * julia --startup-file=no -e 'using DaemonMode; runargs()' path/to/script3.jl <arguments>
The first line should ensure that after a reboot DaemonModeâs server is running. The next 3 lines would run DaemonMode and tell it run your script(s) at 1am, 2am, and 3am. Assuming no issues with stdin/stdout running under cron, I think that would do what you want.
I also have no clue if the cron program you are usingunderstands â@rebootâ that is a fairly new and probably non standard extension to cron.
1 Like
Thanks you for considering my package. The code from @pixel27 is right, you can use it directly in the crontab. I personally use a small script âjclientâ that is actually:
#!/bin/bash
julia -e âusing DaemonMode; runargs()â *
to make more easy to run, to use Daemon I simple change âjulia script.jlâ to âjclient script.jlâ.
I actually does not use it with cron, but il should be run without any problem.
I have never use â@rebootâ, however. If that option is not working I suggest to have the following crontab:
30 0 * * * julia --startup-file=no -e 'using DaemonMode; serve()'
0 1 * * * julia --startup-file=no -e 'using DaemonMode; runargs()' path/to/script1.jl <arguments>
0 2 * * * julia --startup-file=no -e 'using DaemonMode; runargs()' path/to/script2.jl <arguments>
0 3 * * * julia --startup-file=no -e 'using DaemonMode; runargs()' path/to/script3.jl <arguments>
0 4 * * * julia --startup-file=no -e 'using DaemonMode; sendExitCode()'
I have add a line before all script starting the server, and after running all script you can add the line julia --startup-file=no -e âusing DaemonMode; sendExitCode()â
to close the server. You should assure that it is run only when the last script has finished.
1 Like