SlackwareThis Forum is for the discussion of Slackware Linux.
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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 &
}
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.
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 ?
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.
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 ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.