Execute logstash as service on startup


(Danilo Giacchi) #1

Hi i am new to Logstash and i am using the version 5.5.0 and elasticsearch 5.5.0 on xubuntu 16.04.
I'm trying to create a bridge between postgresql 9.6.0 and elasticsearch.
I'm able to execute logstash with configuration file (logstash.conf) in order to manage insert update and delete on postgres.

input {
jdbc {
    jdbc_connection_string => "jdbc:postgresql://localhost:5432/BSS"
    jdbc_user => "postgres"
tags => [ "prodCanc" ]
jdbc_password => "*******"
    jdbc_validate_connection => true
    jdbc_driver_library => "/home/danilo/Desktop/postgresql-42.1.3.jar"
    jdbc_driver_class => "org.postgresql.Driver"
    statement => "SELECT * from prodotti_cancellati"
}
}
output {
if "prodCanc" in [tags]{
	    elasticsearch {
	 action => "delete"
	 index => "prodotti"
	 document_type => "product"
   		 document_id => "%{id}"
   		 hosts => "localhost:9200"

    }
}
}

input {
jdbc {
    jdbc_connection_string => "jdbc:postgresql://localhost:5432/BSS"
    jdbc_user => "postgres"
    tags => [ "prodotti" ]
    jdbc_password => "******"
    jdbc_validate_connection => true
    jdbc_driver_library => "/home/danilo/Desktop/postgresql-42.1.3.jar"
    jdbc_driver_class => "org.postgresql.Driver"
    statement => "SELECT * from prodotti"
}
}
output {
    if "prodotti" in [tags]{
        elasticsearch {

             index => "prodotti"

             document_type => "product"
             document_id => "%{id}"
             hosts => "localhost:9200"
        }
    }
}

I am running logstash with following command and it works perfectly:
sudo /usr/share/logstash/bin/logstash -f /etc/logstash/logstash.conf

Now I need to execute logstash with this configuration on startup and I need to automatically listen for change on postgres database.
Thanks in advance for any reply.


(Magnus B├Ąck) #2

I'm not sure what you're having problems with. Running Logstash as a service on Ubuntu is documented here: https://www.elastic.co/guide/en/logstash/current/running-logstash.html


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.