I have followed the steps in this tutorial but it wouldn't work.
https://serversforhackers.com/setting-up-mailcatcher
I did however successfully installed mailcatcher and have tested. It is working, however I can't run it as a service.
Anyone knows how to do this in CentOS? Thanks.
All operations made by root or sudoer user.
create file /etc/init.d/mailcatcher
add to it this content (from https://gist.github.com/oppara/c4233b289c86e2b3cb66) :
#!/bin/sh
# chkconfig: 345 99 1
# description: mailcatcher
# processname: mailcatcher
start() {
echo -n "starting mailcatcher:"
/usr/local/rbenv/shims/mailcatcher --http-ip=0.0.0.0
return 0
}
stop() {
killall mailcatcher
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo $"Usage: $0 {start|stop}"
exit 2
esac
exit 0
make file executable:
chmod +x /etc/init.d/mailcatcher
add service available:
chkconfig --add mailcatcher
enable service:
chkconfig mailcatcher on
start or stop service with this command:
service mailcatcher stop|start
Related
I have a server machine that has RHL6 (Red Hat Linux 6) and is based on SysV initialization (does not have systemd package), and I want to make my prometheus node exporter collect metrics from this machine.
All I can find online is how to create a node exporter service with systemctl (systemd): basically you create a .service file under /etc/systemd/system and then write something like this in it:
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
And then you start the service, enable it at startup, etc with systemctl command like this
sudo systemctl start node_exporter
sudo systemctl status node_exporter
sudo systemctl enable node_exporter
But the problem is that I don't have systemd installed and I don't have the right to update the server machine system so I am trying to find a way how to write an init script for node exporter to be placed under /etc/rd.d/init.d in my case.
It seems that all scripts under init.d are shell scripts that declare many methods like start(), stop(), restart(), reload(), force_reload(), ...
So it's not as easy as writing the service based on systemd.
Anyone have an idea how to do that with SysV init ???
Thanks,
I managed to found a solution for my problem.
Here is how the script looks like:
#!/bin/bash
#
# chkconfig: 2345 90 12
# description: node-exporter server
#
# Get function from functions library
. /etc/init.d/functions
# Start the service node-exporter
start() {
echo -n "Starting node-exporter service: "
/usr/sbin/node_exporter_service &
### Create the lock file ###
touch /var/lock/subsys/node-exporter
success $"node-exporter service startup"
echo
}
# Restart the service node-exporter
stop() {
echo -n "Shutting down node-exporter service: "
killproc node_exporter_service
### Now, delete the lock file ###
rm -f /var/lock/subsys/node-exporter
echo
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status node_exporter_service
;;
restart|reload)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
We place the above script under /etc/init.d named "node-exporter" (without .sh) and we place the binary for the node exporter under /usr/sbin (with systemd we place binaries under /usr/local/bin).
You can download the binary file for node exporter from here https://github.com/prometheus/node_exporter/releases.
Then we add the script file to the list of services with command chkconfig --add node-exporter (to check if it already exists use command chkconfig --list node-exporter).
Enable the service with command chkconfig node-exporter on.
And then to start/stop/restart ... we use command /etc/init.d/node-exporter start/stop/restart ....
In the start script we basically run the binary file and in the stop script we kill the process by its name.
I hope this will be useful.
I am trying to develop a script that can restart an activator instance running on a specified port. I normally run my activator project at port 15000 and I am aiming to have it restarted using the script. I can then later call that script from a web page to have activator restarted remotely etc.
So far I found a really handy utility in Linux called fuser which can find a process listening at a specified port and kill it. Something like:
fuser -k 15000/tcp which works fine on linux but NOT on a mac.
I guess I would also need to somehow track the activator project location to start it later.
Please let me know your suggestions and comments on how this can be done.
I'm using a bash file for this. It works on Linux and Mac OS.
It's named loader.sh and put into your distributions root.
To stop it uses the kill command and the PID stored in RUNNING_PID.
#!/bin/bash
# Change IP address and port here
address="127.0.0.1"
port="9000"
# Get directory and add it to PATH
dir="$( cd "$( dirname "$0" )" && pwd )"
export PATH="$dir:$dir/bin:$PATH"
function start() {
# Check if we started already
[ -f $dir/RUNNING_PID ] && return
echo -n "Starting"
# You can specify a config file with -Dconfig.resource
# or a secret with -Dplay.crypto.secret
myApp -Dhttp.port=$port -Dhttp.address=$address > /dev/null &
echo "...started"
}
function stop() {
[ -f $dir/RUNNING_PID ] || return
echo -n "Stopping"
kill -SIGTERM $(cat $dir/RUNNING_PID)
while [ -f $dir/RUNNING_PID ]
do
sleep 0.5
done
echo "...stopped"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: loader.sh start|stop|restart"
exit 1
;;
esac
I have installed nginx-gridfs and followed https://github.com/mdirolf/nginx-gridfs.
Nginx installed successfully.
In nginx.conf file I have specified as below:
server{
location /gridfs/ {
gridfs my_app;
}
}
It throws an error gridfs is unknown directive.
Restarting nginx: nginx: [emerg] unknown directive "gridfs" in /etc/nginx/nginx.conf:69
nginx: configuration file /etc/nginx/nginx.conf test failed
Any one suggest solution.
Thanks,
Prasad.
While compiling nginx from its source code and then installing it using make install it gets installed in /usr/local/nginx instead of the /etc/nginx so the path and daemon created needs to be changed in the nginx scipt(which you have to create manually and link it since compiling from source code won't create its own).
I assume you've already installed nginx from its source code adding the gridfs module.
Now unfortunately, you can't start or stop the service of nginx using the script in /etc/init.d/nginx because installing from the source code won't create a script(if found in /etc/init.d/, then this script is previously generated while installing nginx using package manager)
Then check your nginx status. If it's running then use:
sudo kill `cat /usr/local/nginx/logs/nginx.pid`
then go ahead and create a script:
sudo nano /etc/init.d/nginx
Inside the bank file use this code snippet:
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/nginx/sbin
#DAEMON=/usr/sbin/nginx
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
. /lib/lsb/init-functions
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON || true
sleep 1
start-stop-daemon --start --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
status)
status_of_proc -p /usr/local/nginx/logs/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
exit 1
;;
esac
exit 0
Then make the file executable:
sudo chmod +x /etc/init.d/nginx
Now add the script to the default run levels:
sudo /usr/sbin/update-rc.d -f nginx defaults
That's it. You are done! You can now use the script to start, stop and restart nginx:
sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx restart
Follow this link if you need more help: 1
At the bottom of the page you'll find the link to create the nginx script manually.
I am having a weird problem with mongodb after installation it is ending with a message
invoke-rc.d: unknown initscript, /etc/init.d/mongodb not found.
dpkg: error processing mongodb-10gen (--configure):
What is wrong here I followed the steps given here: http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages
The issue is that you are trying to install a version packaged for Upstart init services, but Debian Squeeze still uses SysV init by default.
There is a note on this in the install docs:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian-or-ubuntu-linux/#installing-mongodb
If you are using Debian or Ubuntu that uses SysV style init process, use the following line:
deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen
This means that you need to create mongodb start script in /etc/init.d/
Try this script
#!/bin/bash
#
# mongodb Startup script for the mongodb server
#
# chkconfig: - 64 36
# description: MongoDB Database Server
#
# processname: mongodb
#
# Source function library
. /lib/lsb/init-functions
if [ -f /etc/sysconfig/mongodb ]; then
. /etc/sysconfig/mongodb
fi
prog="mongod"
mongod="/usr/local/mongodb/bin/mongod"
RETVAL=0
start() {
echo -n $"Starting $prog: "
daemon $mongod "--fork --logpath /var/log/mongodb.log --logappend 2>&1 >>/var/log/mongodb.log"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
}
reload() {
echo -n $"Reloading $prog: "
killproc $prog -HUP
RETVAL=$?
echo
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
fi
;;
reload)
reload
;;
status)
status $mongod
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}"
RETVAL=1
esac
exit $RETVAL
after type in terminal:
sudo chmod +x /etc/init.d/mongodb
sudo /etc/init.d/mongodb start
ps -A | grep mongod
I'm writing a Django app that uses celery. So far I've been running on Ubuntu, but I'm trying to deploy to CentOS.
Celery comes with a nice init.d script for Debian-based distributions, but it doesn't work on RedHat-based distributions like CentOS because it uses start-stop-daemon. Does anybody have an equivalent one for RedHat that uses the same variable conventions so I can reuse my /etc/default/celeryd file?
Is better solved here:
Celery CentOS init script
You should be good using that one
Since I didn't get an answer, I tried to roll my own:
#!/bin/sh
#
# chkconfig: 345 99 15
# description: celery init.d script
# Defines the following variables
# CELERYD_CHDIR
# DJANGO_SETTINGS_MODULE
# CELERYD
# CELERYD_USER
# CELERYD_GROUP
# CELERYD_LOG_FILE
CELERYD_PIDFILE=/var/run/celery.pid
if test -f /etc/default/celeryd; then
. /etc/default/celeryd
fi
# Source function library.
. /etc/init.d/functions
# Celery options
CELERYD_OPTS="$CELERYD_OPTS -f $CELERYD_LOG_FILE -l $CELERYD_LOG_LEVEL"
if [ -n "$2" ]; then
CELERYD_OPTS="$CELERYD_OPTS $2"
fi
start () {
cd $CELERYD_CHDIR
daemon --user $CELERYD_USER --pidfile $CELERYD_PIDFILE $CELERYD $CELERYD_OPTS &
}
stop () {
if [[ -s $CELERYD_PIDFILE ]] ; then
echo "Stopping Celery"
killproc -p $CELERYD_PIDFILE python
echo "done!"
rm -f $CELERYD_PIDFILE
else
echo "Celery not running."
fi
}
check_status() {
status -p $CELERYD_PIDFILE python
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
check_status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac