Link to home
Start Free TrialLog in
Avatar of vianneyjs03
vianneyjs03Flag for United States of America

asked on

Ubuntu Sever Application Startup

I need to run an application on my server at the startup.

1- I copied my script in /etc/init.d, like so:
sudo cp /usr/app/app01.x86 /etc/init.d/app01

2- Then made it executable:
sudo chmod a+x app01

3- Then informed the system that I wish the app01 to run automatically on server startup, using:
sudo update-rc.d app01 defaults

I got this message:
root@app01svr01:~# sudo update-rc.d app01 defaults
update-rc.d: warning: /etc/init.d/app01 missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
 Adding system startup for /etc/init.d/app01 ...
   /etc/rc0.d/K20app01 -> ../init.d/app01
   /etc/rc1.d/K20app01 -> ../init.d/app01
   /etc/rc6.d/K20app01 -> ../init.d/app01
   /etc/rc2.d/S20app01 -> ../init.d/app01
   /etc/rc3.d/S20app01 -> ../init.d/app01
   /etc/rc4.d/S20app01 -> ../init.d/app01
   /etc/rc5.d/S20app01 -> ../init.d/app01
   
5- I rebooted the server to check that the app01 was automatically starting, and actually it was, but was loaded as S20app01.
The problem is that I created two scripts to stop/restart the application:

Stop Scrip:
#!/bin/sh
killall -9 app01

Restart:
#!/bin/sh
killall -9 app01
sleep 1
ulimit -c unlimited -n 65536
/usr/app/app01 &


As you can see on the scripts I stop/restart the proccess called app01, but the app01 is starting up as a process called S20app01 as mentioned above.


What can I do to assure that app01 will always start up as the proccess called "app01" instead of something else.
Or there is other way to accomplish this?



Thanks
Avatar of upanwar
upanwar
Flag of India image

No need to worry.
When we add chkconfig to any script to start or stop at the time of booting. It creates soft links in run levels directory, the file which name start with S and K, S stands for starting of service in run level and K stand for stopping of service.

Nos like 20 denotes the sequence of starting and stopping service.
Avatar of vianneyjs03

ASKER

Thanks upanwar.

So, should I change my scripts to this?

Stop Script:
#!/bin/sh
killall -9 S20app01

Restart Script:
#!/bin/sh
killall -9 S20app01
sleep 1
ulimit -c unlimited -n 65536
/usr/app/app01 &

Is there any chances that this "S20app01" process name change in the future?


Thanks a lot.
no need to change anyting.
Avatar of arnold
chkconfig --list app01 it should tell you on which run levels it will run and on which run levels it will not.

As upanwar pointed out the symlinks is how the main /etc/init.d/app01 is linked to each run level rc2.d rc3.d rc4.d rc5.d rc6.d

presumably in your app01 script you have a line:
#chkconfig [run_levels_to_run] [start number] [stop number]
i.e. if you want it to run at run levels 345, it should start in the middle (0-100) 50 a and stop in the middle 50 your line will be
#chkconfig 345 50 50
The consideration for the start/stop order deal with whether the resources it needs were already started. i.e. if your application relies on network, mysql, etc. its start number can not be lower their those services nor can it be higher than those services on the stoppage.
i.e. network is 10 90
mysql is 64 36
If app01 need mysql to work, it can not start before 64 not can it be stopped after 36.
in this case your app01 chkconfig line should be:
#chkconfig 345 70 30

You should not use kill -9 as it does not provide your application any chance to clean up after itself i.e. finish transactions it was doing and depending on what the application is doing, could lead to data loss.
kill -15 (TERM) is a better approach that lets the application know that it needs to finish up and exit.
That's the reason why I'm asking this question, sorry  didn't mention it.

When I run the stop/restart script i got this message:
"process not found" because the application is starting up as "S20app01" instead of "app01", I checked this with the Sytem Monitor.

The S20app01 is not the name of the application that runs. S20app01 is merely a script that starts the application and based on the entry you posted the application is run as /usr/app/app01

Note that using a to broad a kill directive could get the script terminated
i.e. a script S20app01 with a directive within saying

PID=`ps -ef | grep app01`
kill -TERM $PID
Could have a list of PIDs that includes this script and it could be the first killed.

Hi Arnold.

I'm a little bit confused (I'm a Ubuntu/scripting nuewbie), what you said is that i should use this script:
PID=`ps -ef | grep app01`
kill -TERM $PID

To kill the "S20app01" process that is running
No you should not have an S20app01 running, you should have a /usr/app/app01 running.
S20app01 will only be running if /usr/app/app01 is not really a daemon i.e. it does not detach and through itself into the background to do that, you should add an ampersand (&) on the /usr/app/app01 line in the script
/usr/app/app01 &

This way S20app01 will be done when app01 is run in the background.
I don't think that app01 is a deamon as you say.
So the stop script should be something like:

#!/bin/sh
killall -9 /usr/app/app01 &


Please advise.
No, the start of the app01 should have the &
There is no point of sending the termination process into the background.

start )

do stuff
/usr/app/app01 & #starting the application and sending it to the background

stop )
   kill -TERM /usr/app/app01

restart)
      $0 stop
      $0 start
Ok, thanks Arnold for your outstanding support, I'll check this and get back to you.


Regards.

Hi Arnold.

Everytime I've tried to run the script you suggested, I got this error:


# sudo /etc/init.d/app01
/etc/init.d/app01: 2: Syntax error: ")" unexpected
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial