| Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-02-2009, 12:23 PM
|
#1
|
|
Member
Registered: Sep 2007
Posts: 217
Rep:
|
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?
|
|
|
|
04-02-2009, 12:27 PM
|
#2
|
|
Member
Registered: Jun 2006
Location: Italy
Distribution: Slackware 13.1
Posts: 213
Rep:
|
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
|
|
|
|
04-02-2009, 12:34 PM
|
#3
|
|
Member
Registered: Sep 2007
Posts: 217
Original Poster
Rep:
|
Seems like it would work, are there any drawbacks to doing it that way, specifically security issues with it?
|
|
|
|
04-02-2009, 12:39 PM
|
#4
|
|
Senior Member
Registered: Nov 2003
Location: Knoxville, TN
Distribution: Kubuntu 9.04
Posts: 1,168
Rep:
|
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.
|
|
|
|
04-02-2009, 12:50 PM
|
#5
|
|
Member
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 531
Rep:
|
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
|
|
|
|
04-02-2009, 04:33 PM
|
#6
|
|
Member
Registered: Jan 2002
Location: Labrador, Canada
Distribution: CentOS, Debian
Posts: 182
Rep:
|
Very nice and useful post Robert.
|
|
|
|
04-03-2009, 01:40 AM
|
#7
|
|
Member
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 531
Rep:
|
Thx, but I hope he's gonna use it or its gonna work for him. 
|
|
|
|
04-03-2009, 01:46 AM
|
#8
|
|
Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Rep: 
|
If the user has a shell, you could simply add
@reboot commands_go_here
to the user's crontab
|
|
|
|
04-03-2009, 01:50 AM
|
#9
|
|
Member
Registered: Sep 2007
Posts: 217
Original Poster
Rep:
|
Thanks for the suggestions guys!! I did what Robert said, seemed to be the easiest way.
|
|
|
|
04-04-2009, 08:48 AM
|
#10
|
|
Member
Registered: Sep 2007
Posts: 217
Original Poster
Rep:
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:41 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|