The "monitor" script in the root dir is not the C++ executable application - this sits in src folder. To set up the app executable as a linux long-running service you have to do the following:
- ssh in to the EC2 box: sh -i // [email protected]. The // is the relative path to the pem file which is not saved to the repo. If you don't have it, it's probably because you shouldn't.
1.1) Install Nginx
-
Upload the monitor service script from your local machine to EC2 home directory (/ubuntu/home) on the EC2 box (call this from your local machine); scp -i // //<monitor_service_script> [email protected]: (note the colon at the end)
-
Move this file to /etc/init.d on EC2. Make sure it is an executable; sudo chmod 755 monitor from the same dir as the monitor script.
-
Run the following command to be able allow the service to run in background after termination of ssh session; sudo update-rc.d monitor defaults.
-
copy the src/monitor executable from local to remote as shown above. then in your ssh session mv the file to /usr/local/bin and make sure it is accompanied by a file call device_log_file in the same dir.
-
to start or stop the script run: sudo /etc/init.d/monitor start|stop.
-
if this doesnt work. Try destroying the session and recreating a new one. Apparently this can be important.
Nginx is set up to proxy any port 80 calls on to port 8080 which is what the app listens on: In /etc/nginx/sites-available/monitor we have:
server { # simple reverse-proxy
listen 80;
server_name ec2-52-207-234-165.compute-1.amazonaws.com;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
and in sites-enabled we create a symlink: ln -s /etc/nginx/sites-available/monitor monitor. Restart nginx; sudo service nginx restart