Program to start on EC2 instance boot. - amazon-ec2

I have a program that I run on amazon EC2 and I would like to set it up in a way so that when I boot a new EC2 instance it starts the program and sets itself up without any input from me.
How could i do this?
The program is a java .jar file.

Assuming you are booting the machine from an AMI with java installed and the program in a particular directory, you can have the command to start the program (jar -jar ... ) in somefile like /etc/rc.local.

If, by chance, it is Windows, you could also run a batch file on system startup:
1. Run REGEDT32.EXE.
2. Modify the following value within HKEY_CURRENT_USER:
Software\Microsoft\Windows NT\CurrentVersion\Winlogon\ParseAutoexec
1 = autoexec.bat is parsed
0 = autoexec.bat is not parsed

Related

EC2 user-data not starting my application

I am using user-data of ec2 instance to power up my auto scale instances and run the application. I am running node js application.
But it is not working properly. I have debugged and checked the instance cloud monitor output. So it says
pm2 command not found
After reading and investigating a lot I have found that the path for the command as root is not there.
As EC2 user-data when it tries to run it finds the path
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
After ssh as ec2-user it is
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin:/home/ec2-user/bin
After ssh as sudo su it is
/root/.nvm/versions/node/v10.15.3/bin:/sbin:/bin:/usr/sbin:/usr/bin
It works only for the last path.
So what is the way or script to run the command as root during launch of the instance provided by user-data?
All thought to start your application with userdata is not recommended, because as per AWS documentation they are not assuring that instance will only come up after successful execution of user data. Even if user data failed it will spin up your instance.
For your problem, I assume if you give the complete absolute path of the binary, It will work.
/root/.nvm/versions/node/v10.15.3/bin/pm2
Better solution for this approach, create a service file for your application startup and start application with systemd or service.

automatic hadoop services Start

iam using centos 7 and i want to make hadoop services working by dynamic way
i mean i want to automate the process of issuing start-all.sh command
to be executed automatically after boot of centos
i had made the following script and let it called start-hadoop.sh (/root/start-hadoop.sh)
/etc/rc.d/init.d/functions
/usr/local/hadoop/etc/hadoop/hadoop-env.sh
/usr/local/hadoop/sbin/start-dfs.sh
which sould start hadoop-services
i had trired to give this script execute permissions as root user and to put this script directory in the file rc.local
which is found under the path /etc/rc.d/rc.local of course after giving it
execute permissions but it is not executed at boot
any help please and are there any better ways

Start ruby app as service on CentOS 7

I have a ruby script (actually an example script from the Oxidized project), which is written in Ruby and opens a UDP port (514) listening for syslog messages and executing some code in the background.
The system runs on CentOS 7. I want to start this script as "service" automatically when the OS boots. The script however needs to run as a specific user (oxidized) and should be controllable using normal "service ... [start|stop|status|...|" behaviour. What would be the best way to achieve this?
Startup services can be managed by 2 different boot systems.
CentOS6 uses System V (Old Boot System)
CentOS7 uses Systemd (New Boot System) (Systemd does support System V scripts.)
Here is a link "How to write startup script for systemd"
https://unix.stackexchange.com/questions/47695/how-to-write-startup-script-for-systemd
Here is a link "How to write a System V init script to start, stop, and restart my own application or service"
https://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html

Running a batch file from Jenkins hangs and does not return to the Jenkins job

I am using the "Send files or execute commands over SSH after the build runs" option in my Jenkins job configuration. I am running a .bat file on a remote server. The .bat file is starting an authentication server. The authentication server needs to remain up and running on the remote server.
The authentication server is delivered with a .bat file to start and stop the server. When I run the delivered .bat file my jenkins job hangs and never completes. The delivered .bat file named startAuth.bat looks like this:
call java -jar Auth.jar db migrate Auth.yml
call java -jar Auth.jar server Auth.yml
Based on some end user restrictions, I cannot modify the startAuth.bat file, so I have create another .bat file to call startAuth.bat named runStartAuth.bat. It looks like this:
cd c:\tmp
start runStartAuth.bat
exit /b
My thinking was by using "start" the .bat should be run in a separate process, one that could remain up and running until the next Jenkins job run, and the calling .bat would exit with the exit /b line. Unfortunately, the Jenkins job seems to ignore the exit and just spins and spins.
What am I doing wrong?
I'm not really an expert with Jenkins ... but I think since the slave agent JVM wrapper over your batch file knows that the child process has not yet finished, it will not return control to the executor.
Instead, can you try having the same commands on the Jenkins slave node configuration ? I believe you will have slave launcher prefix command in the Advanced section of the slave node.

Run Powershell script on machine start?

I have a script that I need to have run every time a certain Windows XP machine boots up. I've written it in Powershell, and it works. But how do I get it to run when the machine starts? Not when I log in, but on machine start.
Thank you
Task Scheduler - Run at Startup
add a new key to the following registry hive.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
if you want the program be executed once only then add it to
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce
keys in this hive will be deleted after it is executed. You can add ! at the beginning of the name to force the deletion to happen at the end of the execution.
The sequence of execution is listed in the following link
http://support.microsoft.com/kb/179365

Resources