I get an error when trying to run it:
~/projects/test-app
/usr/local/bin/meteor:3
# This is the script that we install somewhere in your $PATH (as "meteor")
Here is the command I run:
pm2 start meteor-pm2.json
And here is meteor-pm2.json:
{
"name" : "test-app",
"script" : "/usr/local/bin/meteor",
"MAIL_URL":"smtp://yourmail_configuration_here",
"MONGO_URL":"mongodb://localhost:27017/meteor",
"ROOT_URL":"https://www.mysite.com/",
"PORT":"3000",
"out_file":"/home/josh/logs/app.log",
"error_file":"/home/josh/logs/err.log"
}
I also try this:
cat start
#!/bin/bash
MONGO_URL="mongodb://localhost:27017/meteor"
PORT=3000
ROOT_URL="https://www.mysite.com/"
/usr/local/bin/meteor
and I run it with:
pm2 start ./start -x interpreter bash
and I get:
/usr/local/bin/meteor
^
ReferenceError: usr is not defined
when i modify the bash script by adding the export:
#!/bin/bash
export MONGO_URL="mongodb://localhost:27017/meteor"
export PORT=3000
export ROOT_URL="https://www.mysite.com/"
/usr/local/bin/meteor
I get:
export - SyntaxError: Unexpected reserved word
Any ideas what am I doing wrong?
Is pm2 trying to run the bash script in it's own special script interpreter that doesn't allow the use of export?
I believe this process.json syntax is more correct:
{
"apps": [
{
"name": "myAppName",
"script": "./bundle/main.js",
"log_date_format": "YYYY-MM-DD",
"exec_mode": "fork_mode",
"env": {
"PORT": 3000,
"MONGO_URL": "mongodb://127.0.0.1/meteor",
"ROOT_URL": "https://myapp.example.com/",
"BIND_IP": "127.0.0.1"
}
}
]
}
then I just start it using run.sh which contains:
#!/bin/sh
#
# This shell script starts the actual
# app in the production environtment.
#
pm2 start process.json -i max # Enable load-balancer and cluster features
Note: the BIND_IP env var is there to change it from the default (0.0.0.0). The 0.0.0.0 would make the app accessible around the ssl proxy layer (if you use SSL/TLS with nginx or some other web server and the BIND_IP is set to 0.0.0.0 then pretty much anyone could access it via http://myapp.example.com:3000 around the encrypted layer, unless you block that port in your web server's configuration).
This is how I got my meteor app (Telescope) working
ROOT_URL=http://localhost:3000 PORT=3000 MONGO_URL=mongodb://127.0.0.1:27017/Telescope pm2 start main.js
inside .meteor/local/build
Meteor isn't actually running from /usr/local/bin/meteor, that script is only used for bootstrapping etc, that when done redirects to ~/.meteor/meteor
From /usr/local/bin/meteor:
# All this script does is exec ~/.meteor/meteor. But what if you don't have it
# yet? In that case, it downloads a "bootstrap tarball", which contains the
# latest version of the Meteor tools, and plops it down at ~/.meteor. In fact,
# once you've run this once, you don't even really need this script: you can put
# ~/.meteor/ into your PATH, or a symlink to ~/.meteor/meteor into some other
# PATH directory. No special permissions needed!
So what you need to do is change your script pointer to use meteor in your "Warehouse dir" (~/meteor/meteor)
This means that pm2 expects some syntax and finds another in the start script. In order to direct it to the right syntax, add this to your config.json file:
"interpreter" : "bash"
P.S.: addition of this parameter to the command line didn't work
Related
I have a dockerised Nginx server created with openresty base image. When a particular endpoint is called it need to update nginx config dynamically. For the changes to reflect I am trying to reload the nginx soon after the changes in config.
with in the container i am able to reload nginx server using /usr/local/openresty/nginx/sbin/nginx -s reload
when i try to use the same with in lua as below ,It doesn't shoot any error but the config changes aren't getting reflected.
os.execute("/usr/local/openresty/nginx/sbin/nginx -s reload ")
You can skip calling nginx altogether and just send a HUP signal to the master process using LuaJITs FFI.
local process = require 'ngx.process'
local ffi = require 'ffi'
ffi.cdef 'int kill(int pid, int sig);'
ffi.C.kill(process.get_master_pid(), 1)
However, this doesn't fix the permissions problem.
One idea that could work is:
Set up a named pipe with mkfifo and make it so your nginx-user can write to it
Enable the Priviliged Agent worker process.
Set the privileged worker up to listen for input on the named pipe (for example using the ngx.pipe module to open cat and waiting for input) and send a HUP signal to the master process
Change your os.execute code to instead write some line of text into the named pipe to have the privileged agent reload the server.
EDIT: If you dislike the cat hack, you might want to have a look at https://github.com/slact/ngx_lua_ipc
It might be possible to use IPC to keep the whole thing self-contained within a single nginx server instance, without any file access.
This command would be run with nginx worker process privileges, and you need to be a root in order to execute this command. You can try to make a particular script for this (lets assume its name would be /usr/local/openresty/nginx/sbin/reload-nginx.sh:
#!/bin/sh
/usr/local/openresty/nginx/sbin/nginx -s reload
set the owner of this script no nginx process user (lets assume its name is nginx), and set the suid bit on this script
chown nginx /usr/local/openresty/nginx/sbin/reload-nginx.sh
chmod +x /usr/local/openresty/nginx/sbin/reload-nginx.sh
chmod u+s /usr/local/openresty/nginx/sbin/reload-nginx.sh
and try to execute this script from your lua code:
os.execute("/usr/local/openresty/nginx/sbin/nginx-reload.sh")
I'm currently struggling with running a .sh script I'm trying to trigger from Jenkins.
Within the Jenkins "execute shell" section, I'm connecting to a remote server (The Jenkins agent does not have right OS to build what I need.), using:
cp -r . /to/shared/drive/to/have/access/on/remote
ssh -t -t username#servername << EOF
cd /to/shared/drive/to/have/access/on/remote
source build.sh dev
exit
EOF
Inside build.sh, I'm exporting R_LIBS to build a package for different R versions.
...
for path in "${!rVersionPaths[#]}"; do
export R_LIBS="${path}"
Rscript -e 'install.packages(c("someDependency", "someOtherDependency"), repos="http://cran.r-project.org");'
...
Setting R_LIBS should functions here like setting lib within install.packages(...). For some reason the R_LIBS export doesn't get picked up. Also setting other env variables like http_proxy are ignored. This causes any requests outside the network to fail.
Is there any particular way of achieving this?
Maybe pass those variables with env, like
env R_LIBS="${path}" Rscript -e 'install.packages(c("someDependency", .....
Well i'm not able to comment on the question, so posting it as answer.
I had similar problem when calling remote shell script from Jenkins, the problem was somehow bash_profile variables were not loaded when called the script from Jenkins but locally it worked. Loading the bash profile in ssh connection solved it for me.
Add source to bash_profile in build.sh
. ~/.bash_profile OR source ~/.bash_profile
Or
Reload bash_profile in ssh connection
`ssh -t -t username#servername << EOF
. ~/.bash_profile
your commands here
exit
EOF
You can set that variable in the same command line like this:
R_LIBS="${path}" Rscript -e \
'install.packages(c("someDependency", "someOtherDependency"), repos="http://cran.r-project.org");'
It's possible to append more variables in this way. Note that this will set those environment variables only for the command being called after them (and its children processes as well).
You said that "R_LIBS export doesn't get picked up". Question Is the value UNSET? Or is it set to some other value & you are trying to override it?
It is possible that SSH may be invoking "/bin/sh -c". Based on the second answer to: Why does 'cd' command not work via SSH?, you can simplify the SSH command and explicitly invoke the build.sh script in Bash:
cp -r . /to/shared/drive/to/have/access/on/remote
ssh -t -t username#servername "cd /to/shared/drive/to/have/access/on/remote && bash -f build.sh dev"
This makes the SSH invocation more similar to invoking the command within a remote interactive shell. (You can avoid sourcing scripts and exporting variables.)
You don't need to export R_LIBSor env R_LIBS when it is possible to prefix any command with local environment variable overrides (agrees with Luis' answer):
...
for path in "${!rVersionPaths[#]}"; do
R_LIBS="${path}" Rscript -e 'install.packages(c("someDependency", "someOtherDependency"), repos="http://cran.r-project.org");'
...
The Rscript may be doing a lot with env vars. You can verify that you are setting the R_LIBS env var by replacing Rscript with the env command and observe the output:
...
for path in "${!rVersionPaths[#]}"; do
R_LIBS="${path}" env
...
According to this manual "Initialization at Start of an R Session", Rscript looks in several places to load "site and user files":
$R_PROFILE
$R_HOME/etc/Renviron
$R_HOME/etc/Renviron.site
$R_ENVIRON_USER
$R_PROFILE_USER
./.Rprofile
$HOME/.Rprofile
./.RData
The "Examples" section of that manual shows this:
## Not run:
## Example ~/.Renviron on Unix
R_LIBS=~/R/library
PAGER=/usr/local/bin/less
If you add the --vanilla command-line option to ignore all of these files, then you may get different results and know something in the site/init/environ files is affecting your R_LIBS! I cannot run this system myself. Hopefully we have given you some areas to investigate.
You probably don't want to source build.sh, just invoke it directly (i.e. remove the source command).
By source-ing the file your script is executed in the SSH shell (likely sh) rather than by bash, which it sounds like is what you intended.
I am using Consul Template V0.19.0 for windows, for rendering nginx loadbalancing config.It is working as expected.
Now I want the consul template, to execute the nginx exe in a folder with args (-s reload) as below:-
Case 1:
template {
source = "Template/template.ctmpl"
destination = "F:\\IDE\\Visual Studio Collection\\Web Servers\\nginx-
1.12.0\\nginx-1.12.0\\conf\\nginx.conf"
command = "F:\\IDE\\Visual Studio Collection\\Web Servers\\nginx-
1.12.0\\nginx-1.12.0\\nginx -s reload"
command_timeout = "60s"
}
But it throws error like, "failed to execute command "F:\IDE\Visual Studio Collection\Web Servers\nginx-1.12.0\nginx-1.12.0\nginx.exe" from "Template/template.ctmpl" => "F:\IDE\Visual Studio Collection\Web Servers\nginx-1.12.0\nginx-1.12.0\conf\nginx.conf": child: exec: "F:IDEVisual": file does not exist".
Case 2:-
Currently I have achieved this by making the nginx as service (using nssm) and gave the command like,
command = "powershell restart-service nginx"
instead of giving the full path followed by "-s reload".
But for this, have to make the nginx as a service using apps like nssm.
May I know, is there any way to tell the command attribute in the consul template config to, "execute the nginx exe in folder like in the Case 1" ?
Thanks.
Try this
template {
source = "Template/template.ctmpl"
destination = "F:\\IDE\\Visual Studio Collection\\Web Servers\\nginx-
1.12.0\\nginx-1.12.0\\conf\\nginx.conf"
command = "\"F:\\IDE\\Visual Studio Collection\\Web Servers\\nginx-
1.12.0\\nginx-1.12.0\\nginx\" -s reload"
command_timeout = "60s"
}
If that doesn't work try below options also for command
command = "\"F:/IDE/Visual Studio Collection/Web Servers/nginx-
1.12.0/nginx-1.12.0/nginx\" -s reload"
or
command = "\"F:\\\\IDE\\\\Visual Studio Collection\\\\Web Servers\\\\nginx-
1.12.0\\\\nginx-1.12.0\\\\nginx\" -s reload"
Edit-1
So based on the discussion, it seems that your nginx config has a relative folder based config. When nginx is started from a folder, then it also needs to be reloaded from the same folder. So you need to changed to the folder and then execute the reload command. Two formats that you should try are
command="cd '<NGINX FOLDER PATH>' && nginx -s reload"
or
command="cmd /k 'cd \'<NGINX FOLDER PATH>\' && nginx -s reload'"
I recently installed Ngrok in order to test my localhost meteor App on my phone.
I am successful in accessing the meteor app via a tunnel by ngrok.
However when I try to login using I get this error message:
The login process shows the following error message:
400. That’s an error.
Error: redirect_uri_mismatch
Application: AppName
You can email the developer of this application at: my#emailadress.com
The redirect URI in the request, http://localhost:7123/_oauth/google,
does not match the ones authorized for the OAuth client.
Updating the Authorized JavaScript origins & redirect URIs to the Ngrok forwarding addresses, doesn't have an effect.
How do I correctly use ngrok in conjuction with Google Oauth?
Any help would be greatly appreciated
Use ngrok and change the Root URL to the one supplied by ngrok.
ROOT_URL=http:XXXXXXXX.ngrok.io meteor to start meteor.
It's trying to use http://localhost:7123/_oauth/google instead of a more ngrok-like url that could be, for example: https://fd4fdbbb.ngrok.io/_oauth/google
You can check the parameters that you are using to run the app and the environment variables too.
For example, I typically use
ServiceConfiguration.configurations.upsert(
{ service: 'facebook' },
{
$set: {
appId: process.env.facebookConsumerKey,
secret: process.env.facebookConsumerSecret,
loginStyle: 'popup'
}
}
);
And run meteor using a bash script that looks like:
#!/bin/bash
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
nvm install 4.4.7
IP_ADDRESS=`ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | grep -v '10.0.0.1'` echo "Starting app on: $IP_ADDRESS:3000"
# NODE_DEBUG=request \
# facebookOAuthRedirectURL=http://$IP_ADDRESS:3000/_oauth/facebook \
facebookAppName="BlahApp - local dev" \
facebookConsumerKey=12345 \
facebookConsumerSecret=xxxxxx \
facebookOAuthRedirectURL=http://$IP_ADDRESS:3000/_oauth/facebook \
MONGO_URL=mongodb://$IP_ADDRESS:27017/staging-blah-app \
ROOT_URL=http://$IP_ADDRESS:3000 \
BIND_IP=$IP_ADDRESS \
MOBILE_DDP_URL=http://$IP_ADDRESS \
MOBILE_ROOT_URL=http://$IP_ADDRESS \
meteor --port $IP_ADDRESS:3000 --settings development-settings.json
So you can, instead of using googleOAuthRedirectURL=http://$IP_ADDRESS:3000/_oauth/google could use https://fd4fdbbb.ngrok.io/_oauth/google
The issue was that the environment variable were not read by meteor, and even though it was overwritten on the client side, somehow the server connected to google with a wrong callback url.
Now for the solution... I started by ensuring that the settings in the google service configuration were reset by running this in the terminal after killing the app:
meteor reset
In a separate terminal, I then started ngrok to generate a tunnel link:
./ngrok http 7123
Yielding the tunnel link:
http://adba9b9f.ngrok.io/
In a separate terminal I start my app by assigning it to "port 7123" and setting "http://adba9b9f.ngrok.io" as the absoluteUrl like this:
ROOT_URL=http://adba9b9f.ngrok.io meteor --port 7123
To confirm that this command has been carried out, I typed this into the browser console
Meteor.absoluteUrl()
The response:
"http://adba9b9f.ngrok.io"
Indicates that the Meteor.absoluteUrl() command was successful.
Next, I accessed my app via the "http://adba9b9f.ngrok.io" tunnel and clicked on the "Configure google button", where GLADLY noticed that the Authorized JavaScript origins were preset to:
http://adba9b9f.ngrok.io and
Authorized redirect URIs preset to: http://adba9b9f.ngrok.io/_oauth/google
I then filled in the Client ID and Client Secret part with details from the google credentials, and updated the google credentials with the details from the configure google button details and saved.
Am happy to say... Everything works desirably now.
I'm trying to deploy from apigee tool with the following command:
apigeetool deployproxy -n my_proxy_name -o myorgname -e test -d apiproxy-3/ -b my_base_path -u myusername -p mypassword
and getting always this:
Import failed to /v1/organizations/myorg/apis?action=import&name=my_proxy_name with status 400:
{
"code" : "messaging.config.beans.InvalidBundle",
"message" : "Bundle is invalid. Unable to read/find APIProxy contents",
"contexts" : [ ]
}
At first I thought it was my proxy development.. so I tried downloading the proxy as zip file, uncompressing it, and then uploading from this command without any changes, and got the same thing.
Could this be a problem with me being on yosemite dev build 2?
the issue here is with the paid hosted option, it seems My org was having an isse and support is looking into it.
Try renaming the subdirectory from apiproxy-3 to apiproxy, then retry.