running node.js server using upstart causes 'terminated with status 127' on 'ubuntu 10.04'
127 in bash means: "command not found", illegal_command, possible problem with $PATH or a typo.
Source: http://tldp.org/LDP/abs/html/exitcodes.html
This might be a question for server fault, as it is bash related, but this question / answer might help you:
https://serverfault.com/questions/277706/cron-fails-with-exit-status-127
AWS Lambda Node.js 10.x Runtime error with selenium-webdriver
We recently faced the exact same issue. After upgrading to AWS Lambda Node v10.x from Node v8.x, chrome and chromedriver stopped working. In short, the root cause is that Lambda Node 10.x runs on Amazon Linux 2 Vs Lambda Node v8 which runs on Amazon Linux. Amazon Linux 2 lacks a number of packages comparing to it's predecessor, making it more lightweight but at the same time a pain in case you want to set up a custom runtime environment. Before I give you the steps to resolve this, let me first highlight a few useful links that helped me find the right set of binaries I had to also include in my lambda deployment package.
Just remember! The way to resolve this is to figure out which binaries are missing from your Lambda deployment package and add them in.
- How to use Amazon Linux native binary packages in an AWS Lambda deployment package. Once you know you are missing some binaries in your Lambda environment, this link from AWS will help you include them into your package. For my purpose I used an EC2 Amazon Linux 64 bit AMI to download the packages and extract them. Detailed steps follow... https://aws.amazon.com/premiumsupport/knowledge-center/lambda-linux-binary-package
- Besides binaries missing from Amazon Linux 2, there are also no fonts installed. This link will tell you how to install fonts on AWS Lamda. One of the reasons Chrome fails to run on Lambda is the lack of fonts.
https://forums.aws.amazon.com/thread.jspa?messageID=776307 - This is a nice issue thread on github that taught me that the order of paths in the LD_LIBRARY_PATH environment variable matters. This is the environment variable that holds the paths where your binaries are in. https://github.com/alixaxel/chrome-aws-lambda/issues/37
- Now this is a game changer. Without the amazing docker container lambci created simulating AWS Lambda to as close as it can be, I would have never figured it out. After trying all sorts of things between an Amazon Linux 2 EC2 server and AWS Lambda, this ended up being my playground, where I could iterate trying different packages very quickly. https://hub.docker.com/r/lambci/lambda/
- Running Arbitrary Executables in AWS Lambda. Some helpful link if you want to run an executable directly on lambda and see how it behaves. The error messages you see from selenium-webdriver package are actually not surfacing the real error that chrome or chromedriver throws. Trying to directly run chrome or chromedriver in the lambci docker container is how I managed to debug this and figure out which binaries were missing. https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/
So, here is what you need to do:
- Launch an Amazon Linux 2 64 bit server. A t3.micro should be enough.
- SSH to the machine and install rmpdevtools:
sudo yum install -y yum-utils rpmdevtools
- Create a temporary directory for downloading the missing packages:
cd /tmp
mkdir lib
cd lib
- Download the RPM packages missing in AWS Lambda node v10.x:
yumdownloader --resolve GConf2 glibc glib2 libblkid libffi libgcc libmount libsepol libstdc++ libuuid pcre zlib libselinux dbus-glib mozjs17 polkit polkit-pkla-compat libX11 libX11-common libXau libxcb fontconfig expat fontpackages-filesystem freetype stix-fonts gnu-free-sans-fonts fontpackages-filesystem gnu-free-fonts-common nss nspr nss-softokn nss-softokn-freebl nss-util dbus-libs audit-libs bzip2-libs cracklib elfutils-libelf elfutils-libs libattr libcap libcap-ng libcrypt libdb libgcc libgcrypt libgpg-error libsepol lz4 pam systemd-libs xz-libs mesa-libOSMesa-devel mesa-libOSMesa mesa-libglapi sqlite
- Extract the RPM packages:
rpmdev-extract *rpm
- Create some temporary location for copying the binaries from the extracted RPM artifacts:
sudo mkdir -p /var/task
sudo chown ec2-user:ec2-user /var/task
cd /var/task
mkdir lib
mkdir fonts
- Copy the extracted binaries to the new temporary location:
/bin/cp /tmp/lib/*/usr/lib64/* /var/task/lib
/bin/cp /tmp/lib/*/lib64/* /var/task/lib
/bin/cp /tmp/lib/*/usr/share/fonts/*/*.ttf /var/task/fonts
- Zip the artifacts:
zip -r ./lib.zip ./*
- Download them from the server extract the zip and include your lambda handler. At this point you should have a very similar structure like the one you had with some more binaries in your lib folder and a new fonts folder.
- Include the following config file "fonts.conf" in your /var/task/fonts folder:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/var/task/fonts/</dir>
<cachedir>/tmp/fonts-cache/</cachedir>
<config></config>
</fontconfig>
- Add the following code snippet in your lambda handler. This will set the right order of include paths for the LD_LIBRARY_PATH environment variable and will also set the FONTCONFIG_PATH to the new /var/task/fonts directory.
process.env.FONTCONFIG_PATH = `${process.env.LAMBDA_TASK_ROOT}/fonts`;
if (process.env.LD_LIBRARY_PATH.startsWith("/var/task/lib:") !== true) {
process.env.LD_LIBRARY_PATH = [...new Set(["/var/task/lib", ...process.env.LD_LIBRARY_PATH.split(':')])].join(':');
}
- Download locally lambci/lambda image.
docker pull lambci/lambda
- Debug your lamda handler by running a lambci image like this:
docker run --rm -v "$THE_LOCAL_DIR_OF_YOUR_UNCOMPRESSED_LAMDA_PACKAGE":/var/task lambci/lambda:nodejs10.x index.handler
- Iterate steps 7 to 14 until you get it working on the lambci container. With the given RPM packages it should work, but in case it does not, you can debug locally what is going on by trying to launch chrome in your lambda like this:
const childProcess = require('child_process');
childProcess.execFileSync(`${process.env.LAMBDA_TASK_ROOT}/lib/chrome`);
This is a cumbersome process, but at the end of the day, all you are doing is just adding some more binaries into your package and 3 lines of code in your handler to update the lib and fonts environment variables.
Just in case, adding below as well the chrome flags we are using:
const defaultChromeFlags = [
"--headless",
"--disable-gpu",
"--window-size=1280x1024",
"--no-sandbox",
"--user-data-dir=/tmp/user-data",
"--hide-scrollbars",
"--enable-logging",
"--v=99",
"--single-process",
"--data-path=/tmp/data-path",
"--ignore-certificate-errors",
"--homedir=/tmp",
"--disk-cache-dir=/tmp/cache-dir"
];
Good luck!
Chromedriver won't launch headlessly with Protractor tests (error 199)
I added something in my Protractor configuration file that solved the problem:
capabilities: {
'browserName': 'chrome',
// NEW
'chromeOptions': {
args: ["--headless", 'no-sandbox', "--disable-gpu", "--window-size=800x600"]
}
},
The tests launch. They get another error (they dont plug to the Xvfb). But this one is another story...
How to exit in Node.js
Call the global process
object's exit
method:
process.exit()
From the docs:
process.exit([exitcode])
Ends the process with the specified
code
. If omitted, exit with a 'success' code0
.To exit with a 'failure' code:
process.exit(1);
The shell that executed node should see the exit code as
1
.
Related Topics
String Comparison Not Working Properly
Bash Echo with an $ Character Outside the String
Writing a Program for Hiding Processes from Ps Command Result
When to Use Pipes VS When to Use Shared Memory
Execute a Shell Script Everyday at Specific Time
How to Mount from Command Line Like the Nautilus Does
Linux Rename Files to Uppercase
Is There Any Method to Run Perf Under Wsl
In Bash, Why 'X=100 Echo $X' Doesn't Print Anything
Ftdi D2Xx Conflict with Ftdi_Sio on Linux - How to Remove Ftdi_Sio Automatically
Explicitly Invoke Sig_Dfl/Sig_Ign Handlers on Linux
Trying to Ping Linux Vm Hosted on Azure Does Not Work
View a Log File in Linux Dynamically