Update: With the 19.216-33 version of the Collector, released May 1, 2018, a systemd entry should be added automatically at install time.
When a Collector installs, it tries to auto-detect which startup system to use. The wrapper script will try to detect systemd by looking for the following:
- Ensure directory "/etc/systemd" exists (ls /etc/systemd)
- Ensure either of these files exists: "/bin/pidof" OR "/usr/sbin/pidof"
- Use that file to check for systemd running, e.g. "/bin/pidof systemd" OR "/usr/sbin/pidof systemd"
If the above checks true, then the Collector will create the systemd startup scripts, otherwise, it will fall back to the init.d startup scripts.
If the Collector defaults to the init.d startup scripts, it is possible that systemd is not yet running on the host server. This can happen when using scripts to deploy Linux images with the Collector, such as when bootstrapping Linux instances with the Collector. This can result in a race condition that gets the Collector installed before systemd is ready. To avoid this, you can simply add a "sleep" parameter to your deployment script to delay the Collector installation for a few seconds or, if you are installing more that one application, you can move the Collector installation to the bottom of your application list.
How to manually create a systemd startup script
After the installation of the Collector via RPM, Deb, .tar or .sh scripts you can manually create a systemd start script (sumologic.service) to start the Collector at boot time. Below is a template used to create this service script. You just need to place this within "/usr/lib/systemd/system" directory and then set the script to be executable.
[Unit]
Description=Sumo Logic Collector
[Service]
Type=forking
ExecStart=/opt/SumoCollector/collector start
ExecStop=/opt/SumoCollector/collector stop
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300
[Install]
WantedBy=multi-user.target
Once you have the file in place kill any running Collector process on the host and then run the following command.
sudo systemctl enable collector.service
You can then start/stop/restart the service with the following commands.
sudo systemctl stop collector.service
sudo systemctl start collector.service
Comments
2 comments
The directory /usr/lib/systemd/system is not the place to put custom scripts. Those must go to /etc/systemd/system and a "systemctl daemon-reload" must be issued after.
Besides, systemd init scripts don't need to be executable.
Also, I found that there may be a bug in this recommended Systemd service file. Add "PIDFile=/opt/SumoCollector/collector.pid" to fix it if you have problems starting collector as a Systemd service
See: https://github.com/SumoLogic/sumologic-collector-chef-cookbook/issues/141#issuecomment-455467673
Please sign in to leave a comment.