View previous topic :: View next topic |
Author |
Message |
linuxpyro Apprentice
Joined: 08 Sep 2004 Posts: 255
|
Posted: Mon Dec 04, 2006 4:49 am Post subject: [SOLVED] Init Script for Non-Root Service |
|
|
I'm setting up a DC++ hub with Verlihub. I have it set up and working fine, as both root and the user hub. I have the following init script, which starts the hub find as the root user:
Code: |
#!/sbin/runscript
# Verlihub boot script for gentoo distributions
# feel free to change these
confdir=/etc/verlihub
logdir=/var/log/verlihub
verlihubexe=/usr/local/bin/verlihub
# don't change these ones, though!
loghistorydir=$logdir/history
logfile=$logdir/log
errfile=$logdir/err
loghistfile=$loghistorydir/log
errhistfile=$loghistorydir/err
pidfile=/var/run/verlihub.pid
requiredfiles="dbconfig db"
optionalfiles="motd faq rules help_admin help_master help_op help_usr help_reg"
depend() {
need net
need mysql
}
start() {
ebegin "Starting verlihub"
# make sure the configuration directory exists
if [ ! -d $confdir ]; then
eerror FATAL ERROR: missing configuration directory $confdir
return 1
fi;
# ensure log directory exists
if [ ! -d $logdir ]; then
mkdir $logdir
fi;
# ensure log history directory exists
if [ ! -d $loghistorydir ]; then
mkdir $loghistorydir
fi;
# check for the required files
for f in $requiredfiles; do
file=$confdir/$f
if [ ! -e $file ]; then
eerror "FATAL ERROR: missing required file $file"
return 1
fi;
done;
# check for the optional files
for f in $optionalfiles; do
file=$confdir/$f
if [ ! -e $file ]; then
eerror "WARNING: missing file $file, some functionality will be disabled"
fi;
done;
# backup logs and date/timestamp them
if [ -e $errfile ]; then
mv -f $errfile $errhistfile.`date +%Y_%m_%d_%k:%M:%S`.old
fi
if [ -e $logfile ]; then
mv -f $logfile $loghistfile.`date +%Y_%m_%d_%k:%M:%S`.old
fi
# start the hub
$verlihubexe >$logfile 2>$errfile &
pid=$!
disown $pid
echo $pid > $pidfile
eend $?
}
stop() {
ebegin "Stopping verlihub"
pid=`cat $pidfile`
kill $pid
rm $pidfile
eend $?
}
restart() {
svc_stop
sleep 5
svc_start
}
|
My question is, how can I modify it to make the hub start as the user hub? As far as I know, there's no way to configure the hub to change to a non-root user, like I think Apache can. So, it has to be something within the init script. Could I just add su - hub just before $verlihubexe >$logfile 2>$errfile &?
Thanks for any insight.
Edit: Typo.
Last edited by linuxpyro on Mon Dec 04, 2006 5:54 am; edited 1 time in total |
|
Back to top |
|
|
Sadako Advocate
Joined: 05 Aug 2004 Posts: 3792 Location: sleeping in the bathtub
|
Posted: Mon Dec 04, 2006 5:09 am Post subject: |
|
|
Try replacing the line were you actually start the app ($verlihubexe >$logfile 2>$errfile &) with the following;
Code: | start-stop-daemon --start -c USERNAME -x $verlihubexe >$logfile 2>$errfile & |
replacing USERNAME with the name of the user you want the program to run as.
You can also use start-stop-daemon to manage the pid file, set the nice priority or even operate within a chroot, if desired.
I highly recommend reading the start-stop-daemon man page.
Also, on a side note, all the variables you set at the start should really go into a conf file under the same name as the init script but located in /etc/conf.d, the variables will be available to the init script. _________________ "You have to invite me in" |
|
Back to top |
|
|
linuxpyro Apprentice
Joined: 08 Sep 2004 Posts: 255
|
Posted: Mon Dec 04, 2006 5:53 am Post subject: |
|
|
Thank you! That starts the hub without an error, but when I do run /etc/init.d/verlihub start I get the following:
Code: |
* Re-caching dependency info (mtimes differ)...
* Re-caching dependency info (mtimes differ)...
* Re-caching dependency info (mtimes differ)...
* Re-caching dependency info (mtimes differ)...
* Starting verlihub ...
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information.
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information. [ ok ]
|
I'm thinking that's just a permissions issue though... I think I can call this solved. |
|
Back to top |
|
|
Headrush Watchman
Joined: 06 Nov 2003 Posts: 5597 Location: Bizarro World
|
Posted: Mon Dec 04, 2006 6:38 am Post subject: |
|
|
linuxpyro wrote: | I'm thinking that's just a permissions issue though... I think I can call this solved. |
Your date command returns a space.
So your mv command has three files, so when copying multiple files move expects the last to be a directory. (Of course it is a file and errors)
Try Code: | date +%Y_%m_%d_%k:%M:%S |
in a terminal and you can see the space. %k returns a space on single digit hours instead of 01, 02, etc. Use %H instead. Code: | date +%Y_%m_%d_%H:%M:%S |
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|