SOLVED Jail - Problem with startup scripting

TiagoShadow

Cadet
Joined
Dec 15, 2021
Messages
7
Hi Everyone,

I've recently installed TrueNAS on my server, it was previously a Windows machine for general Game Servers and NodeJs Web App, but I wanted to have a personal cloud service so I decided to try this, so I'm recently new to TrueNas and unexperienced when it comes to Linux.

I was able to configure and set up Nextcloud with localstorage and a mountpoint to a windows shared dataset, so I could access my cloud folders from the network, there was a lot of documentation and videos explaining.
But when it comes to NodeJS there is no almost nothing online, I've created a default jail, and installed node and npm packages to it. I wanted to run nodejs server from a folder inside nextcloud, I was able to do achieve, the only setback was since the I've these folders also shared with windows network, I cannot install node modules in those folders, only globally
So all I had to do to start Node was to 'envset' the path to Nodejs global modules, and then I could run my nodejs app with no problems in shell, but if I close the window my server closes and when I open the shell again the 'envset' I've created is gone. I've looked and the solution for this was to create a rc script

I've created the following script and saved it on '/ect/rc.d' folder, but it does not work. When I restart the jail nothing happens...

2021-12-16 005707.png
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
Try this as /usr/local/etc/rc.d/node:
Code:
#!/bin/sh
#
# PROVIDE: node
# KEYWORD: shutdown
#
# Add the following to /etc/rc.conf[.local] to enable this service
#
# node_enable="YES"
#

. /etc/rc.subr

: ${node_enable="NO"}

name=node
rcvar="node_enable"

start_cmd="node_start"
stop_cmd="/usr/bin/true"

node_start()
{
        if ! checkyesno node_enable ; then
                return 0
        fi

        export NODE_PATH="/usr/local/lib/node_modules:/usr/local/bin/node:/media/Vision/visionOS/app.js"
}


load_rc_config ${name}
run_rc_command "$1"


Also remember to chmod +x /usr/local/etc/rc.d/node and sysrc node_enable="YES".
 

TiagoShadow

Cadet
Joined
Dec 15, 2021
Messages
7
Try this as /usr/local/etc/rc.d/node:
Code:
#!/bin/sh
#
# PROVIDE: node
# KEYWORD: shutdown
#
# Add the following to /etc/rc.conf[.local] to enable this service
#
# node_enable="YES"
#

. /etc/rc.subr

: ${node_enable="NO"}

name=node
rcvar="node_enable"

start_cmd="node_start"
stop_cmd="/usr/bin/true"

node_start()
{
        if ! checkyesno node_enable ; then
                return 0
        fi

        export NODE_PATH="/usr/local/lib/node_modules:/usr/local/bin/node:/media/Vision/visionOS/app.js"
}


load_rc_config ${name}
run_rc_command "$1"


Also remember to chmod +x /usr/local/etc/rc.d/node and sysrc node_enable="YES".

It did not work, 'syrc' and 'export' commands do not exist, never the less I've tried it, didn't work, changed from export to setenv, did not work, tried in the both '/etc/rc.d' and '/usr/local/etc/rc.d' which the latter did not exit in my system so I've created the folder, didn't work
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
Did you do this on the host or inside the plugin?
 

TiagoShadow

Cadet
Joined
Dec 15, 2021
Messages
7
I'm not sure if its diferent or not, again, new to this, but I don't have a plugin for this, only a jail
I did it inside the jail, that's where I've node installed and have it working when I open shell and execute node, the if I close the jail shell it shuts down the node js server
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
OK, then you don't need a start script. You'll need to modify the NodeJS launcher script to include export NODE_PATH="/usr/local/lib/node_modules:/usr/local/bin/node:/media/Vision/visionOS/app.js".
 

TiagoShadow

Cadet
Joined
Dec 15, 2021
Messages
7
OK, then you don't need a start script. You'll need to modify the NodeJS launcher script to include export NODE_PATH="/usr/local/lib/node_modules:/usr/local/bin/node:/media/Vision/visionOS/app.js".
The script to launch NodeJS is the one that I posted here originally

2021-12-16 005707.png


this was suppose to run when the jail started, and first line is to set the environment path 'NODE_PATH' to 'user/local/lib/node_modules' and the next line is to run node.js '/usr/local/bin/not /media/Vision/visionOS/app.js' starts the node server.
This is basically what I do when I open the jail shell to start the server, but it closes if I close the jail shell window, I needed this to run on start of the jail, even if the shell was not opened.

I'm sorry if I did not explain it well on the first post
 

TiagoShadow

Cadet
Joined
Dec 15, 2021
Messages
7
Hi,

Just wanted to share that I was able to fix the issue, in a desperate developer move I looked into other codes in the folder /rc.d and saw what they had, so I experimented with adding and removing stuff until it worked.

The result:
#!/bin/sh # # PROVIDE: node # KEYWORD: shutdown # REQUIRE: DAEMON # # Add the following to /ect/rc.conf[.local] to enable this service # # node_enable="YES" . /etc/rc.subr name="node" desc="NodeJS Server" rcvar="node_enable" start_cmd="node_start" stop_cmd=":" node_start() { export NODE_PATH="/usr/local/lib/node_modules:/usr/local/bin/node:/media/Vision/visionOS/app.js" exec /usr/local/bin/node /media/Vision/visionOS/app.js } load_rc_config ${name} run_rc_command "$1"
I'm not sure if it is the line Require that makes the script run a bit later in the lifecycle of the jail fixed it, or the removal of ': ${node_enable="NO"}' makes the diference
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
Glad you figured it out yourself.
 
Top