brndnmtthws / conky

Light-weight system monitor for X, Wayland (sort of), and other things, too
https://conky.cc
GNU General Public License v3.0
7.17k stars 615 forks source link

Changed lua script is reloaded however lua_startup_hook is not called again #366

Closed wlatendresse closed 6 years ago

wlatendresse commented 7 years ago

This issue is pretty annoying when writing new lua scripts which use the startup hook to set things up. When a script changes, conky (lua?) will load the new version upon save but the startup hook will NOT be called once again, therefore is is always necessary to restart conky after some changed to a script (at least in my version which is debian's testing version 1.10.6)

wlatendresse commented 7 years ago

So I just figured out that it is possible to 'rewrite' the conky config file which will trigger a restart. Therefore this issue is not that important ... Maybe I'll try to fix it as soon as I install the git version of conky.

dbriba commented 7 years ago

I have same problem with lua_startup_hook. I have a script lua :

function conky_main()
  os.execute("/home/dominique/.conkyrc/conky-1.10/conky-meteo/conky-londres-2/3b")
  end

And I call it in my conky with:

lua_load = '/home/dominique/.conkyrc/conky-1.10/conky-meteo/conky-londres-2/weather.lua',
lua_startup_hook = 'main

In the doc I can see:

This function, if defined, will be called by Conky at startup or when the configuration is reloaded.
Use this hook to initialize values, or for any run-once applications. Conky puts 'conky_' in front of functionname to prevent accidental calls to the wrong function unless you place 'conky' in front of it yourself.

The problem is the script is not relaunched when conky is reloaded (in my case it is every 600 seconds).

The script is just launch one time when I launch my conky, and it's all.

It is normal or it's a bug ?

plikhari commented 7 years ago

The startup hook is working as designed. It is called the very first time conky is started - it will not be called on save or on any of the exec set of calls.

Perhaps you are using an incorrect hook - you should be using lua_draw_hook_pre.

Just a recap -

dbriba commented 7 years ago

Ok plikhari, I know that. I test also lua_draw_hook_pre, but with that, lua download five time same file (see here : https://github.com/brndnmtthws/conky/issues/358 ), and it is not admissible for me.

When I used conky 1.9, the pre_exec variable made the job, without problem. Why did they remove this option ? ( it was so simple and useful! )

All of conky's users are not able to write a lua-script.

plikhari commented 7 years ago

OK - I am the developer of conkywx [a fantastic weather program] and since 2013 - I have used lua to exceed the boundaries of what is normally possible with vanilla conky. As of now I am in the process of releasing conkywx SIX - just sorting out one of the templates - which is playing hard to get lol

All of conky's users are not able to write a lua-script.

I have absolutely no issues with writing lua scripts - so what is it that I am doing different ??

Try this - create a bash script - you use this to launch or restart conky. To background a conky process you can use a -d option or place & at the end of the line. This gives a very flexible way to get a fresh conky start while you can mess around with lua or which ever scripting you prefer to use. I have always used this method way before I started using lua with conky. The main engine for conkywx is in perl - lua is just for the conky end of it.

You can run this script from a terminal or bind it to a key sequence etc

#!/bin/bash

if [[ $(pidof conky) ]] ; then killall -SIGUSR1 conky; fi

conky -c directory name/conky config name &

exit

Now regarding pre_exec - you can write a simple script in lua - OR - give a larger time interval to the (t)exec(p)(i) set of calls - 6 hours or 24 hours - you get the same result. The process is run once over an interval - which could be the lifetime of the process or a large enough time that it really would not matter if the process was restarted.

dbriba commented 7 years ago

Give a large interval don't make the job for me. You say "Now regarding pre_exec - you can write a simple script in lua". Okay, but how ? Have you an example ?

plikhari commented 7 years ago

Can you please share the code - what you want to achieve - perhaps I can then see - there may be yet another way to reach your goal.

Please include from start to finish when you expect your data displayed.

dbriba commented 7 years ago

Thank for your post, but I try other thing, and that work (with crondtab). It close my issue.

lasers commented 6 years ago

What's the status of this issue? Thank you.

plikhari commented 6 years ago

I am testing 1.10.9_pre - and lua_startup_hook is working as designed. The hook will only trigger at the first start of that conky resource or if that resource file is edited and saved.

This issue should be closed.

lasers commented 6 years ago

@plikhari Thank you for testing this. :heart_eyes: :fire:

This seems to working okay here for me too... as designed.

file: write_to_file.conf

conky.config = {
    out_to_x=false,
    out_to_console=true,
    lua_load = '~/conky/write_to_file.lua',
    lua_startup_hook = 'write',
}
conky.text = [[
    ${exec date}
]]

file: write_to_file.lua

function conky_write()
    os.execute("date >> /tmp/date.log")
end

$ tail -f /tmp/date.log

It also seems like there were several issues that was simply solved by upgrading to at least 1.10.8. This might be one of them. Whatever it was, it's gone now. Anyhow, we'll close this now. Thank you.

I triggered a new bug testing this too. :face_with_head_bandage: I'll file an issue shortly. :wink: