LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-18-2010, 07:44 AM   #1
naveenisback
Member
 
Registered: Jun 2009
Posts: 80
Blog Entries: 1

Rep: Reputation: 16
run application in startup


Hi,

Os: ubuntu
language : c++

I developed an application PowerManager(which was generated after compiling a program gcc Power.c -o PowerManager).
I wrote this program such that it has to run at start up by following this linkhttp://en.wikipedia.org/wiki/Daemon_...er_software%29

I put this application in System -> Preference -> Startup Application.
It is working fine, but after logging out it is not working(I checked this by writing logfile).

But this program must run even after logout. How can I do this.

Thanks In advance
 
Old 01-18-2010, 08:12 AM   #2
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,278

Rep: Reputation: 148Reputation: 148
check this, it may be helpful
PHP Code:
#!/bin/sh
#
# chkconfig: 345 85 15
# description:
# processname: 

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

start
() {
echo -
"Starting Application: "
/path/to/application &
echo 
"done."
}
stop() {
echo -
"Shutting down Application: "
killproc application
echo "done."
}

# See how we were called
case "$1" in
start
)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo 
"Usage: $0 {start|stop|restart}"
esac
exit 
 
Old 01-18-2010, 09:37 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
What kirukan is describing is making your application into a service. These are programs that are launched as system services, usually running with root privileges, and started by the system. When you put your application in 'System -> Preference -> Startup Application' (whatever that is), it is a program that will run as part of your personal desktop, only. This is why it goes away when you log out.
Hope this clarifies the situation somewhat.
--- rod.
 
Old 01-19-2010, 12:25 AM   #4
naveenisback
Member
 
Registered: Jun 2009
Posts: 80

Original Poster
Blog Entries: 1

Rep: Reputation: 16
Hi

thanks for ur reply.
But Im very poor in shell scripting.

I dint understood following lines.

# Source function library.
. /etc/rc.d/init.d/functions

what is that functions means. is it executable file of my application.

# See how we were called
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start

and where I have put this shell script and how to run.. please explain in brief.
 
Old 01-19-2010, 08:25 AM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
The code that kirukan posted is the template of a script that you can use to start/stop/restart a service. You would need to put it in the /etc/init.d directory, as well as flesh it out with references to your own application. The functions that are loaded are a standard collection of bash functions that perform helpful actions. You may not require any of them to finish out the script, but they won't be harmful in any case. The syntax used is 'source some/bash/script', where '.' is an alias for the source command. This causes the shell to read the script, which contains the helper functions, which are then loaded for the (short) life of the script.
To run the script (as root, probably):
Code:
service your_service_name start/stop/restart/other
For more info,
Code:
man bash
man service
man chkconfig
For even more, see Advanced Bash-Scripting Guide.
--- rod.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write script to run an application in startup kavehiks Linux - General 3 10-21-2009 02:34 PM
I run Fedora 9 and I boot from USB, how I run at startup Firewall and antivirus? gginis Linux - Software 3 06-08-2008 03:19 AM
have a startup application run as a different user hafio Red Hat 1 02-23-2008 09:09 PM
application firing at startup ekdya Fedora 1 10-03-2006 01:24 AM
Run an application under a user on startup? wichmann_uwe Linux - General 1 01-23-2004 03:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration