logstash load plugin configuration on server restart - logstash

so if I understand correctly to load logstash with some input config I need to run
bin/logstash -f logstash-simple.conf
how I automate this process so if my server will restart it will auto load some configs?
the docs not talking about this at all
edit: I am not 100% sure but it looks like the configs files shout be on /etc/logstash/conf.d/

use this command for systems that use upstart
sudo systemctl start logstash.service
The required configuration file for upstart systems is
/etc/init/logstash.conf

Related

How to restart a running python script if the Ubuntu 16.04 server crashes automatically?

I have a simple script
#!/usr/bin/env python
# coding: utf-8
i=0
while (True):
print(i)
i=i+1
I want this script to run in background
If the server crashes, I want it to automatically restart an pick where the program left of
How do I do that
You have tu run your script as a service:
The file must have .service extension under /lib/systemd/system/ directory.
Now Your system service has been added to your service. Let’s reload the systemctl daemon to read new file. You need to reload this deamon each time after making any changes in in .service file.
sudo systemctl daemon-reload
Now enable the service to start on system boot, also start the service using the following commands.
sudo systemctl enable dummy.service
sudo systemctl start dummy.service
I personally use supervisord to handle processes. To make your script start where it left off you need some kind of persistence, like a file or a database where you can put the last state of your script and read at the restart.

Filebeat command not found

I am running ELK in a docker container at localhost, I am trying to start filebeat (not through docker container) but I am receiving the error below.
/etc/init.d/filebeat: command not found
Has anyone had similar issues or any idea how to resolve this?
Also they have mentioned:
If you use an init.d script to start Filebeat on deb or rpm, you can’t specify command line flags (see Command Line Options). To specify flags, start Filebeat in the foreground.
But don't understood. I have checked a lot but nothing helped. I am running this in ubuntu 16.10
Sounds like you want to start filebeat on the host but you don't have it installed
https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-installation.html
Since you are using a Linux distribution with systemd, have you tried starting filebeat as a systemd service? Check the status:
systemctl status -l filebeat
If that returns info about the service, then filebeat is set up to be a systemd service, not an init.d spawn. Enable it to have it persist after reboot with:
sudo systemctl enable filebeat
And start it with:
sudo systemctl start filebeat

How to reload nginx config if it is running or start if it's stopped?

I update nginx config files periodically and due to technical issues sometimes it can happen that nginx is not running.
In this case if I run nginx -s reload, I see this error:
nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
How can I reload nginx config with the command from above if it's running or start if it's not running without seeing that error?
If you can't count on the fact that nginx is already running then you should just restart it. But, if you really want the above, assuming you're running on linux/unix and it looks like you are then you can create a tiny shell script. Again, assuming your default shell is bash or bash compatible (other shells would have to be ported) you could do something like this:
#!/bin/sh
if [ -f /run/nginx.pid ]; then
/path/to/nginx -s reload
else
/path/to/whatever/command/starts/nginx
fi
You can take the above to a whole new level by using inotify. Again, assuming you're running a Linux distribution, you can install your OS distribution's inotify-tools package and automate running the above script file every time your config files change. See this for more info on using inotify:
How to execute a command when a file changes

Enabling systemd service with preseed

I'm trying to enable serial-getty#ttyS0.service to output getty to serial console as well as tty0.
I have tried running systemctl enable serial-getty#ttyS0 but I suspect that systemd might not be running when late_command is running.
Then I tried making the symlink manually with ln -s /lib/systemd/system/serial-getty#.service /etc/systemd/system/getty.target.wants/serial-getty#ttyS0.service and after the install getty.target.wants only contains getty#tty1.service.
I can't use console=tty0 console=ttyS0,115200n8 kernel parameter because then messages from the init system and the system logger will only appear on the first serial port and I want them to appear on tty0.
Does anyone have any experience or any idea on how to enable services in preseed config?
Thanks.

Using a Cron Job to check if my mod_wsgi / apache server is running and restart

my group and I are running a server that is based upon Django and uses mod_wsgi to run an Apache server. We will not be working on this project after it is over, so I am attempting to set up cronjob similar functionality to check if the apache server has shut down(system restart or power failure), and if it has, will restart the server for me. I've found documentation on how to check if an apache server is down and restart the server if it is, but our server uses https and thus our start command is pretty verbose.
Can I simply use the functionality provided in these examples:
https://askubuntu.com/questions/277389/cron-job-to-restart-apache
https://www.digitalocean.com/community/tutorials/how-to-use-a-simple-bash-script-to-restart-server-programs
Or do I need a much more complicated process to make this happen?
The command we use to initially start the server is
python manage.py runmodwsgi --host 0.0.0.0 --port 8001 --https-port 8000 --ssl-certificate (certificate Location) --server-name (Domain Name)
I'm pretty new to Linux and using both Mod-wsgi as well as Apache so any help is greatly appreciated.
I suppose it is not good way to resolve this problem.
I recommend you use monit (https://mmonit.com/). It is cool program for checking services.
apt-get install monit
Apache restart configuration directives:
check process httpd with pidfile /var/run/httpd.pid
group apache
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"
if failed host 127.0.0.1 port 80
protocol http then restart
if 5 restarts within 5 cycles then timeout
You are better off using the --setup-only option to mod_wsgi-express or the Django integration for it, to generate the configuration but not run it. Then as others have mentioned, integrate it into the system service manager.
The two commands for starting and stopping the Apache/mod_wsgi instance would be apachectl start and apachectl stop, where apachectl is that which was generated when running with the additional --setup-only option.
When running it as a system service, also make sure you use the --server-root option to specify a more persistent location for the generated configuration. Do not use the default under /tmp if running for anything but temporary development sessions as some Linux systems will remove files under /tmp causing things to start failing after a while.
Also, since under a service manager it would generally be starting as root, particularly if listening on port 80 is a requirement, ensure you use the --user and --group options to specify what user/group your Python web application should run as.
Read:
https://pypi.python.org/pypi/mod_wsgi
for more details of the --setup-only option and start-server commands for generating the configuration. Because you are using the Django integration, you will need to use the --setup-only option.
For more informed helped, bring your issue to the mod_wsgi mailing list. The mod_wsgi-express way of running Apache/mod_wsgi is new enough that unlikely that anyone here is really going to know much about it.
There is no need to do this at all. There is no reason to start up Apache manually; once it's installed as a system service, Ubuntu will start it up automatically on restart or crash.
You should reflect on why you feel the need to do this for Apache specifically, and not any of the other system services you depend on, such as the database.

Resources