LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-25-2009, 10:16 PM   #1
gilly1409
LQ Newbie
 
Registered: Jul 2009
Location: Sydney
Posts: 4

Rep: Reputation: 0
Services - starting them manually in a terminal


Hi

I've been playing around with services using a standard script to start a third party service at boot time. I used chkconfig --add <servicename> to achieve this - so far, all good!

There are time that I need to stop and start this service manually ie

service <servicename> stop &

service <servicename> start &

(note - I haven't yet done restart in the script but will do when I get 2 mins)

these commands work fine. But when I close the terminal window after I start the service, the service also ends.

I am sure this is something really obvious but so far my googling hasn't returned any relevant info.

My other question is why do I still need the ampersand to release the terminal window when running as a service. If I do something like

service iptables start

I get my terminal back with no need for the ampersand

Did I miss something in my script?

cheers

G
 
Old 08-25-2009, 10:29 PM   #2
MBybee
Member
 
Registered: Jan 2009
Location: wherever I can make a living
Distribution: PC-BSD / FreeBSD / Debian / Ubuntu / Win7 / OpenVMS
Posts: 438

Rep: Reputation: 57
Perhaps what you're looking for is nohup, though I don't recall needing to use that with the service command before.

Syntax would be "nohup service iptables start &", for example. This is a Fedora/RedHat/Centos box, I assume?
 
Old 08-26-2009, 12:06 AM   #3
tommylovell
Member
 
Registered: Nov 2005
Distribution: Fedora, Redhat
Posts: 372

Rep: Reputation: 101Reputation: 101
An explanation and a solution.

The explanation. Normally the program that is invoked in your rc startup file has the ability to "daemonize" itself.
That's like nohup'ing and &'ing itself.

The solution. In your rc file add the 'nohup' and the '&' to what you are starting. Not the most sophisticated approach, but it works.

Here is an example called /etc/rc./init.d/test that starts 'mycommand'. You'd add it with 'chkconfig --add test'; 'chkconfig test on'; and could manually start it with 'service test start'.
Code:
#!/bin/bash
#
# test          Send an email, start or stop 'mycommand'
#
# chkconfig: - 90 10
# description: Just send an email when runlevel changes
#
HOST=`hostname`
MAIL="/bin/mailx"
RMAIL="me@mysite.com"

case "$1" in
'start')
[ -f /var/lock/subsys/test ] \
        && echo "test appears started"
${MAIL} -s "test starting on ${HOST}" ${RMAIL} < /dev/null >/dev/null 2>&1
touch /var/lock/subsys/test
nohup /full/path/to/mycommand 2>&1 >>/home/me/mycommand/nohup.out &
;;

'stop')
[ -f /var/lock/subsys/test ] \
        || echo "test appears already stopped"
${MAIL} -s "test stopping on ${HOST}" ${RMAIL} < /dev/null >/dev/null 2>&1
/bin/rm -f /var/lock/subsys/test
killall -s9 mycommand
;;

*)
echo "Usage: $0 { start | stop }"
exit 1
;;
esac
exit 0
 
  


Reply

Tags
daemon, service


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
Manually Starting installation dhirsolo Linux - Newbie 6 05-23-2006 12:07 PM
manually starting services? greythorne Ubuntu 3 12-21-2005 02:58 PM
Starting services from terminal ExploiT Linux - General 4 09-18-2004 10:04 PM
TightVNC Ver terminal Services.. also looking for terminal Services for linux 2782d4 Linux - Security 3 05-20-2004 02:30 AM
activate services manually 2047 Linux - Networking 3 09-12-2001 01:32 PM


All times are GMT -5. The time now is 12:13 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration