Mongos auto start script for Linux - mongodb

I have two mongos server in a production environment. I want to start mongos automatically when the server reboots. I tried several options to achieve this, but couldn't. I have three config servers.

This is the easiest way to get it accomplished.
If you are using Linux , it should have 'crontab' installed – a utility which runs cron job.
You need to execute the following command (only once) to automate run of mongos on every start/re-start of your linux machine. Here we are editing the crontab to add a cron job(run script) on every reboot/boot event.
sudo crontab -e
Add a line like this to it:
#reboot /path/to/script
The script should invoke path/to/mongo/bin/mongos -options

Related

ssh to multiple servers in one go

I have to login to multiple hosts at one time, sometimes the number is around 20. The user and pass are same for all the hosts.
Currently to ssh onto these servers I have to run the ssh command manually in power shell and enter the password.
Is there any way I can just provide the servers list along with user/pass and open multiple PowerShell windows in one go? (help me if that can be achieved using ps script)
Sometimes I have to run the same command on all hosts, for that I am using mobaxterm. But again, in this tool as well I have to ssh to servers one by one.
Is there any single tool which can do both the magics (ssh to multiple hosts in one go and I can run commands parallelly)

Jboss EAP 6 CLI Script with commands that require reload

I'm working on a cli script for JBoss EAP 6 (just a bunch of commands in a .bat file).
Now I'm running into issues with commands that rely on each other, where the former sets the server to a "reload-required" state.
For example:
first command: remove default-datasource ExampleDS. Outcome: success, server in state "reload required"
second command: remove h2-driver (required by default datasource). Outcome: failed, since server has not been restarted yet.
I've tried to place a reload command in between, but it seems as if the server is not completely up when the second command gets executed. Outcome still is failed, although if I try it a few seconds later, it works.
/subsystem=datasources/data-source=ExampleDS:remove
reload
/subsystem=datasources/jdbc-driver=h2:remove
Any suggestions how to make the CLI wait until JBoss is completely up again?
Try batching those commands together and doing a reload after you run the batch. For example:
batch
/subsystem=datasources/data-source=ExampleDS:remove
/subsystem=datasources/jdbc-driver=h2:remove
:reload
run-batch
Another option is to run the server to start the server in admin-only mode while configuring it. You should need the reload command in that case, but if you do make sure you use :reload(admin-only=true) until you're done configuring the server.
%JBOSS_HOME%\bin\standalone.bat --admin-only
rem Wait until server is started, then execute the CLI commands
%JBOSS_HOME%\bin\jboss-cli.bat -c --commands="/subsystem=datasources/data-source=ExampleDS:remove,/subsystem=datasources/jdbc-driver=h2:remove"

Can't run Mongo DB deamon in docker container

I'm running docker container in OSX using boot2docker. It is a latest Ubuntu image with mongo installed using official way from package mongodb-org.
I can perfectly run mongod from command line, but can't run it as a service.
When I'm trying to do sudo service mongod start it returns
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mongod start
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mongod
I have tried to do start mongod which doesn't have any output. I have tried everything I found in Google, but no luck.
Meanwhile, I have tried to install MySQL using apt-get and I can perfectly run it as a service.
Also I have tried to install Mongo from Ubuntu's mongodb package which is a older version. Also no problem to run it as a service.
I suspect that there is something wrong with /etc/init.d/mongod script, but don't know exactly what.
Apprieciate any help.
The init-related commands on the Docker Ubuntu image are dummied out / not working because Upstart (/sbin/init) is not the first process started on the machine.
In general, any service which initializes using Upstart will not run properly in a Docker container unless you start the container with /sbin/init (you probably have to be using the ubuntu-upstart image, and make a bunch of tweaks to it too.)
If you really needed to do it this way, write a traditional init script for mongo and insert it using update-rc.d. Then, starting it with /sbin/service should work.
Why not just have the Dockerimage run mongod instead of init/shell/etc? "One process per container", right?
Use a Dockerfile to create your image, and set the CMD to:
CMD ["/usr/bin/mongod", "-f", "/etc/mongod.conf"]

Starting Mongo Query router on system reboot

I have a sharded MongoDB cluster setup running under a single mongos instance. I have added another mongos instance which runs fine with existing configuration.
Problem: I want the two mongos instances to be automatically started when the system reboots.
So far I have created a bash script to start the server and added a crontab entry which supposed to run this bash script at the system startup. But the script is no longer executed by crontab. No log entries or no any errors.
Why is the script not running by CRON? When I manually run the script using bashcommand, it runs fine and starts the server without any problem.
The script looks like below:
#!/bin/bash
mongos --configdb "config0:27020,config1:27020,config2:27020" --port "27017" --logpath "/data/mongodb.log" &
And the crontab entry is:
#reboot /startMongos.sh

Stop or restart beanstalkd manually on command line

Beanstalkd is running on my Ubuntu VPS. I don't know how to stop or shut down the beandstalkd server. I want to stop the server manually on the command line.
I've found monitoring tools and a configurations script, but no commands for the commandline.
Beanstalkd is normally run with the standard OS-level tools (so, on Ubuntu, upstart). There are a number of example configuration scripts for LaunchD, systemD and Upstart in the Beanstalkd repo.
For an Ubuntu system, you would copy the Upstart .conf file, making any required tweaks to the command line you need (to enable the binary log, for example) and drop it into the /etc/init/ directory. Then the usual start, restart, stop & status commands would be able to control the Beanstalkd daemon, and it could be auto-started on bootup.
If it's not already under upstart control, then you can simply kill the process, like anything else, by finding the process ID (pgrep -lf beanstalkd).