Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 5235  / 1 Year ago, sun, may 28, 2023, 3:57:47

I have phantomjs installed and I want to run a phantom server whenever the (Ubuntu) server starts.



I am currently working locally on Ubuntu 14.04, and the server this will be deployed to is also Ubuntu 14.04.



This is what I have so far:



upstart script:



# /etc/init/phantomjs.conf

start on startup

exec '/path/to/script/to/start/server.bash'


bash script to start the phantom server:



#/path/to/script/to/start/server.bash   

#!/bin/bash

phantomjs /path/to/the/server.js -host 127.0.0.1 -port 1337


When I run the server normally from the command line, it works as expected.



When I run the upstart script, it ouputs OK, PhantomJS is ready to the log file, but when I make post requests to it, nothing else happens. I would expect it to output something to the log each time I make a request, like it does when I run it from the command line, but it seems to just start the server and then nothing else.


More From » bash

 Answers
2

It turns out the reason this wasn't working was because the phantomjs server only works properly if I start the server in the directory the file is in.



Executing the full path of the script doesn't work.



To fix this I took Stef K's script and added



evn SERVER_DER=/path/to/server/directory
evn SERVER_FILE=phantomserver.js
...
script
chdir $SERVER_DIR
exec phantomjs $SERVER_FILE -host $HOST -port $PORT | logger -s -t "phantomjs: "
end script


Thank you Stef K and CameronNemo for your improved versions of my initial script.


[#23991] Monday, May 29, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ditery

Total Points: 9
Total Questions: 116
Total Answers: 119

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
;