ยง2024-08-18

  1. install requirements
sudo apt install -y curl build-essential graphicsmagick
  1. Download and extract the latest release of Rocket.Chat.
alexlai@hc4Noble:~$ curl -L https://releases.rocket.chat/latest/download -o ~/build/src/rocket.chat.tgz
# Extract the Rocket.Chat server files using these commands:

alexlai@hc4Noble:~$ tar -xzvf ~/build/src/rocket.chat.tgz -C /tmp

alexlai@hc4Noble:~$ ls ~/build/bundle/
main.js  programs  README  server  star.json
  1. the latest using Engine versions Node: 14.21.3 MongoDB: 4.4, 5.0, 6.0 Apps-Engine: 1.44.0
$ fnm install 14.21.3
$ fnm default 14.21.3
$ npm --version
6.14.18
$ npx --version
6.14.18
$ node --version
v14.21.3
$ sudo ln -sf /home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/bin/node /usr/bin/node 
alexlai@hc4Noble:/tmp/bundle/programs/server$ sudo ln -sf /home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/bin/npm /usr/bin/npmalexlai@hc4Noble:/tmp/bundle/programs/server$ sudo ln -sf /home/alexlai/.local/share/fnm/node-npx 
  1. npm install
$ $ cd /tmp/bundle/programs/server && npm install --production
npm WARN deprecated node-pre-gyp@0.15.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated npmlog@4.1.2: This package is no longer supported.
npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm WARN deprecated osenv@0.1.5: This package is no longer supported.
npm WARN deprecated gauge@2.7.4: This package is no longer supported.
npm WARN deprecated are-we-there-yet@1.1.7: This package is no longer supported.
npm WARN deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs

> fibers@5.0.1 install /tmp/bundle/programs/server/node_modules/fibers
> node build.js || nodejs build.js

