LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-22-2015, 02:26 PM   #1
spadez
LQ Newbie
 
Registered: Jul 2012
Posts: 5

Rep: Reputation: Disabled
Creating an init script for uwsgi using a deployment script


I modified the uwsgi init.d script for debian from the apt-get package download. This is the script I have below:

Quote:
#!/bin/sh
### BEGIN INIT INFO
# Provides: uwsgi
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: This script manages uWSGI Emperor server instance(s).
### END INIT INFO

DAEMON=/var/www/app/venv/bin/uwsgi
PIDFILE=/var/run/uwsgi.pid
DAEMON_ARGS="--ini /var/www/app/conf/uwsgi/app.ini --pidfile /var/run/uwsgi.pid"

. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start()
{
if [ "$ENABLED" != yes ]; then
[ "$VERBOSE" != no ] && log_progress_msg "(disabled; see /etc/default/uwsgi)"
return 2
fi
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS 1> /dev/null 2>&1 \
|| return 2
}
do_stop()
{
start-stop-daemon --stop --quiet --retry=QUIT/30/KILL/5 --pidfile $PIDFILE --name uwsgi
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
rm -f $PIDFILE
return "$RETVAL"
}
do_reload()
{
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name uwsgi
return 0
}

case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "uwsgi" && exit 0 || exit $?
;;
reload|force-reload)
log_daemon_msg "Reloading"
do_reload
log_end_msg $?
;;
restart)
log_daemon_msg "Restarting"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;;
*) log_end_msg 1 ;;
esac
;;
*)
log_end_msg 1
;;
esac
;;
*)
echo "Usage: /etc/init.d/uwsgi {start|stop|status|restart|reload|force-reload}" >&2
exit 3
;;
esac

:
However when I try to run the following commands:

Quote:
chmod u+x /etc/init.d/uwsgi
update-rc.d uwsgi defaults
service uwsgi start
The result I get is:

Quote:
Usage: /etc/init.d/uwsgi {start|stop|status|restart|reload|force-reload}
However this shouldn't happen for that command. It happens no matter how I try and run it (service uwsgi stop etc). What have I done wrong?

Last edited by spadez; 02-22-2015 at 03:57 PM.
 
Old 02-23-2015, 01:11 PM   #2
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
I suspect no-one has responded because that case statement is a real mess. Is that what the actual formatting looks like in the script?

When I look at that I think it shouldn't work but you are bringing in variables and functions from other scripts and testing them in a way that makes it impossible to guess at how it would go.

Try breaking it down to a simpler statement and building it up. Make sure whatever you post is formatted so it's readable and easy to see what it's supposed to do.
 
  


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
[SOLVED] can i write a shell script in /etc/init.d that will run a python script? lapishater276 Debian 1 06-27-2014 03:23 PM
[SOLVED] why init script cannot source init tools unless session root linuxecho Linux - Newbie 8 02-17-2014 05:17 PM
Creating links to an init script. slash1981 Linux - Newbie 4 12-20-2009 05:26 PM
Init script in /etc/init.d does not start at boot tdnnash25 Linux - Server 4 12-18-2009 04:40 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:25 PM.

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