Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest to add upstart and systemd scripts for logstash. #5012

Closed
abcfy2 opened this issue Apr 5, 2016 · 5 comments
Closed

Suggest to add upstart and systemd scripts for logstash. #5012

abcfy2 opened this issue Apr 5, 2016 · 5 comments

Comments

@abcfy2
Copy link

abcfy2 commented Apr 5, 2016

Both upstart and systemd have more advanced features than init.d, and make service scripts easier. For example, for the stop() function in init.d script:

stop() {
  # Try a few times to kill TERM the program
  if status ; then
    pid=`cat "$pidfile"`
    echo "Killing $name (pid $pid) with SIGTERM"
    kill -TERM $pid
    # Wait for it to exit.
    for i in 1 2 3 4 5 6 7 8 9 ; do
      echo "Waiting $name (pid $pid) to die..."
      status || break
      sleep 1
    done
    if status ; then
      if [[ $KILL_ON_STOP_TIMEOUT -eq 1 ]] ; then
        echo "Timeout reached. Killing $name (pid $pid) with SIGKILL. This may result in data loss."
        kill -KILL $pid
        echo "$name killed with SIGKILL."
      else
        echo "$name stop failed; still running."
      fi
    else
      echo "$name stopped."
    fi
  fi
}

A little hard, right? And not do well with perform a stop operate. I often meet that when I want logstash to restart, but start two processes(the old process stop failed, while start a new one).

sudo service logstash restart
Killing logstash (pid 21829) with SIGTERM
Waiting logstash (pid 21829) to die...
Waiting logstash (pid 21829) to die...
Waiting logstash (pid 21829) to die...
Waiting logstash (pid 21829) to die...
Waiting logstash (pid 21829) to die...
Waiting logstash (pid 21829) to die...
Waiting logstash (pid 21829) to die...
Waiting logstash (pid 21829) to die...
Waiting logstash (pid 21829) to die...
logstash stop failed; still running.
logstash started.

But both upstart and systemd could handle this problem easily. For example, upstart has a built-in kill timeout stanza that could force kill a service if still running after timeout. And do not need to write a stop() function manually.

And I find that in fact, logstash has a Ubuntu upstart script: https://github.com/elastic/logstash/blob/master/pkg/logstash.upstart.ubuntu. But why not using for now?

Today, modern Linux distributions introduce systemd as the default service manager(Ubuntu 16.04 or later, Debian 8 or later, RHEL/CentOS 7 or later). So logstash should prepare new systemd script for the distributions which support systemd.

@purbon
Copy link
Contributor

purbon commented Apr 5, 2016

Thanks a lot for you proposal @abcfy2!

@andrewvc
Copy link
Contributor

andrewvc commented Apr 6, 2016

This is sorely needed, I 100% agree.

@jordansissel
Copy link
Contributor

I use jordansissel/pleaserun for generating most of this lately. I would be happy if we did the same.

However, for rpm/deb packaging, it becomes extremely annoying to ship multiple service definitions (sysv init, upstart, systemd, et al) with a single rpm or deb.

You can roughly achieve a systemd or upstart for logstash today with pleaserun, something like:

% pleaserun -p systemd --install /opt/logstash/bin/logstash -f /etc/logstash/logstash.conf
% systemctl enable logstash
% systemctl start logstash

Swap upstart in place of systemd in the above example for similar effect on upstart systems (centos 6, ubuntu 08.10+, etc)

@suyograo
Copy link
Contributor

Fixed in #5341

@demuxer
Copy link

demuxer commented Jan 15, 2018

@jordansissel has the answer, after looking for the right thread and forums, the simple and effective solution is

% systemctl enable logstash
% systemctl start logstash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants