Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wlatendresse opened this issue Jan 31, 2017 · 11 comments

Comments

@wlatendresse
Copy link

wlatendresse commented Jan 31, 2017

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
Copy link
Author

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
Copy link
Contributor

dbriba commented Feb 12, 2017

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 function_name 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
Copy link

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 -

  • startup hook = at the very start of conky lifetime
  • shutdown hook = at the very end of conky lifetime
  • lua_draw_hook_pre = at every iteration BEFORE a conky window is drawn - means each time conky is triggered to process and show results which includes all exec set of calls or saved
  • lua_draw_hook_post = at every iteration AFTER a conky window is drawn - means each time conky is triggered to process and show results which includes all exec set of calls or saved

@dbriba
Copy link
Contributor

dbriba commented Feb 12, 2017

Ok plikhari, I know that.
I test also lua_draw_hook_pre, but with that, lua download five time same file (see here : #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
Copy link

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
Copy link
Contributor

dbriba commented Feb 14, 2017

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
Copy link

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
Copy link
Contributor

dbriba commented Feb 17, 2017

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

@lasers
Copy link
Contributor

lasers commented Aug 13, 2018

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

@plikhari
Copy link

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
Copy link
Contributor

lasers commented Aug 14, 2018

@plikhari Thank you for testing this. 😍 🔥

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. 🤕 I'll file an issue shortly. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants