GusGold / FreeNASTempsGUI

Updates FreeNAS generated code for temperature graphs in GUI
MIT License
6 stars 0 forks source link

Oh dear dit i do something wrong ? parse error. #1

Closed spacecabbie closed 6 years ago

spacecabbie commented 7 years ago

I get the following error when i run "npm i"

full log output below

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'i' ]
2 info using npm@5.4.2
3 info using node@v8.5.0
4 verbose npm-session 832cfb80980f4d0b
5 silly install runPreinstallTopLevelLifecycles
6 silly install loadCurrentTree
7 silly install readLocalPackageData
8 verbose stack Error: Failed to parse json
8 verbose stack Unexpected token } in JSON at position 602 while parsing near '...ASTempsGUI.git"
8 verbose stack         },
8 verbose stack }
8 verbose stack '
8 verbose stack     at parseError (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:436:11)
8 verbose stack     at parseJson (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:104:26)
8 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:51:5
8 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
8 verbose stack     at tryToString (fs.js:514:3)
8 verbose stack     at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:502:12)
9 verbose cwd /usr/local/freenastemp
10 verbose FreeBSD 11.0-STABLE
11 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "i"
12 verbose node v8.5.0
13 verbose npm  v5.4.2
14 error file /usr/local/freenastemp/package.json
15 error code EJSONPARSE
16 error Failed to parse json
16 error Unexpected token } in JSON at position 602 while parsing near '...ASTempsGUI.git"
16 error        },
16 error }
16 error '
17 error File: /usr/local/freenastemp/package.json
18 error Failed to parse package.json data.
18 error package.json must be actual JSON, not just JavaScript.
18 error
18 error Tell the package author to fix their package.json file. JSON.parse
19 verbose exit [ 1, true ]
GusGold commented 7 years ago

Fixed this previously but never committed. npm i should work now

spacecabbie commented 7 years ago

Awesome i think i got it working one question though in the injectTempGUI.sh on line 4 it links to the jail nginx.conf since it was not created there i cp the original from the main system is that correct ? Ifso may i suggest you ad that step in the read me ?

GusGold commented 7 years ago

Ahh, sorry that wasn't clear.

On line 8, it copies across the file into the jail at the path specified at line 4, and then once the conf is updated, it copies it back on line 13

You shouldn't need to create the file initially, but it won't make a difference if you did.

spacecabbie commented 7 years ago

Awesome nice little script thanks ! wiert its not default in freenas to monitor temps though.

GusGold commented 7 years ago

I know right, seems like such a basic thing!

I'm also working on adding updating for the FreeNAS UI too (step 4) as that is overwritten when FreeNAS is updated.

spacecabbie commented 7 years ago

Roger i put a watch on update of this project :)

spacecabbie commented 7 years ago

Hi just a small update the script runs fine but the conf file reverted nonetheless today. Output:

root@FileServer:~ # /root/scripts/injectTempGUI.sh
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Stopping nginx.
Waiting for PIDS: 90912.
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
root@FileServer:~ #

Any idea how i could go about troubleshooting this ?

GusGold commented 7 years ago

Hmm. You've got your cron job set up, right? When you ran the above output, did it update the conf for you? If you run it again, does it restart nginx again, or does it finish with No need to update?

spacecabbie commented 7 years ago

Yea the cron job is setup when i run it repeatedly it keeps doing that. no changes are written but it dus restarts nginx

root@FileServer:~ # /root/scripts/injectTempGUI.sh
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Stopping nginx.
Waiting for PIDS: 41217.
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
root@FileServer:~ # /root/scripts/injectTempGUI.sh
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Stopping nginx.
Waiting for PIDS: 44022.
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
root@FileServer:~ # /root/scripts/injectTempGUI.sh
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Stopping nginx.
Waiting for PIDS: 44127.
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
root@FileServer:~ # /root/scripts/injectTempGUI.sh
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Stopping nginx.
Waiting for PIDS: 44158.
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
root@FileServer:~ #
GusGold commented 7 years ago

Sorry for the delay.

Hmm, can you please try updating to this index.js. I don't think the updated nginx config was being written to disk before being copied back to your actual nginx.conf.

spacecabbie commented 7 years ago

Thats ok i am not in a hurry. Exact same out put though :( I did remove the conf file on the jail to see if the script would make it this time it game a error the html file was not there so i made a blank one. no error on the conf file and it was also not created in the jail dir.

root@FileServer:~ # /root/scripts/injectTempGUI.sh
Adding to UI Template
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Stopping nginx.
Waiting for PIDS: 62871.
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
root@FileServer:~ # /root/scripts/injectTempGUI.sh
Adding to UI Template
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Stopping nginx.
Waiting for PIDS: 70647.
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
spacecabbie commented 7 years ago

Hi i was busy so it took me a while to look at this problem again it seems the error is in index.js when i run it standalone in the jail it gives me:

root@nzbget:/usr/local/freenastemp # ./index.js ./index.js: 1: Syntax error: "(" unexpected

GusGold commented 7 years ago

You'll have to run it as node ./index.js, but it'll need the index.html from the reports page and the nginx.conf file to run properly.

Can you paste your FREENASUI and FREENASUIJAIL paths that are in injectTempGUI.sh (lines 5-6) along with your FREENASUI file. I'm guessing it isn't pointing to the correct file.

spacecabbie commented 7 years ago

injectTempGUI.sh file: `

!/bin/bash

NGINX=/usr/local/etc/nginx/nginx.conf #Path of nginx.conf on your FreeNAS System NGINXJAIL=/mnt/BlackHole/jails/nzbget/usr/local/freenastemp/nginx.conf #Path of temporary nginx.conf in jail (relative to FreeNAS, not jail) FREENASUI=/usr/local/www/freenasUI/templates/reporting/index.html #Path of UI Template on FreeNAS FREENASUIJAIL=/mnt/BlackHole/jails/nzbget/usr/local/freenastemp/index.html #Path of temporary UI Template in jail (relative to FreeNAS, not jail) JAIL=nzbget #Name of your jail (Jails->Jails in FreeNAS UI list the names) JAILSCRIPT=/usr/local/freenastemp/index.js #Path of node script (relative to jail)

cp $NGINX $NGINXJAIL; cp $FREENASUI $FREENASUIJAIL; chmod o+rw $NGINXJAIL; chmod o+rw $FREENASUIJAIL; jexec $JAIL node $JAILSCRIPT; ECODE=$? if [ $ECODE -eq 0 ]; then cp $NGINXJAIL $NGINX && cp $FREENASUIJAIL $FREENASUI && rm $NGINXJAIL && rm $FREENASUIJAIL && service nginx restart exit $?; elif [ $ECODE -eq 1 ]; then echo "No need to update"; exit 0; else echo "Error" >&2; exit $ECODE; fi ` index.html https://pastebin.com/uVNA0c04

fyi only the nginx part seems to fail cause the script did detect the index.html pard i had this issue before you updated to include the index.html edit.

GusGold commented 7 years ago

Ah ha, okay, so!

That index.html file should be sitting in the same directory as your graphs output. The index.html file that should be at /usr/local/www/freenasUI/templates/reporting/index.html is the one generated by FreeNas/Dojo and looks something like (on FreeNAS-11.0-U4 (54848d13b)):

<div data-dojo-type="dijit.layout.TabContainer" data-dojo-props="nested:true, title: '{% trans "Reporting"|escapejs %}', doLayout: true" style="width: 100%;">
  <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title: '{% trans "CPU" %}', href: '{% url "reporting_cpu" %}', refreshOnShow: true"></div>
  <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title: '{% trans "Disk" %}', href: '{% url "reporting_disk" %}', refreshOnShow: true"></div>
  <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title: '{% trans "Memory" %}', href: '{% url "reporting_memory" %}', refreshOnShow: true"></div>
  <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title: '{% trans "Network" %}', href: '{% url "reporting_network" %}', refreshOnShow: true"></div>
  <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title: '{% trans "Partition" %}', href: '{% url "reporting_partition" %}', refreshOnShow: true"></div>
  <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title: '{% trans "System" %}', href: '{% url "reporting_system" %}', refreshOnShow: true"></div>
  <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title: '{% trans "Target" %}', href: '{% url "reporting_target" %}', refreshOnShow: true"></div>
  <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title: '{% trans "ZFS" %}', href: '{% url "reporting_zfs" %}', refreshOnShow: true"></div>
</div>

So, my suggested fix is to:

  1. Move /usr/local/www/freenasUI/templates/reporting/index.html to where rdd-graph.sh is generating your graphs.
  2. Update line 10 in index.js to be the directory you just moved index.html to in step 1.
  3. Replace /usr/local/www/freenasUI/templates/reporting/index.html with the code block above (hopefully you're on a similar enough version, or maybe FreeNAS will regenerate it for you).
spacecabbie commented 7 years ago

Fair point i'll have to double check that but the problem i am having is the nginx.conf is not being updated. nevertheless i shall apply above fix.

GusGold commented 6 years ago

How'd you go with this @spacecabbie?