Open BourneSuper opened 5 months ago
Hi,
how to deubg
What are you going to debug? Like code execution?
how to log variables
Did you mean logging variables with njs or access Unit variables with njs?
how to share data between every requests
No such features yet, could you share more about the requirement?
it's complicated to update js_modules.
Indeed, similar to tls section, it was discussed here. https://github.com/nginx/unit/issues/195 For now, there is no clear better way on it. But we plan to make them easier to use.
Hi,
how to deubg
What are you going to debug? Like code execution?
how to log variables
Did you mean logging variables with njs or access Unit variables with njs?
how to share data between every requests
No such features yet, could you share more about the requirement?
it's complicated to update js_modules.
Indeed, similar to tls section, it was discussed here. #195 For now, there is no clear better way on it. But we plan to make them easier to use.
1 & 2 : debug and logging help to konw if a njs script was working or at which line it was stucked.
- it's complicated to update js_modules already used
If you use the unitc
command line tool to edit a js_module, it will do the necessary steps for you.
$ unitc /js_modules/foo edit
1 & 2 : debug and logging help to konw if a njs script was working or at which line it was tucked.
I would suggest you try it and let me know if we missed something on it.
If the JS doesn't work, there is error message thrown like js exception: ...
.
- it's complicated to update js_modules already used
If you use the
unitc
command line tool to edit a js_module, it will do the necessary steps for you.$ unitc /js_modules/foo edit
It is s useful tool. It starts nano editor. Can it start vim editor?
1 & 2 : debug and logging help to konw if a njs script was working or at which line it was tucked.
I would suggest you try it and let me know if we missed something on it. If the JS doesn't work, there is error message thrown like
js exception: ...
.
It can throw a exception when error occurs. If there was no syntax error, how could I know if a variable was assigned a right value. I there a funtion like r.log in nginx?
how could I know if a variable was assigned a right value.
What does variable
mean here, could you show an example?
I there a funtion like r.log in nginx?
Unit hasn't introduced the request object r
yet, we'll extend the njs module features, but it's not clear yet for now.
how could I know if a variable was assigned a right value.
What does
variable
mean here, could you show an example?I there a funtion like r.log in nginx?
Unit hasn't introduced the request object
r
yet, we'll extend the njs module features, but it's not clear yet for now.
A variable is a type of one certain programming language. Its value can change during codes running.
For javascript,var count = 0;
count is a variable.
[unitc] is a useful tool. It starts nano editor. Can it start vim editor?
Yes,
$ unitc --help | grep -i edit
EDIT # Opens the URI contents in $EDITOR
Set the EDITOR
environment variable to vim
.
[unitc] is a useful tool. It starts nano editor. Can it start vim editor?
Yes,
$ unitc --help | grep -i edit EDIT # Opens the URI contents in $EDITOR
Set the
EDITOR
environment variable tovim
.
I don't unstand the help description. cmdline params often start with - or --
sudo unitc /js_modules/util vim
unitc: ERROR: Invalid option (vim)
sudo unitc /js_modules/util vi
unitc: ERROR: Invalid option (vi)
sudo unitc vim /js_modules/util
unitc: ERROR: Invalid option (vim)
sudo unitc EDITOR=vim /js_modules/util
unitc: ERROR: Invalid option (EDITOR=vim)
sudo unitc $EDITOR=vim /js_modules/util
unitc: ERROR: Invalid option (=vim)
sudo unitc EDIT=vim /js_modules/util
unitc: ERROR: Invalid option (EDIT=vim)
Try this
export EDITOR=vim
sudo unitc /js_modules/util edit
Note that edit
is one of the general options to unitc
which does not require a -
prefix. You can think of edit
like other HTTP methods used by the Unit Control API (e.g. GET, DELETE, PUT).
Try this
export EDITOR=vim sudo unitc /js_modules/util edit
Note that
edit
is one of the general options tounitc
which does not require a-
prefix. You can think ofedit
like other HTTP methods used by the Unit Control API (e.g. GET, DELETE, PUT).
this environment variable didn't work. '''shell echo $EDITOR vim ''' I tried vim, Vim, vi, Vi. It still started with nano editor.
this environment variable didn't work. '''shell echo $EDITOR vim ''' I tried vim, Vim, vi, Vi. It still started with nano editor.
Very strange. This is how the tool determines which editor to use. You will see it does not assume nano, in fact it falls back to vi as a last resort. https://github.com/nginx/unit/blob/master/tools/unitc#L258
What is the result of this command in a bash shell?
test "$EDITOR" && printf '%s' "$EDITOR" || command -v editor || command -v vim || echo vi
Does it change when you run with sudo
?
this environment variable didn't work. '''shell echo $EDITOR vim ''' I tried vim, Vim, vi, Vi. It still started with nano editor.
Very strange. This is how the tool determines which editor to use. You will see it does not assume nano, in fact it falls back to vi as a last resort. https://github.com/nginx/unit/blob/master/tools/unitc#L258
What is the result of this command in a bash shell?
test "$EDITOR" && printf '%s' "$EDITOR" || command -v editor || command -v vim || echo vi
Does it change when you run with
sudo
?
I debugged this shell script. $EDITOR
is empty. It can't get $EDITOR
in the first line. So it fallbacked to command -v editor
and started nano.
if I wrote a new test script, $EDITOR
equals 'vim'. Something wrong with unitc but I don't know where.
Fortunately, it's not C language, so I can modify it to this."
EDITOR=$(test command -v vim || echo vi)
With sudo you can try either of the following arguments to preserve the environment
-E, --preserve-env Indicates to the security policy that the user wishes to pre‐ serve their existing environment variables. The security pol‐ icy may return an error if the user does not have permission to preserve the environment.
--preserve-env=list Indicates to the security policy that the user wishes to add the comma-separated list of environment variables to those pre‐ served from the user's environment. The security policy may return an error if the user does not have permission to pre‐ serve the environment. This option may be specified multiple times.
With sudo you can try either of the following arguments to preserve the environment
-E, --preserve-env Indicates to the security policy that the user wishes to pre‐ serve their existing environment variables. The security pol‐ icy may return an error if the user does not have permission to preserve the environment.
--preserve-env=list Indicates to the security policy that the user wishes to add the comma-separated list of environment variables to those pre‐ served from the user's environment. The security policy may return an error if the user does not have permission to pre‐ serve the environment. This option may be specified multiple times.
That's right.
sudo -E unitc /js_modules/util edit
or
su root
unitc /js_modules/util edit
Sorry for the extra steps @BourneSuper - I was testing with macOS which seems to inherit $EDITOR
with sudo(8).
If you are creating a configuration in a local development environment, you may find it more convenient to start unitd
with a TCP control socket so that you don't need to use sudo(8) to access the control API.
Use the unitd --control
option from the command line, or for Linux-systemd systems add something like this to /etc/default/unit
DAEMON_ARGS="--control 127.0.0.1:8081"
The unitc
tool will discover the control socket automatically.
hi,
unit version: 1.31.1
i have some questions about scripting:
a. delete 'settings' in config b. delete js_modules c. update js_modules d. update config