Traceback (most recent call last):
  File "/home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 50, in <module>
    sys.exit(gyp.script_main())
             ^^^^^^^^^^^^^^^^^
  File "/home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 554, in script_main
    return main(sys.argv[1:])
           ^^^^^^^^^^^^^^^^^^
  File "/home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 547, in main
    return gyp_main(args)
           ^^^^^^^^^^^^^^
  File "/home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 520, in gyp_main
    [generator, flat_list, targets, data] = Load(
                                            ^^^^^
  File "/home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 136, in Load
    result = gyp.input.Load(build_files, default_variables, includes[:],
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 2782, in Load
    LoadTargetBuildFile(build_file, data, aux_data,
  File "/home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 391, in LoadTargetBuildFile
    build_file_data = LoadOneBuildFile(build_file_path, data, aux_data,
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 234, in LoadOneBuildFile
    build_file_contents = open(build_file_path, 'rU').read()
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid mode: 'rU' while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:285:12)
gyp ERR! System Linux 6.6.0-odroid-arm64
gyp ERR! command "/home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/bin/node" "/home/alexlai/.local/share/fnm/node-versions/v14.21.3/installation/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--release"
gyp ERR! cwd /tmp/bundle/programs/server/node_modules/fibers
gyp ERR! node -v v14.21.3
gyp ERR! node-gyp -v v5.1.1
gyp ERR! not ok 
node-gyp exited with code: 1
Please make sure you are using a supported platform and node version. If you
would like to compile fibers on this machine please make sure you have setup your
build environment--
Windows + OS X instructions here: https://github.com/nodejs/node-gyp
Ubuntu users please run: `sudo apt-get install g++ build-essential`
RHEL users please run: `yum install gcc-c++` and `yum groupinstall 'Development Tools'` 
Alpine users please run: `sudo apk add python make g++`
sh: 1: nodejs: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! fibers@5.0.1 install: `node build.js || nodejs build.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the fibers@5.0.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/alexlai/.npm/_logs/2024-08-18T21_47_33_131Z-debug.log

  1. Move the extracted files to the /opt directory.
$ sudo mv /tmp/bundle/ /opt/Rocket.Chat
$ ls -l /opt/
total 4
drwxr-xr-x 4 alexlai alexlai 4096 Aug 16 09:47 Rocket.Chat
drwxr-xr-x 3 root    root      21 Aug 18 14:35 xfs
  1. Configure the Rocket.Chat service

Add the rocketchat user and set the right permissions on the Rocket.Chat folder.


alexlai@hc4Noble:~$ sudo useradd -M rocketchat && sudo usermod -L rocketchat # -L lock user account
alexlai@hc4Noble:~$ id rocketchat 
uid=1027(rocketchat) gid=1027(rocketchat) groups=1027(rocketchat)

lexlai@hc4Noble:~$ sudo usermod -aG alexlai rocketchat  #--> to excute node
alexlai@hc4Noble:~$ id rocketchat 
uid=1027(rocketchat) gid=1027(rocketchat) groups=1027(rocketchat),1026(alexlai)

usrmod -L This prevents the user from logging in by disabling their password.

  1. chang ownership of /opt/Rocket.Chat
alexlai@hc4Noble:~$ sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat
alexlai@hc4Noble:~$ ls -l /opt/Rocket.Chat/
total 20
-r--r--r-- 1 rocketchat rocketchat  243 Aug 16 09:47 main.js
drwxr-xr-x 5 rocketchat rocketchat 4096 Aug 16 09:47 programs
-r--r--r-- 1 rocketchat rocketchat  535 Aug 16 09:47 README
drwxr-xr-x 2 rocketchat rocketchat 4096 Aug 16 09:47 server
-r--r--r-- 1 rocketchat rocketchat  602 Aug 16 09:47 star.json
  1. I did install node in /usr/bin skip setting NODE_PATH=$(which node)

  2. /etc/systemd/system/rocketchat.service

[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target nginx.service mongod.service
[Service]
ExecStart=node /opt/Rocket.Chat/main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocketchat
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01
MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01
ROOT_URL=http://localhost:3000/ PORT=3000
[Install]
WantedBy=multi-user.target


npm run postinstall

root@hc4Noble:/home/alexlai# mkdir -p /home/rocketchat/.cache
root@hc4Noble:/home/alexlai# cd /opt/Rocket.Chat/programs/server/npm/node_modules/@rocket.chat/apps-engine
root@hc4Noble:/opt/Rocket.Chat/programs/server/npm/node_modules/@rocket.chat/apps-engine# export DENO_DIR=/home/rocketchat/.cache/deno
root@hc4Noble:/opt/Rocket.Chat/programs/server/npm/node_modules/@rocket.chat/apps-engine# npm install --production
npm warn config production Use `--omit=dev` instead.
npm warn deprecated hoek@6.1.3: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm warn deprecated cryptiles@4.1.3: This module has moved and is now available at @hapi/cryptiles. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm warn deprecated boom@7.3.0: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.

> @rocket.chat/apps-engine@1.44.0 postinstall
> node scripts/postinstall.js

/opt/Rocket.Chat/programs/server/npm/node_modules/@rocket.chat/apps-engine/node_modules/deno-bin/bin/deno: 1: Syntax error: Unterminated quoted string

added 14 packages, and audited 18 packages in 2m

2 packages are looking for funding
  run `npm fund` for details

4 high severity vulnerabilities

To address issues that do not require attention, run:
  npm audit fix

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.

root@hc4Noble:/opt/Rocket.Chat/programs/server/npm/node_modules/@rocket.chat/apps-engine# npm run postinstall

> @rocket.chat/apps-engine@1.44.0 postinstall
> node scripts/postinstall.js

/opt/Rocket.Chat/programs/server/npm/node_modules/@rocket.chat/apps-engine/node_modules/deno-bin/bin/deno: 1: Syntax error: Unterminated quoted string

root@hc4Noble:/opt/Rocket.Chat/programs/server/npm/node_modules/@rocket.chat/apps-engine# chown -R rocketchat:rocketchat /opt/Rocket.Chat/