I'm getting an error Syntax error: EOF in backquote substitution and I don't have the faintest idea why. Would anyone mind taking a quick look?
#! /bin/sh
# chkconfig 345 85 60
# description: startup script for produtcrawler-router
# processname: producrawler-router
NAME=productcrawler-router
DIR=/etc/productcrawler/services
EXEC=router.py
PID_FILE=/var/run/productcrawler.pid
IEXE=/etc/init.d/productcrawler-router
RUN_AS=root
### BEGIN INIT INFO
# Provides: productcrawler-router
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 5
# Default-Stop: 0 1 2 3 6
# Description: Starts the productcrawler-router service
### END INIT INFO
if [ ! -f $DIR/$EXEC ]
then
echo "$DIR/$EXEC not found."
exit
fi
case "$1" in
start)
echo -n "Starting $NAME"
cd $LDIR
start-stop-daemon -d $DIR --start --background --pidfile $PID_FILE --make-pidfile --exec $EXEC --quiet
echo "$NAME are now running."
;;
stop)
echo -n "Stopping $NAME"
kill -TERM `cat $PID_FILE
rm $PID_FILE
echo "$NAME."
;;
force-reload|restart)
$0 stop
$0 start
;;
*)
echo "Use: /etc/init.d/$NAME {start|stop|restart|force-reload}"
exit 1
;;
esac
The syntax coloring didn't give it away?
stop)
echo -n "Stopping $NAME"
kill -TERM `cat $PID_FILE
It's the backtick and the end of the kill line.
Related
I had created a deamon in centos 7 to send an email from email queue.
Email queue is implemented in Yii1. That works fine but when I tried to create and run daemon in server but it fails and shows an error :
echo "Error! Could not start MyStaging!"
I am following instructions which I found here.
On inspection I found that PID gets the value 1232 and pgrep -u $RUNAS -f $NAME > /dev/null command returns empty.
Below is my script:
#!/bin/bash
### BEGIN INIT INFO
# Provides: MyStaging
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: This service having purpose to send email from email queue where relevant email push by particular module operation in queue.
### END INIT INFO
SCRIPT="/usr/bin/php5 /home/my/public_html/staging/protected/yiic mailqueue run"
RUNAS=root
NAME=MyStagingMailQueue
PIDFILE=/var/run/$NAME.pid
LOGFILE=/var/log/$NAME.log
start() {
if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE); then
echo 'Service already running' >&2
return 1
fi
echo 'Starting service ' >&2
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
# su -s /bin/sh $RUNAS -c "$CMD" > "$PIDFILE"
# Try with this command line instead of above if not workable
su -c "$CMD" $RUNAS > "$PIDFILE"
sleep 2
PID=$(cat $PIDFILE)
if pgrep -u $RUNAS -f $NAME > /dev/null
then
echo "$NAME is now running, the PID is $PID"
else
echo "Error! Could not start $NAME!"
fi
}
stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
echo 'Service not running' >&2
return 1
fi
echo 'Stopping service ' >&2
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
echo 'Service stopped' >&2
}
status() {
printf "%-50s" "Checking $NAME..."
if [ -f $PIDFILE ]; then
PID=$(cat $PIDFILE)
if [ -z "$(ps axf | grep ${PID} | grep -v grep)" ]; then
printf "%s\n" "The process appears to be dead but pidfile still exists"
else
echo "Running, the PID is $PID"
fi
else
printf "%s\n" "Service not running"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
esac
I don't know what is the issue. Please help me sort it out.
Since you're using CentOS 7, it's better to create a systemd service.
Step1:
Create a service file for your service say yiicmail.service. Do :
sudo touch /etc/systemd/system/yiicmail.service
Step2:
Open the the above file with your favourite editor and put the below content in it:
[Unit]
Description=yiic service
After=network.target
[Service]
Type=simple
User=root
ExecStart="/usr/bin/php5 /home/whizbite/public_html/staging/protected/yiic mailqueue run"
#If there are spaces, I would strings within quotes like above
Restart=on-abort
[Install]
WantedBy=multi-user.target
Step3:
Now it is the time to play with the service. To start it, do :
sudo systemctl start yiicmail # You don't have to type full name, that is, yiicmail.service
To check the status, do :
sudo systemctl status yiicmail
To stop it, do :
sudo systemctl stop yiicmail
To start the service at boot, do :
sudo systemctl enable yiicmail
To disable the service at boot, do:
sudo systemctl disable yiicmail
Hope this helps.
I want that aria2 starts when the system is booting. I found different init.d scripts but non of them is working for me...
Can you tell me whats wrong with that init.d script?
#!/bin/sh
### BEGIN INIT INFO
# Provides: Aria2
# Required-Start: $network $local_fs $remote_fs
# Required-Stop:: $network $local_fs $remote_fs
# Should-Start: $all
# Should-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Aria2 - Download Manager
### END INIT INFO
NAME=aria2c
ARIA2C=/usr/local/bin/$NAME
PIDFILE=/var/run/$NAME.pid
CONF=/etc/aria2/aria2.conf
ARGS="--conf-path=${CONF} --enable-rpc --rpc-listen-all --daemon"
USER="aria2"
test -f $ARIA2C || exit 0
. /lib/lsb/init-functions
case "$1" in
start) log_daemon_msg "Starting aria2c" "aria2c"
start-stop-daemon --start --quiet -b -m --pidfile $PIDFILE --chuid $USER --startas $ARIA2C -- $ARGS
log_end_msg $?
;;
stop) log_daemon_msg "Stopping aria2c" "aria2c"
start-stop-daemon --stop --quiet --pidfile $PIDFILE
log_end_msg $?
;;
restart|reload|force-reload)
log_daemon_msg "Restarting aria2c" "aria2c"
start-stop-daemon --stop --retry 5 --quiet --pidfile $PIDFILE
start-stop-daemon --start --quiet -b -m --pidfile $PIDFILE --chuid $USER --startas $ARIA2C -- $ARGS
log_end_msg $?
;;
status)
status_of_proc -p $PIDFILE $ARIA2C aria2c && exit 0 || exit $?
;;
*) log_action_msg "Usage: /etc/init.d/aria2c {start|stop|restart|reload|force-reload|status}"
exit 2
;;
esac
exit 0
When I start, it says
[ ok ] Starting aria2c: aria2c.
But when i take a look with
/etc/init.d/aria2c status
it says
[FAIL] aria2c is not running ... failed!
Appreciate your help!
Try this:
#!/bin/sh
### BEGIN INIT INFO
# Provides: aria2
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: aria2c init script.
# Description: Starts and stops aria2 daemon.
### END INIT INFO
USER="root"
DAEMON=/usr/bin/aria2c
CONF=/etc/aria2/aria2.conf
start() {
if [ -f $CONF ]; then
logger -st ARIA2C "Starting aria2c daemon..."
nohup start-stop-daemon -S -c $USER -x $DAEMON -- -D --enable-rpc --conf-path=$CONF
else
logger -st ARIA2C "Couldn't start aria2 daemon (no $CONF found)"
fi
}
stop() {
logger -st ARIA2C "Stoping aria2c daemon..."
start-stop-daemon -o -c $USER -K -u $USER -x $DAEMON
}
status() {
dbpid=`pgrep -fu $USER $DAEMON`
if [ -z "$dbpid" ]; then
logger -st ARIA2C "aria2c daemon not running."
else
logger -st ARIA2C "aria2c daemon running..."
fi
}
case "$1" in
start)
start
sleep 1
;;
stop)
stop
sleep 1
;;
restart)
stop
sleep 2
start
;;
status)
status
;;
*)
echo "Usage: {start|stop|restart|status}"
exit 1
esac
exit 0
You must edit your config file in /etc/aria2/aria2.conf
In this file paste this:
daemon=true
enable-rpc=true
rpc-listen-port=6800
rpc-listen-all=true
####### your download folder, ensure that this folder exist! ##########
dir=/tmp
where is your logfile located
log=/var/log/aria2.log
log-level=warn
dht-listen-port=6801
auto-save-interval=30
#seed ratio and seed time in minutes
seed-ratio=1.0
seed-time=1460
max-upload-limit=20K
event-poll=select
With these files (/etc/init.d/aria2d and /etc/aria2/aria2.conf) aria work, when i run manually -> sudo /etc/init.d/aria2d start
Unfortunately aria don't start automatically when i reboot system.
This question already has an answer here:
Syntax error of ";; unexpected" on simple init script for Debian
(1 answer)
Closed 4 years ago.
It seems like the colons should be there from the tutorials I am reading, and yet it is telling me to remove them?
/etc/init.d/uwsgi: 27: /etc/init.d/uwsgi: Syntax error: ";;" unexpected
Here is my code:
#!/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.
### 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
case "$1" in
start)
echo "Starting"
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
esac
;;
stop)
echo "Stopping"
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"
esac
;;
status)
status_of_proc "$DAEMON" "uwsgi" && exit 0 || exit $?
;;
reload)
echo "Reloading"
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name uwsgi
return 0
;;
*)
echo "Usage: /etc/init.d/uwsgi {start|stop|status|reload|force-reload}" >&2
exit 3
;;
esac
The proper syntax for the case statement is:
case expression in
pattern1)
statements
;;
pattern2)
statements
;;
esac
i.e. just closed with a single esac at the end. Anything else is just going to cause a syntax error.
You can feed scripts into ShellCheck, which does on-line script checking and will indicate where the syntax error is (which you can highlight in the input that you're pasting in here).
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
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