I'm trying to create a service script in /etc/init.d to run my shell script wich is under /home/user !!
here a part of my script :
#! /bin/sh
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/home/user/workspace/eattogether/app-server/app.server.core/target/wisdom
DESC="chameleon service"
NAME=chameleon.sh
DAEMON=/home/user/workspace/eattogether/app-server/app.server.core/target/wisdom/$NAME
DAEMON_ARGS="start"
PIDFILE=/home/user/workspace/eattogether/app-server/app.server.core/target/wisdom/CHAMELEON.pid
SCRIPTNAME=/etc/init.d/spheros
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
do_start()
{
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 \
|| return 2
}
do_stop()
{
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
rm -f $PIDFILE
return "$RETVAL"
}
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
when I tr to execute this script i got an error : cannot access ./bin/*.jar: No such file or directory
here my other script :
# Check if the RUNNING_PID file is not there already
if [ -f RUNNING_PID ]; then
echo "[error] RUNNING_PID existing. Is this chameleon already running?"
exit 1
fi
#CLASSPATH=$(JARS=("bin"/*.jar); IFS=:; echo "${JARS[*]}")
for i in `ls ./bin/*.jar`
do
CLASSPATH=${CLASSPATH}:${i}
done
if test "$1" = "--interactive"; then
"$JAVA" -cp ${CLASSPATH} ${JVM_ARGS} -Dchameleon.home=$dir org.ow2.chameleon.core.Main "$#"
else
"$JAVA" -cp ${CLASSPATH} ${JVM_ARGS} -Dchameleon.home=$dir org.ow2.chameleon.core.Main "$#" &
echo $! > RUNNING_PID
fi
any idea how to resolve this ?? tell the service to use the directory where the script is located ???
thanks jackman for the reply,
I did found a solution for this issue. I decided to use :
start-stop-daemon --chdir /path/to/my/script
this solved my problem.
You could add this to the daemon script:
cd -P "$(dirname "$0")"
But don't do this:
for i in `ls ./bin/*.jar`
do this instead
for i in ./bin/*.jar
and let the shell expand the filenames for you.
You should quote variables like "$this" not like ${this}
Related
Trying to deploy jboss eap 7 server in linux environment which got deployed in windows (same server configuration is working fine in windows) giving this issue
RROR [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 103) Context initialization failed:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reportBeanService':
Invocation of init method failed; nested exception is javax.naming.NamingException: WFLYNAM0062:
Failed to lookup EAR_Name/Module/Bean!com.src.ejb.BeanRemote [Root exception is java.lang.NoClassDefFoundError: Could not initialize Class com.sun.proxy.$Proxy73]
Any idea what can be the issue here or if you guys have faced the same issue please respond
this is my standalone.sh (this is the only file which is different from my windows version)
#!/bin/sh
# Use --debug to activate debug mode with an optional argument to specify the port.
# Usage : standalone.sh --debug
# standalone.sh --debug 9797
# By default debug mode is disable.
DEBUG_MODE="${DEBUG:-false}"
DEBUG_PORT="${DEBUG_PORT:-8787}"
SERVER_OPTS=""
while [ "$#" -gt 0 ]
do
case "$1" in
--debug)
DEBUG_MODE=true
if [ -n "$2" ] && [ "$2" = `echo "$2" | sed 's/-//'` ]; then
DEBUG_PORT=$2
shift
fi
;;
-Djava.security.manager*)
echo "ERROR: The use of -Djava.security.manager has been removed. Please use the -secmgr command line argument or SECMGR=true environment variable."
exit 1
;;
-secmgr)
SECMGR="true"
;;
--)
shift
break;;
*)
SERVER_OPTS="$SERVER_OPTS '$1'"
;;
esac
shift
done
DIRNAME=`dirname "$0"`
PROGNAME=`basename "$0"`
GREP="grep"
# Use the maximum available, or set MAX_FD != -1 to use that
MAX_FD="maximum"
# OS specific support (must be 'true' or 'false').
cygwin=false;
darwin=false;
linux=false;
solaris=false;
freebsd=false;
other=false
case "`uname`" in
CYGWIN*)
cygwin=true
;;
Darwin*)
darwin=true
;;
FreeBSD)
freebsd=true
;;
Linux)
linux=true
;;
SunOS*)
solaris=true
;;
*)
other=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$JBOSS_HOME" ] &&
JBOSS_HOME=`cygpath --unix "$JBOSS_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$JAVAC_JAR" ] &&
JAVAC_JAR=`cygpath --unix "$JAVAC_JAR"`
fi
# Setup JBOSS_HOME
RESOLVED_JBOSS_HOME=`cd "$DIRNAME/.." >/dev/null; pwd`
if [ "x$JBOSS_HOME" = "x" ]; then
# get the full path (without any relative bits)
JBOSS_HOME=$RESOLVED_JBOSS_HOME
else
SANITIZED_JBOSS_HOME=`cd "$JBOSS_HOME"; pwd`
if [ "$RESOLVED_JBOSS_HOME" != "$SANITIZED_JBOSS_HOME" ]; then
echo ""
echo " WARNING: JBOSS_HOME may be pointing to a different installation - unpredictable results may occur."
echo ""
echo " JBOSS_HOME: $JBOSS_HOME"
echo ""
sleep 2s
fi
fi
export JBOSS_HOME
# Read an optional running configuration file
if [ "x$RUN_CONF" = "x" ]; then
RUN_CONF="$DIRNAME/standalone.conf"
fi
if [ -r "$RUN_CONF" ]; then
. "$RUN_CONF"
fi
JAVA_OPTS="-Denvprop.loc="/home/user1/wildfly-10.0.0.Final/bin/environment.properties" -Djboss.ejb.client.properties.file.path="/home/user1/wildfly-10.0.0.Final/bin/jboss-ejb-client.properties" -Dfa.dfprimary=DFSERVER1 -Dfa.dfsecondary=DFSERVER1 -Dfa.servername=DFSERVER1 -Dfa.init.log4j=true -Dfa.log.config.location="/home/scm/FirstGen_JBOSS7/config/log4j.xml" -DLog2DB=true -server -agentlib:jdwp=transport=dt_socket,address=9999,server=y,suspend=n"
# Set debug settings if not already set
if [ "$DEBUG_MODE" = "true" ]; then
DEBUG_OPT=`echo $JAVA_OPTS | $GREP "\-agentlib:jdwp"`
if [ "x$DEBUG_OPT" = "x" ]; then
JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,address=$DEBUG_PORT,server=y,suspend=n"
else
echo "Debug already enabled in JAVA_OPTS, ignoring --debug argument"
fi
fi
# Setup the JVM
if [ "x$JAVA" = "x" ]; then
if [ "x$JAVA_HOME" != "x" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA="java"
fi
fi
if [ "$PRESERVE_JAVA_OPTS" != "true" ]; then
# Check for -d32/-d64 in JAVA_OPTS
JVM_D64_OPTION=`echo $JAVA_OPTS | $GREP "\-d64"`
JVM_D32_OPTION=`echo $JAVA_OPTS | $GREP "\-d32"`
# Check If server or client is specified
SERVER_SET=`echo $JAVA_OPTS | $GREP "\-server"`
CLIENT_SET=`echo $JAVA_OPTS | $GREP "\-client"`
if [ "x$JVM_D32_OPTION" != "x" ]; then
JVM_OPTVERSION="-d32"
elif [ "x$JVM_D64_OPTION" != "x" ]; then
JVM_OPTVERSION="-d64"
elif $darwin && [ "x$SERVER_SET" = "x" ]; then
# Use 32-bit on Mac, unless server has been specified or the user opts are incompatible
"$JAVA" -d32 $JAVA_OPTS -version > /dev/null 2>&1 && PREPEND_JAVA_OPTS="-d32" && JVM_OPTVERSION="-d32"
fi
if [ "x$CLIENT_SET" = "x" -a "x$SERVER_SET" = "x" ]; then
# neither -client nor -server is specified
if $darwin && [ "$JVM_OPTVERSION" = "-d32" ]; then
# Prefer client for Macs, since they are primarily used for development
PREPEND_JAVA_OPTS="$PREPEND_JAVA_OPTS -client"
else
PREPEND_JAVA_OPTS="$PREPEND_JAVA_OPTS -server"
fi
fi
# EAP6-121 feature disabled
# Enable rotating GC logs if the JVM supports it and GC logs are not already enabled
#NO_GC_LOG_ROTATE=`echo $JAVA_OPTS | $GREP "\-verbose:gc"`
#if [ "x$NO_GC_LOG_ROTATE" = "x" ]; then
# backup prior gc logs
#mv "$JBOSS_LOG_DIR/gc.log.0" "$JBOSS_LOG_DIR/backupgc.log.0" >/dev/null 2>&1
#mv "$JBOSS_LOG_DIR/gc.log.1" "$JBOSS_LOG_DIR/backupgc.log.1" >/dev/null 2>&1
#mv "$JBOSS_LOG_DIR/gc.log.2" "$JBOSS_LOG_DIR/backupgc.log.2" >/dev/null 2>&1
#mv "$JBOSS_LOG_DIR/gc.log.3" "$JBOSS_LOG_DIR/backupgc.log.3" >/dev/null 2>&1
#mv "$JBOSS_LOG_DIR/gc.log.4" "$JBOSS_LOG_DIR/backupgc.log.4" >/dev/null 2>&1
#mv "$JBOSS_LOG_DIR/gc.log.*.current" "$JBOSS_LOG_DIR/backupgc.log.current" >/dev/null 2>&1
#"$JAVA" $JVM_OPTVERSION -verbose:gc -Xloggc:"$JBOSS_LOG_DIR/gc.log" -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -XX:-TraceClassUnloading -version >/dev/null 2>&1 && mkdir -p $JBOSS_LOG_DIR && PREPEND_JAVA_OPTS="$PREPEND_JAVA_OPTS -verbose:gc -Xloggc:\"$JBOSS_LOG_DIR/gc.log\" -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -XX:-TraceClassUnloading"
#fi
JAVA_OPTS="$PREPEND_JAVA_OPTS $JAVA_OPTS"
fi
if [ "x$JBOSS_MODULEPATH" = "x" ]; then
JBOSS_MODULEPATH="$JBOSS_HOME/modules"
fi
if $linux; then
# consolidate the server and command line opts
CONSOLIDATED_OPTS="$JAVA_OPTS $SERVER_OPTS"
# process the standalone options
for var in $CONSOLIDATED_OPTS
do
# Remove quotes
p=`echo $var | tr -d "'"`
case $p in
-Djboss.server.base.dir=*)
JBOSS_BASE_DIR=`readlink -m ${p#*=}`
;;
-Djboss.server.log.dir=*)
JBOSS_LOG_DIR=`readlink -m ${p#*=}`
;;
-Djboss.server.config.dir=*)
JBOSS_CONFIG_DIR=`readlink -m ${p#*=}`
;;
esac
done
fi
if $solaris; then
# consolidate the server and command line opts
CONSOLIDATED_OPTS="$JAVA_OPTS $SERVER_OPTS"
# process the standalone options
for var in $CONSOLIDATED_OPTS
do
# Remove quotes
p=`echo $var | tr -d "'"`
case $p in
-Djboss.server.base.dir=*)
JBOSS_BASE_DIR=`echo $p | awk -F= '{print $2}'`
;;
-Djboss.server.log.dir=*)
JBOSS_LOG_DIR=`echo $p | awk -F= '{print $2}'`
;;
-Djboss.server.config.dir=*)
JBOSS_CONFIG_DIR=`echo $p | awk -F= '{print $2}'`
;;
esac
done
fi
# No readlink -m on BSD
if $darwin || $freebsd || $other ; then
# consolidate the server and command line opts
CONSOLIDATED_OPTS="$JAVA_OPTS $SERVER_OPTS"
# process the standalone options
for var in $CONSOLIDATED_OPTS
do
# Remove quotes
p=`echo $var | tr -d "'"`
case $p in
-Djboss.server.base.dir=*)
JBOSS_BASE_DIR=`cd ${p#*=} ; pwd -P`
;;
-Djboss.server.log.dir=*)
if [ -d "${p#*=}" ]; then
JBOSS_LOG_DIR=`cd ${p#*=} ; pwd -P`
else
#since the specified directory doesn't exist we don't validate it
JBOSS_LOG_DIR=${p#*=}
fi
;;
-Djboss.server.config.dir=*)
JBOSS_CONFIG_DIR=`cd ${p#*=} ; pwd -P`
;;
esac
done
fi
# determine the default base dir, if not set
if [ "x$JBOSS_BASE_DIR" = "x" ]; then
JBOSS_BASE_DIR="$JBOSS_HOME/standalone"
fi
# determine the default log dir, if not set
if [ "x$JBOSS_LOG_DIR" = "x" ]; then
JBOSS_LOG_DIR="$JBOSS_BASE_DIR/log"
fi
# determine the default configuration dir, if not set
if [ "x$JBOSS_CONFIG_DIR" = "x" ]; then
JBOSS_CONFIG_DIR="$JBOSS_BASE_DIR/configuration"
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
JBOSS_HOME=`cygpath --path --windows "$JBOSS_HOME"`
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
JBOSS_MODULEPATH=`cygpath --path --windows "$JBOSS_MODULEPATH"`
JBOSS_BASE_DIR=`cygpath --path --windows "$JBOSS_BASE_DIR"`
JBOSS_LOG_DIR=`cygpath --path --windows "$JBOSS_LOG_DIR"`
JBOSS_CONFIG_DIR=`cygpath --path --windows "$JBOSS_CONFIG_DIR"`
fi
if [ "x$JBOSS_MODULEPATH" = "x" ]; then
JBOSS_MODULEPATH="$JBOSS_HOME/modules"
fi
# Process the JAVA_OPTS and fail the script of a java.security.manager was found
SECURITY_MANAGER_SET=`echo $JAVA_OPTS | $GREP "java\.security\.manager"`
if [ "x$SECURITY_MANAGER_SET" != "x" ]; then
echo "ERROR: The use of -Djava.security.manager has been removed. Please use the -secmgr command line argument or SECMGR=true environment variable."
exit 1
fi
# Set up the module arguments
MODULE_OPTS=""
if [ "$SECMGR" = "true" ]; then
MODULE_OPTS="$MODULE_OPTS -secmgr";
fi
# Display our environment
echo "========================================================================="
echo ""
echo " JBoss Bootstrap Environment"
echo ""
echo " JBOSS_HOME: $JBOSS_HOME"
echo ""
echo " JAVA: $JAVA"
echo ""
echo " JAVA_OPTS: $JAVA_OPTS"
echo ""
echo "========================================================================="
echo ""
while true; do
if [ "x$LAUNCH_JBOSS_IN_BACKGROUND" = "x" ]; then
# Execute the JVM in the foreground
eval \"$JAVA\" -D\"[Standalone]\" $JAVA_OPTS \
\"-Dorg.jboss.boot.log.file="$JBOSS_LOG_DIR"/server.log\" \
\"-Dlogging.configuration=file:"$JBOSS_CONFIG_DIR"/logging.properties\" \
-jar \""$JBOSS_HOME"/jboss-modules.jar\" \
$MODULE_OPTS \
-mp \""${JBOSS_MODULEPATH}"\" \
org.jboss.as.standalone \
-Djboss.home.dir=\""$JBOSS_HOME"\" \
-Djboss.server.base.dir=\""$JBOSS_BASE_DIR"\" \
"$SERVER_OPTS"
JBOSS_STATUS=$?
else
# Execute the JVM in the background
eval \"$JAVA\" -D\"[Standalone]\" $JAVA_OPTS \
\"-Dorg.jboss.boot.log.file="$JBOSS_LOG_DIR"/server.log\" \
\"-Dlogging.configuration=file:"$JBOSS_CONFIG_DIR"/logging.properties\" \
-jar \""$JBOSS_HOME"/jboss-modules.jar\" \
$MODULE_OPTS \
-mp \""${JBOSS_MODULEPATH}"\" \
org.jboss.as.standalone \
-Djboss.home.dir=\""$JBOSS_HOME"\" \
-Djboss.server.base.dir=\""$JBOSS_BASE_DIR"\" \
"$SERVER_OPTS" "&"
JBOSS_PID=$!
# Trap common signals and relay them to the jboss process
trap "kill -HUP $JBOSS_PID" HUP
trap "kill -TERM $JBOSS_PID" INT
trap "kill -QUIT $JBOSS_PID" QUIT
trap "kill -PIPE $JBOSS_PID" PIPE
trap "kill -TERM $JBOSS_PID" TERM
if [ "x$JBOSS_PIDFILE" != "x" ]; then
echo $JBOSS_PID > $JBOSS_PIDFILE
fi
# Wait until the background process exits
WAIT_STATUS=128
while [ "$WAIT_STATUS" -ge 128 ]; do
wait $JBOSS_PID 2>/dev/null
WAIT_STATUS=$?
if [ "$WAIT_STATUS" -gt 128 ]; then
SIGNAL=`expr $WAIT_STATUS - 128`
SIGNAL_NAME=`kill -l $SIGNAL`
echo "*** JBossAS process ($JBOSS_PID) received $SIGNAL_NAME signal ***" >&2
fi
done
if [ "$WAIT_STATUS" -lt 127 ]; then
JBOSS_STATUS=$WAIT_STATUS
else
JBOSS_STATUS=0
fi
if [ "$JBOSS_STATUS" -ne 10 ]; then
# Wait for a complete shudown
wait $JBOSS_PID 2>/dev/null
fi
if [ "x$JBOSS_PIDFILE" != "x" ]; then
grep "$JBOSS_PID" $JBOSS_PIDFILE && rm $JBOSS_PIDFILE
fi
fi
if [ "$JBOSS_STATUS" -eq 10 ]; then
echo "Restarting application server..."
else
exit $JBOSS_STATUS
fi
done
This is an interesting snippet:
Failed to lookup FG_PMD_N6.2.2.4_20170828/ficclaim/ClaimsWebServiceBean!com.firstapex.fic.claims.ejb.ClaimsWebServiceBeanRemote
So it looks like a problem with a user application.
Maybe start with a 'clean' jboss application server (no user apps), then deploy them one by one. You might get some clues as the troubled application deploys.
I have install elasticsearch 2.3.3 in centos 7 but after closing terminal elasticsearch plugin head automatically close but I want keep running in background. please give me helpful answer.
You can run it in background as two ways,
1. Nohup
2. Creating service script and put it in init.d folder
Nohup
Eg: nohup ./bin/elasticsearch
Service script
Use the following script,
#!/bin/bash
### BEGIN INIT INFO
# Provides: Elasticsearch
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Runs elasticsearch daemon
# Description: Runs the elasticsearch daemon as a non-root user
### END INIT INFO
# Process name
NAME=elasticsearch
DESC="Elasticsearch"
PROG="/etc/init.d/elasticsearch"
# Configure location of Elasticsearch bin
ELASTICSEARCH_BIN=/opt/elasticsearch-2.3.0/bin
# PID Info
PID_FOLDER=/var/run/elasticsearch/
PID_FILE=/var/run/elasticsearch/$NAME.pid
LOCK_FILE=/var/lock/subsys/$NAME
PATH=/bin:/usr/bin:/sbin:/usr/sbin:$ELASTICSEARCH_BIN
DAEMON=$ELASTICSEARCH_BIN/$NAME
# Configure logging location
ELASTICSEARCH_LOG=/var/log/elasticsearch.log
# Begin Script
RETVAL=0
if [ `id -u` -ne 0 ]; then
echo "You need root privileges to run this script"
exit 1
fi
# Function library
. /etc/init.d/functions
start() {
echo -n "Starting $DESC : "
pid=`pidofproc -p $PID_FILE elasticsearch`
if [ -n "$pid" ] ; then
echo "Already running."
exit 0
else
# Start Daemon
if [ ! -d "$PID_FOLDER" ] ; then
mkdir $PID_FOLDER
fi
daemon --user=$DAEMON_USER --pidfile=$PID_FILE $DAEMON 1>"$ELASTICSEARCH_LOG" 2>&1 &
sleep 2
pidofproc node > $PID_FILE
RETVAL=$?
[[ $? -eq 0 ]] && success || failure
echo
[ $RETVAL = 0 ] && touch $LOCK_FILE
return $RETVAL
fi
}
reload()
{
echo "Reload command is not implemented for this service."
return $RETVAL
}
stop() {
echo -n "Stopping $DESC : "
killproc -p $PID_FILE $DAEMON
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $PID_FILE $LOCK_FILE
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p $PID_FILE $DAEMON
RETVAL=$?
;;
restart)
stop
start
;;
reload)
reload
;;
*)
# Invalid Arguments, print the following message.
echo "Usage: $0 {start|stop|status|restart}" >&2
exit 2
;;
esac
sudo chmod +x /etc/init.d/elasticsearch
sudo update-rc.d elasticsearch defaults 96 9
sudo /etc/init.d/elasticsearch restart
I have installed mumudvb manually based on instructions in here
https://github.com/braice/MuMuDVB
to get the starting scripts working i executed these commands
cp scripts/debian/etc/default/mumudvb /etc/default/mumudvb
cp scripts/debian/etc/init.d/mumudvb /etc/init.d/mumudvb
/etc/default/mumudvb :
#Mumudvb init config file
#
# This file is used to specify the locations of mumudvb config files for each card
#
#If you don't want to automatically start mumudvb, uncomment this line
#DONTSTARTMUMU=true
#If you want to launch a command before mumudvb (for example for automatic configuration generation)
#LAUNCH_BEFORE_MUMU=""
#Options for mumudvb
DAEMON_OPTS=""
#The user to launch mumudvb
DAEMONUSER="username"
#Change this line to reflect your configuration
#Ex : ADAPTERS="0 1 2 4"
ADAPTERS="0"
#Location of the config files
#Ex : MUMUDVB_CONF_1="/etc/mumudvb/card1.conf"
MUMUDVB_CONF_0="/etc/mumudvb/card0.conf"
this is the init.d/mumudvb script :
#!/bin/sh
### BEGIN INIT INFO
# Provides: mumudvb
# Required-Start: $remote_fs $network $syslog
# Required-Stop: $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: mumudvb
# Description: Digital television streaming program
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/mumudvb
PIDDIR=/var/run/mumudvb
DEFAULT_FILE=/etc/default/mumudvb
NAME=mumudvb
DESC="television streaming program"
#Reading of the config file
if [ -f "$DEFAULT_FILE" ] ; then
. "$DEFAULT_FILE"
fi
if [ "$DONTSTARTMUMU" = "true" ]; then exit 0; fi
. /lib/lsb/init-functions
test -x $DAEMON || exit 5
set -e
do_start() {
if [ ! -d $PIDDIR ]; then
mkdir -p $PIDDIR
fi
chown $DAEMONUSER $PIDDIR
if [ -x "$LAUNCH_BEFORE_MUMU" ]; then
log_daemon_msg "Launching pre script ..."
eval $LAUNCH_BEFORE_MUMU
log_daemon_msg "Done."
fi
for ADAPTER in $ADAPTERS; do
#Todo : fails if all card fails
log_daemon_msg " Starting card $ADAPTER"
eval CONFIG_FILE = MUMUDVB_CONF_0
if [ ! -f $CONFIG_FILE ]; then
log_warning_msg " Card $ADAPTER: Config file $CONFIG_FILE not found."
else
start-stop-daemon --start --oknodo --name mumudvb_$ADAPTER\
--make-pidfile --pidfile=$PIDDIR/mumudvb_init_$ADTAPTER.pid\
--chuid $DAEMONUSER --exec $DAEMON -- $DAEMON_OPTS --card $ADAPTER -c $CONFIG_FILE
fi
done
}
do_stop() {
for PIDFILE in `ls $PIDDIR/mumudvb_init_*.pid 2> /dev/null`; do
start-stop-daemon --stop --oknodo --pidfile "$PIDFILE" \
--exec $DAEMON
done
}
case "$1" in
start)
if [ ! -f "$DEFAULT_FILE" ]; then
log_failure_msg "$DEFAULT_FILE not found, Can't start $NAME"
exit 6
fi
log_daemon_msg "Starting $DESC: $NAME"
do_start
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping $DESC: $NAME"
do_stop
log_end_msg $?
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC: $NAME"
do_stop
sleep 1
do_start
log_end_msg $?
;;
status)
status_of_proc "$DAEMON" "$DESC: $NAME" && exit 0 || exit $?
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
when i run :
sudo service mumudvb status
or
sudo service mumudvb start
nothing returns ...
shouldn't it at least return an error or something ?
**note: runing
mumudvb -c /etc/mumudvb/card0.conf
works fine**
in the file /etc/default/mumudvb set DONTSTARTMUMU to false
DONTSTARTMUMU=false
I'm trying to write init.d script to run solr as daemon, but unfortunately ps aux shows that there is no such process.
Here is the code:
#!/bin/sh
start_path=/opt/solr/example/start.jar
JAVA_PATH=/usr/bin/java
PID=/tmp/.solr/pid
ARGS="-jar $start_path"
if [ ! -d /tmp/.solr ]
then
mkdir /tmp/.solr
fi
start(){
echo -n "Starting solr..."
start-stop-daemon --start --background --name "solr" --make-pidfile --pidfile $PID --exec ${JAVA_PATH} -- ${ARGS}
RETVAL="$?"
if [ "$RETVAL" = 0 ]
then
echo "done."
else
echo "failed. See error code for more information."
fi
return $RETVAL
}
case "$1" in
start)
start
;;
*)
echo $"Usage: solr {start}"
exit 3
;;
esac
exit $RETVAL
How about using the command
java jar start.jar & disown
This would start the process and move it to the background...
Hope I helped!
Well, thanks to this blog post, I finally made it.
Here's how it looks:
#!/bin/sh
PIDFILE=/tmp/.solr/pid
if [ ! -d /tmp/.solr ]
then
mkdir /tmp/.solr
fi
cd /opt/solr/example
start(){
if [ ! -f $PIDFILE ]
then
echo "Starting solr..."
nohup java -jar start.jar &
echo $! > $PIDFILE
RETVAL=$?
if [ "$RETVAL" = 0 ]
then
echo "Done."
else
echo "Failed. See error code for more information."
fi
return $RETVAL
echo $! > $PIDFILE
else
echo "Solr is already running"
return 1
fi
}
stop(){
if [ ! -f $PIDFILE ]
then
echo "Solr is not running"
return 1
else
PID=$(cat $PIDFILE)
echo "Stopping solr..."
kill $PID
RETVAL=$?
if [ "$RETVAL" = 0 ]
then
echo "Solr stopped."
rm $PIDFILE
else
echo "Can't stop Solr."
fi
return $RETVAL
fi
}
restart(){
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: solr {start|stop|restart}"
exit 3
;;
esac
exit $RETVAL
EDIT: I am following this example.
Trying to write an archlinux rc.d script for mongod. I put my binaries in /usr/bin. Here is what I got so far:
#!/bin/bash
# import predefined functions
. /etc/rc.conf
. /etc/rc.d/functions
# Point to the binary
DAEMON=/usr/bin/mongod
# Get the ARGS from the conf
. /etc/conf.d/crond
# Function to get the process id
PID=$(get_pid $DAEMON)
case "$1" in
start)
stat_busy "Starting $DAEMON"
# Check the PID exists - and if it does (returns 0) - do no run
[ -z "$PID" ] && $DAEMON $ARGS $> /dev/null
if [ $? = 0 ]; then
add_daemon $DAEMON
stat_done
else
stat_fail
exit 1
fi
;;
stop)
stat_busy "Stopping $DAEMON"
kill -HUP $PID &>/dev/null
rm_daemon $DAEMON
stat_done
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
The problem is that when I do sudo rc.d start mongod, I get the following error:
:: Starting /usr/bin/mongod
[BUSY] /etc/rc.d/functions: line 203: /run/daemons//usr/bin/mongod: No such file or directory
[DONE]
Syntax error.
I used $> instead of &> on the line:
[ -z "$PID" ] && $DAEMON $ARGS $> /dev/null