LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 04-02-2009, 01:23 PM   #1
Skillz
Member
 
Registered: Sep 2007
Posts: 242

Rep: Reputation: 32
Start services on a restart automatically..


How would I run scripts automatically if a server gets rebooted/restarted from the user who owns those scripts?

Say I have a teamspeak server running under the users tsclient and the startup script to start the server is

./teamspeak2-server_startscript start

How would I execute that script, with that user, automatically on a server reboot?
 
Old 04-02-2009, 01:27 PM   #2
simopal6
Member
 
Registered: Jun 2006
Location: Italy
Distribution: Slackware 13.1
Posts: 218

Rep: Reputation: 30
I'm not sure if this is the best solution, but you could add to /etc/rc.d/rc.local (in Slackware, I don't know about other distributions) something like this:
Code:
su owner_user
./teamspeak2-server_startscript start
 
Old 04-02-2009, 01:34 PM   #3
Skillz
Member
 
Registered: Sep 2007
Posts: 242

Original Poster
Rep: Reputation: 32
Seems like it would work, are there any drawbacks to doing it that way, specifically security issues with it?
 
Old 04-02-2009, 01:39 PM   #4
Crito
Senior Member
 
Registered: Nov 2003
Location: Knoxville, TN
Distribution: Kubuntu 9.04
Posts: 1,168

Rep: Reputation: 53
On an RPM-based distro use the rc.local file. I've been told Deb-based distros don't use rc.local though so YMMV. I'm a Mandriva/Fedora/SuSE guy.
 
Old 04-02-2009, 01:50 PM   #5
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 587

Rep: Reputation: 58
If you using Redhat/CentOS/Fedora/Mandriva/Suse/Slackware, then you can add the script to /etc/rc.local like this

su - username -c 'cd /path/to/the/script; ./teamspeak2-server_startscript start'

and if not then u will have to build a small start/stop script which you can add to /etc/init.d if in case you are using Debian/Ubuntu and then just run:

update-rc.d -n script_name defaults

Its quite simple, Good luck!


Example:

Code:
#!/bin/sh

USER=teamspeakuser
SCRIPTPATH=/path/to/the/script

case $1 in
     start)
     echo -en "Start Teamspeak: "
     su - $USER -c 'cd $SCRIPTPATH; ./teamspeak2-server_startscript start' >/dev/null 2>&1
     echo -e "\t done"
     ;;
     stop)
     echo -en "Stop Teamspeak: "
     su - $USER -c 'cd $SCRIPTPATH; ./teamspeak2-server_startscript stop' >/dev/null 2>&1
     echo -e "\t done"
     ;;
     *)
     echo "Usage: $0 {start|stop}"
     exit 1
esac

exit 0
 
Old 04-02-2009, 05:33 PM   #6
sleddog
Member
 
Registered: Jan 2002
Location: Labrador, Canada
Distribution: CentOS, Debian
Posts: 182

Rep: Reputation: 35
Very nice and useful post Robert.
 
Old 04-03-2009, 02:40 AM   #7
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 587

Rep: Reputation: 58
Thx, but I hope he's gonna use it or its gonna work for him.
 
Old 04-03-2009, 02:46 AM   #8
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
If the user has a shell, you could simply add

@reboot commands_go_here

to the user's crontab
 
Old 04-03-2009, 02:50 AM   #9
Skillz
Member
 
Registered: Sep 2007
Posts: 242

Original Poster
Rep: Reputation: 32
Thanks for the suggestions guys!! I did what Robert said, seemed to be the easiest way.
 
Old 04-04-2009, 09:48 AM   #10
Skillz
Member
 
Registered: Sep 2007
Posts: 242

Original Poster
Rep: Reputation: 32
I would like to point out that anyone who wants to use it for starting teamspeak on a server reboot, you need to use restart. Since teamspeak creates a file with the PID and a graceful shut down of teamspeak deletes this file, a server reboot doesn't. So teamspeak thinks it's still running when the server is rebooted. Using restart forces it to attempt to stop the server, but then it starts it again.
 
  


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
start services at startup automatically merlin23 Linux - Newbie 10 06-30-2013 05:48 AM
restart network services automatically nightmare49 Linux - Networking 1 03-19-2009 08:00 PM
How can I monitor services such as apache and mysql, and restart them automatically? abefroman Linux - Software 3 05-21-2008 11:06 PM
LXer: Linux automatically monitor and restart services when daemon is killed LXer Syndicated Linux News 0 11-25-2006 11:21 PM
Start Stop Restart Services Sifvion Slackware 6 09-14-2002 04:13 AM


All times are GMT -5. The time now is 05:45 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration