Hi
Im looking for an init.d script for a linux system without sudo. I use Mandriva which has an old fashioned root user and no sudo.
Thanks for any help
C
init.d script without sudo?
Forum rules
Help us help you:
Help us help you:
- Are you using the latest stable version of SABnzbd? Downloads page.
- Tell us what system you run SABnzbd on.
- Adhere to the forum rules.
- Do you experience problems during downloading?
Check your connection in Status and Interface settings window.
Use Test Server in Config > Servers.
We will probably ask you to do a test using only basic settings. - Do you experience problems during repair or unpacking?
Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Re: init.d script without sudo?
Just remove the sudo commands, you can run SABnzbd as root.
Re: init.d script without sudo?
Hi, thanks for your reply. Is it safe to run as root with a web interface?
Re: init.d script without sudo?
Worked it out..
Here's what I did, hope it helps somebody else
You need to replace the sabuser and hostname and port with your own as with the Install As A Unix Daemon wiki page.
Thanks to the devs for a great app
Here's what I did, hope it helps somebody else
Code: Select all
#! /bin/sh
case "$1" in
start)
echo "Starting SABnzbd."
su -c "python /usr/local/src/SABnzbd/SABnzbd.py -d -f /home/sabuser/.sabnzbd/sabnzbd.ini" - sabuser
;;
stop)
echo "Shutting down SABnzbd."
wget -q --delete-after "http://HOSTADDRESS:PORT/sabnzbd/api?mode=shutdown"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
Thanks to the devs for a great app
Re: init.d script without sudo?
Taking this a step further, Mandriva uses chkconfig in a similar way to Ubuntu and updaterc.d to manage the rc.d run level scripts. chkconfig needs some headers adding to the init.d file to make it into the correct syntax so it can be started and stopped automatically at boot and shutdown and managed through the graphical service manager in the mandriva control centre.
Ive included the complete file to enable you to do this, obviously you will need to change the SABUSER to your user and HOSTNAME and PORT to your own. It is adapted from the example script in the Mandriva wiki, using a variable for the service name so could be improved upon if you are a real stickler but it does the job!
Save this file as sabnzbd in /etc/init.d, you will need to be root, and make it executable.
Once saved you can add it using chkconfig with
You should then find it listed in MCC and be able to set it to start and stop automatically at boot and shutdown.
It uses a lock file in /var/lock/subsys to prevent multiple occurances. I found I had to add a few sleep's in to give the web server time to respond before it deletes the lock file. You may find you can decrease these but if you are unable to start sabnzbd after stopping it then its likely the lock file still exists, You can safely delete it if the sabnzbd is really stopped...
..will return your search for 'python' if it is and anything else using python (screenlets maybe?) but not a line like - python /usr/local/src/SABnzbd/SABnzbd.py -d -f /home/SABUSER/.sabnzbd/sabnzbd.ini
Hope it helps someone, Im sure it can be adapted to other non debian distro's too.
Ive included the complete file to enable you to do this, obviously you will need to change the SABUSER to your user and HOSTNAME and PORT to your own. It is adapted from the example script in the Mandriva wiki, using a variable for the service name so could be improved upon if you are a real stickler but it does the job!
Code: Select all
#! /bin/sh
#
### BEGIN INIT INFO
# Provides: sabnzbd
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 5
# Short-Description: launches sabnzbd
# Description: Start n Stop SABnzbd n'stuff
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
DAEMON_NAME=sabnzbd
LOCK_FILE=/var/lock/subsys/$DAEMON_NAME
RETVAL=0
# default option, they can be overriden in /etc/sysconfig/$DAEMON_NAME
# of course, you can place what you want.
# this file should be commented, with proper pointer to the doc, and you should use
# more than one line of option, if possible.
[ -f /etc/sysconfig/$DAEMON_NAME ] && . /etc/sysconfig/$DAEMON_NAME
start() {
# if you cannot start the daemon since something is missing ( like a path that
# cannot be set by default
# , place the test here
# if [ -z "$SOME_VAR" ]; then
# echo "You need to set $SOME_VAR in /etc/sysconfig/$DAEMON_NAME"
# RETVAL=1
# return
# fi
[ -f $LOCK_FILE ] && return
echo -n "Starting $DAEMON_NAME: "
su -c "python /usr/local/src/SABnzbd/SABnzbd.py -d -f /home/SABUSER/.sabnzbd/sabnzbd.ini" - SABUSER
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
}
stop() {
echo -n "Shutting down $DAEMON_NAME: "
wget -q --delete-after "http://HOSTNAME:PORT/sabnzbd/api?mode=shutdown"
sleep 3
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 5
start
;;
condrestart)
if [ -f $LOCK_FILE ]; then
stop
sleep 5
start
fi
;;
*)
echo "Usage: $0 {start|stop|restart|condrestart}"
RETVAL=1
esac
exit $RETVAL
Code: Select all
chmod a+x sabnzbd
Code: Select all
chkconfig --add sabnzbd
It uses a lock file in /var/lock/subsys to prevent multiple occurances. I found I had to add a few sleep's in to give the web server time to respond before it deletes the lock file. You may find you can decrease these but if you are unable to start sabnzbd after stopping it then its likely the lock file still exists, You can safely delete it if the sabnzbd is really stopped...
Code: Select all
ps aux | grep python
Hope it helps someone, Im sure it can be adapted to other non debian distro's too.
Re: init.d script without sudo?
Nice script, just a small remark: in stop(), you are reading the return value of the "sleep 3" command rather than the actual shutdown command. As a result, the return value will always be 0, and shutdown will be reported as successful even when it isn't (for example in case the web interface is password protected) or sabnzbd wasn't even running in the first place. Something along the lines of ...mollydog wrote: It uses a lock file in /var/lock/subsys to prevent multiple occurances. I found I had to add a few sleep's in to give the web server time to respond before it deletes the lock file.
Code: Select all
stop() {
echo -n "Shutting down $DAEMON_NAME: "
wget -q --delete-after "http://HOSTNAME:PORT/sabnzbd/api?mode=shutdown"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && {
sleep 3;
rm -f $LOCK_FILE;
}
}
Re: init.d script without sudo?
I see your point. I knew it was all going too well
Its probably better to have it correct and temorarily forced than incorrect so have made the changes as you suggested.
Thankyou!
Its probably better to have it correct and temorarily forced than incorrect so have made the changes as you suggested.
Thankyou!