LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 10-13-2014, 01:11 PM   #1
micheal.hd
LQ Newbie
 
Registered: Oct 2014
Posts: 4

Rep: Reputation: Disabled
calibre startup script


I have installed calibre from sbopkg with all dependencies. The program works as a GUI application from a desktop. Program aslo works when I type the service as on cli with same arguments as in my script.
When I execute the script I put together it does not work. It tells me service started but does not start.

Can someone have a look and see why this is not working. I have gotten this far but lack the finishing touch.

Thx

----------------------------------
#!/bin/sh
#
# Create a user with no login
# sudo groupadd calibre
# sudo useradd -g calibre -d /var/lib/calibre -s /bin/false calibre
# sudo usermod -G calibre calibre
# sudo mkdir /var/lib/calibre
# sudo touch /var/lib/calibre/calibre-server-log
# sudo touch /var/lib/calibre/calibre-server-errors
# sudo chown -R calibre:calibre /var/lib/calibre
#
# Install calibre and dependencies using sbopkg from slackbuilds.org
#

CONTENT=/usr/local/pub/calibre # library location
CALIBRE_LOGFILE=/var/lib/calibre/calibre-server-log # log files are good
CALIBRE_ERRORFILE=/var/lib/calibre/calibre-server-errors
PORT=8080 # port to listen on
CALIBRE_USER=calibre # lets run service as a user
DAEMON=/usr/bin/calibre-server # binary file
PIDFILE=/var/run/calibre-server.pid # setup a pid file
ARGS="--auto-reload --with-library=$CONTENT --pidfile=$PIDFILE --port=$PORT --daemonize"

# Need to get the status of the service prior any pending operations
calibre_status() {
if ( ps aux | grep "$DAEMON" |grep -v grep); then
return 0
else
return 3
fi
}

# start the service pending the outcome from the status request
calibre_start() {
calibre_status;
if [ $? = 0 ]; then
echo "Calibre Server is already running..."
exit 1;
fi
echo "Starting Calibre Server..."
su - $CALIBRE_USER -c "$DAEMON $ARGS" > $CALIBRE_LOGFILE 2>$CALIBRE_ERRORFILE &
}

calibre_stop () {
echo -n "Stopping Calibre Server..."
killall $DAEMON
rm $PIDFILE
echo "done"
}

calibre_restart() {
echo "Restarting Calibre Server..."

calibre_status;
if [ $? = 0 ]; then
calibre_stop
sleep 3
calibre_start
else
calibre_start
fi
}

case "$1" in
start)
calibre_start
exit 0
;;
stop)
calibre_stop
exit 0
;;
restart)
calibre_restart
exit 0
;;
status)
calibre_status
if [ $? = 0 ]; then
echo "Calibre Server is already running..."
else
echo "Calibre is not running"
fi
;;
*)
echo "usage: $0 start|stop|restart|status"
exit 1
;;
esac
 
Old 10-13-2014, 02:35 PM   #2
Gerard Lally
Senior Member
 
Registered: Sep 2009
Location: Leinster, IE
Distribution: Slackware, NetBSD
Posts: 2,177

Rep: Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761
Does the calibre user have write permissions on the log and error files, and execute permission on the var/lib/calibre parent directory?

Code:
ls -la /var/lib | grep calibre
ls -la /var/lib/calibre
 
Old 10-13-2014, 03:43 PM   #3
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106
How do you check that the calibre-server is running?
What do you see when you run the script as "sh -x /path/to/yourscript start" ? Perhaps the script fails halfway.

I use a similar script that starts several calibre content servers, and it has been working for years.

Eric
 
Old 10-13-2014, 07:01 PM   #4
micheal.hd
LQ Newbie
 
Registered: Oct 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
calibre startup script

I had the /var/lib/calibre directory as 0755 and the two log files as 0664.

When I run the script sh -x I get some interesting results:
=====================================================================
Run #1
[michealj@orion run]$ sh -x /etc/rc.d/rc.calibre-server start
+ CONTENT=/usr/local/pub/calibre
+ CALIBRE_LOGFILE=/var/lib/calibre/calibre-server-log
+ CALIBRE_ERRORFILE=/var/lib/calibre/calibre-server-errors
+ PORT=8080
+ CALIBRE_USER=calibre
+ DAEMON=/usr/bin/calibre-server
+ PIDFILE=/var/run/calibre-server.pid
+ ARGS='--auto-reload --with-library=/usr/local/pub/calibre --pidfile=/var/run/calibre-server.pid --port=8080 --daemonize'
+ case "$1" in
+ calibre_start
+ calibre_status
+ ps aux
+ grep /usr/bin/calibre-server
+ grep -v grep
+ return 3
+ '[' 3 = 0 ']'
+ echo 'Starting Calibre Server...'
Starting Calibre Server...
+ exit 0
+ su - calibre -c '/usr/bin/calibre-server --auto-reload --with-library=/usr/local/pub/calibre --pidfile=/var/run/calibre-server.pid --port=8080 --daemonize'
[michealj@orion run]$ /etc/rc.d/rc.calibre-server: line 41: /var/lib/calibre/calibre-server-log: Permission denied

But the permission from the files looked good, RWX on dir and RW on the files. I dont know.

====================================================
Run #2 after I removed the logging from the startup script, I now get another error.
[michealj@orion run]$ sudo sh -x /etc/rc.d/rc.calibre-server start
+ CONTENT=/usr/local/pub/calibre
+ CALIBRE_LOGFILE=/var/lib/calibre/calibre-server-log
+ CALIBRE_ERRORFILE=/var/lib/calibre/calibre-server-errors
+ PORT=8080
+ CALIBRE_USER=calibre
+ DAEMON=/usr/bin/calibre-server
+ PIDFILE=/var/run/calibre-server.pid
+ ARGS='--auto-reload --with-library=/usr/local/pub/calibre --pidfile=/var/run/calibre-server.pid --port=8080 --daemonize'
+ case "$1" in
+ calibre_start
+ calibre_status
+ ps aux
+ grep /usr/bin/calibre-server
+ grep -v grep
+ return 3
+ '[' 3 = 0 ']'
+ echo 'Starting Calibre Server...'
Starting Calibre Server...
+ exit 0
+ su - calibre -c '/usr/bin/calibre-server --auto-reload --with-library=/usr/local/pub/calibre --pidfile=/var/run/calibre-server.pid --port=8080 --daemonize'
[michealj@orion run]$
=========================================================
When I check to see if the server is running:
[michealj@orion run]$ sudo sh -x /etc/rc.d/rc.calibre-server status
+ CONTENT=/usr/local/pub/calibre
+ CALIBRE_LOGFILE=/var/lib/calibre/calibre-server-log
+ CALIBRE_ERRORFILE=/var/lib/calibre/calibre-server-errors
+ PORT=8080
+ CALIBRE_USER=calibre
+ DAEMON=/usr/bin/calibre-server
+ PIDFILE=/var/run/calibre-server.pid
+ ARGS='--auto-reload --with-library=/usr/local/pub/calibre --pidfile=/var/run/calibre-server.pid --port=8080 --daemonize'
+ case "$1" in
+ calibre_status
+ ps aux
+ grep /usr/bin/calibre-server
+ grep -v grep
+ return 3
+ '[' 3 = 0 ']'
+ echo 'Calibre is not running'
Calibre is not running
[michealj@orion run]$
===================================================
I am stumped. Must have something to be with running it as a user. Do you normally run this type of service with root permissions ?
 
Old 10-14-2014, 05:41 PM   #5
micheal.hd
LQ Newbie
 
Registered: Oct 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
The issue has to be around how I created the "calibre" user and when trying to run the script as that user and not root.

Anyone ?
 
Old 10-14-2014, 08:34 PM   #6
saulgoode
Member
 
Registered: May 2007
Distribution: Slackware
Posts: 288

Rep: Reputation: 155Reputation: 155
Code:
su - $CALIBRE_USER -c "$DAEMON $ARGS" > $CALIBRE_LOGFILE 2>$CALIBRE_ERRORFILE &
I believe that the problem is the stdout and stderr redirection occurs before the user is switched -- thus the log and errors files are owned by root, not calibre.

Try moving the second quote to the end of the line.
 
Old 10-17-2014, 07:54 PM   #7
micheal.hd
LQ Newbie
 
Registered: Oct 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Lightbulb

Quote:
Originally Posted by saulgoode View Post
Code:
su - $CALIBRE_USER -c "$DAEMON $ARGS" > $CALIBRE_LOGFILE 2>$CALIBRE_ERRORFILE &
I believe that the problem is the stdout and stderr redirection occurs before the user is switched -- thus the log and errors files are owned by root, not calibre.

Try moving the second quote to the end of the line.
I removed the log files completely and tried su - $CALIBRE_USER -c "$DAEMON $ARGS" & but still no joy.

I think maybe I need to delete this user and start again. There something wrong with the user interaction because if I run the script as root #/usr/bin/calibre-server --with-library=/calibre --daemonize it works.
I tried running the script as my normal user and it failed as well. IS there a group the user must be in for this to work ?
 
  


Reply



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
ANN: Script to package latest (2.5.0) Calibre for Slackware dugan Slackware 4 10-06-2014 12:58 AM
Bash script works different as startup script - any ideas ? robinaspey Linux - Newbie 2 06-11-2014 02:07 PM
apache tomcat startup script not booting at startup. Grtyop Linux - Newbie 2 01-23-2014 02:57 AM
LXer: Search and Read Books from Calibre's Library in Ubuntu 13.10 with Unity Calibre Scope LXer Syndicated Linux News 0 11-22-2013 08:12 PM
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 02:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 03:37 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
Open Source Consulting | Domain Registration