auto restart of supervisord in reboot of centos - init

I have a service file /etc/init.d/supervisord , which I can use to start and stop the service by issuing the command
sudo service supervisord start
Now I want to make supervisord auto start when the machine reboot, and I use
chkconfig --add supervisord
However, it returns the error
service supervisord does not support chkconfig
Thus, I want to add two line to make it work with chkconfig in order to make it restart when server reboot
# chkconfig: 345 99 01
# description: some startup script
Is there any problem?

Related

Which config files could disable the automatically starting ssh server, so a headless connect becomes impossible?

Which config files could disable the automatically starting ssh server, so a headless connect becomes impossible?
I need to know the config files that might interfere with the ssh server to normally start up at boot.
I believe that you are looking for the following commands (assuming you are running the last version of raspbian):
sudo systemctl stop sshd
sudo systemctl disable sshd
sudo systemctl mask sshd
stop Basically stops the service immediately. disable disables the service from starting at bootup. Additionally, mask will make it impossible to load the service.
Digging deeper into what each command does, on modern linux distributions there are configuration files for each service called unit files. They are stored (usually) in /usr/lib/systemd. These are basically the evolution of scripts to start services.
the stop command just calls the sshd.service unit file with a stop parameter, in order to shut down the server.
the disable (or enable) command removes(or creates) a symlink of the unit file in a directory where systemd looks into when booting services (usually, /etc/systemd/system).
systemctl mask creates a symlink to /dev/null instead of the unit file. That way the service cant be loaded.

Run a few additional commands after systemctl restart httpd on CentOS

I need to copy a bunch of files into some folder every time the httpd service restarts
e.g.:
yes | cp ./dynamic/*.file /folder/inside/my/webapp
is there a way to run some additional commands when the httpd is restarted?
According to this: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
You can edit the httpd service file with:
sudo systemctl edit --full httpd.service
You should be able to add more directives to the service unit, such as running your additional commands.

Start mongod service at system startup

I recently updated mongodb, and I run Linux Mint (an Ubuntu based system) and every time I start it up, i cannot use Robomongo because the service mongod is not automatically started; every time I need to open up a terminal and use
sudo service mongod start
Is there a way to start mongod automatically at system start?
Use the following command to autostart mongodb when system start.
systemctl enable mongod.service
You can either put the command in your /etc/bashrc script under and if condition i.e. if the mongod process is not already running, then start it.
Other way is to modify your /etc/rc.local and add the command to start mongod in that file. It will start at bootup.
Using crontab on Ubuntu 20 you can try this.
crontab -e
And input this as a crontab entry
#reboot service mongod start

How do I make it so Mongo runs automatically all the time on my Azure server?

I have two Azure virtual machines. On one I have a Mongo server, on the other I just have a service I created which listens to Twitters streaming API and filters tweets.
Neither of these two services work unless I manually activate them and keep my console window open. For example, to run Mongo I need to ssh into my virtual machine and type: mongod --config /etc/mongod.conf. This starts the Mongo server successfully, but if at anytime I close my browser the service stops.
I believe the reason this is occurring is because when I login the system is allocating me a process by which I can navigate around the system and perform commands. When I type mongod --config /etc/mongod.conf I believe I am using that process to run Mongo. I am not sure how to make Mongo run without doing this though.
How do I make it so Mongo runs automatically all the time on my Azure server?
EDIT:
I tried running Mongo as a daemon but I receive an error:
$ mongod --fork --logpath /var/log/mongodb.log
>>>about to fork child process, waiting until server is ready for connections.
>>>forked process: 63470
>>>ERROR: child process failed, exited with error number 1
This issue has nothing to do with Azure; it's all about how you install MongoDB.
If you install mongodb as a service, via apt-get (or whatever other means your version of linux requires), then it will run independent of you being logged in. You shouldn't be running an always-on service through your command shell.
Here are instructions for installing under Ubuntu. You'll see that, once you set up the prerequisite public key and list file, you then run:
sudo apt-get install -y mongodb-org
You can then start and stop the service via
sudo service mongod start
and
sudo service mongod stop
You can enable mongo to autostart on boot by typing this command in your console:
sudo systemctl enable mongod
Then test it by this command:
sudo service mongod status

Centos Service not starting

Running Centos7, I have init.d service that I'm trying to start. When I do so it comes back with an OK message which = success. Yet when I use TOP I don't see it running.
Now if I take the command that the service should be running from the cat /etc/init.d/XXXX it starts as expected.
How can I go about debugging this? I've checked /messages, and /secure and even dmesg but I don't see anything amiss.
Try systemctl start <command>
Eg if you want to start ssh
systemctl start sshd
or
systemctl start sshd.service
Look for man pages of systemctl
Explaination
CentOS 7 / RHEL 7 / Fedora Linux (many other modern distor) uses Systemd. It is a system and service manager for Linux operating systems. In newer distro such as CentOS7/RHEL7 systemd replaces Upstart as the default init system
In case you have scripts for starting & stopping of a particular process or code
you can place a file /etc/init.d/ directory
with somewhat below logic
#!/bin/bash
SCRIPT_PATH=/pathtoscriptdirectory
case $1 in
start)
sh $SCRIPT_PATH/startup.sh
;;
stop)
sh $SCRIPT_PATH/shutdown.sh
;;
restart)
sh $SCRIPT_PATH/shutdown.sh
sh $SCRIPT_PATH/startup.sh
;;
esac
exit 0
Its good practice to make start stop restart blocks, you can have your custom blocks too
Also make sure that you have executable permission over all the files in this lineup
Then run it like you run the normal services