Adding a script service start for Amazon linux AMI

I use AMI Amazon Linux AMI and make some custom changes (added on axis2server server etc.) and save it as a new AMI. Now what I want to do is when the AMI loads, it starts axis2server (i.e..axis2server should start automatically when the instance loads). To do this, I used the init script, as shown below, and ran the following command:

chkconfig --add axisservice 

But when I start a new instance from my image, the axial server does not start.

I just need to execute script / home / ec2-user / axis2-1.6.1 / bin / axis2server.sh at startup. Did I miss something?

 #! /bin/sh # Basic support for IRIX style chkconfig ### # chkconfig: 235 98 55 # description: Manages the services you are controlling with the chkconfig command ### case "$1" in start) echo -n "Starting axisservice" touch ~/temp.txt cd /home/ec2-user/axis2-1.6.1/bin ./axis2server.sh & echo "." ;; stop) echo -n "Stopping axisservice" echo "." ;; *) echo "Usage: /sbin/service axisservice {start|stop}" exit 1 esac exit 0 

I went through https://help.ubuntu.com/community/CloudInit and it provides a mechanism called User-Data Scripts where the user can execute the script when the script is run.

 $ euca-run-instances --key mykey --user-data-file myscript.sh ami-axxxx 

This is a command line parameter, and I want something like when I run the instance through the user interface, the script should be running. Therefore, I think that the above option cannot be used in my case. Please correct me if I am wrong.

Thank you N.

+6
source share
1 answer

I am sure that the environment is not installed (correctly). This means that I assume that your shell script is trying to run another program and not find it.

So, first I edited the start part of your script (current):

 echo -n "Starting axisservice" touch ~/temp.txt cd /home/ec2-user/axis2-1.6.1/bin ./axis2server.sh & echo "." 

Edited by:

 echo -n "Starting axisservice" touch ~/temp.txt cd /home/ec2-user/axis2-1.6.1/bin ./axis2server.sh RETVAL=$? [ $RETVAL -eq 0 ] && echo Success [ $RETVAL -ne 0 ] && echo Failure echo "." 

So what have I done?

  • removed & so the script waits for the completion of your shell script (axis2server.sh)
  • checked the return status ( $? ) of your shell script

Further debugging:

Add set -x to your scripts to enable tracing and register both stderr and stdout .

Questions:

  • Do you know that stop (in your script service) does nothing?
  • touch ~/temp.txt is creating /root/temp.txt ? (I assume that root is running this script.)
  • If none of my suggestions work, can you share axis2server.sh and insert stderr and stdout ?
+3
source

Source: https://habr.com/ru/post/903126/


All Articles