Skip to content

Instantly share code, notes, and snippets.

@s0undt3ch
Created September 18, 2015 14:01
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save s0undt3ch/969b744d3d7b88c29cba to your computer and use it in GitHub Desktop.
Save s0undt3ch/969b744d3d7b88c29cba to your computer and use it in GitHub Desktop.
CentOS 7 Cassandra systemd service file
# /usr/lib/systemd/system/cassandra.service
[Unit]
Description=Cassandra
After=network.target
[Service]
PIDFile=/var/run/cassandra/cassandra.pid
User=cassandra
Group=cassandra
ExecStart=/usr/sbin/cassandra -f -p /var/run/cassandra/cassandra.pid
StandardOutput=journal
StandardError=journal
LimitNOFILE=100000
LimitMEMLOCK=infinity
LimitNPROC=32768
LimitAS=infinity
Restart=always
[Install]
WantedBy=multi-user.target
@vicdurai
Copy link

vicdurai commented Dec 5, 2016

Running with -f command wont create the pid file.

@kikicarbonell
Copy link

Do you have an updated cassandra.service for version 3.10?

@ngopher
Copy link

ngopher commented Jun 9, 2017

Hi. Can I use this method in ubuntu server(AWS instance) too?

@daverogers
Copy link

Thank you! Big help in my chef recipe.

@YakobovLior
Copy link

how come there is no ExecStop command?

@mrcomoraes
Copy link

how come there is no ExecStop command?

You can put this in file:
ExecStop=/bin/kill -s 15 $MAINPID

@mrcomoraes
Copy link

Thank you!! This was helpful.

@aseev-xx
Copy link

worth adding:
EnvironmentFile=-/etc/default/cassandra

@yigit9194
Copy link

Thank you, it's very helpfull ! :)

@gproietti
Copy link

gproietti commented Dec 4, 2019

Thank you, very helpfull,
I was facing with a strange problem with Cassandra, nomore managed correctly as service on Centos7 because such file was missing after a yum update.
Putting that file under /usr/lib/systemd/system/ and doing a "systemctl daemon-reexec" solved my problem :-)

@andrewjlowery
Copy link

Not sure why a PID file is being set if the unit is left to default to simple?

@maizy
Copy link

maizy commented Feb 25, 2020

After some tries I've created upgraded version of this unit file.

Changes:

  • use background run + Type=forking because -p works only without -f
  • use CASSANDRA_* env variables to load cassandra configs from /etc/cassandra/conf, those are created by cassandra RPM package
  • upd 28.08.2020: add stop timeout
  • upd 28.08.2020: set successful exit code

Tested with cassandra 3.11.5 & centos 7.7

# /usr/lib/systemd/system/cassandra.service

[Unit]
Description=Cassandra
After=network.target

[Service]
RuntimeDirectory=cassandra
PIDFile=/var/run/cassandra/cassandra.pid
Environment=CASSANDRA_HOME=/usr/share/cassandra
Environment=CASSANDRA_CONF=/etc/cassandra/conf
Environment=CASSANDRA_INCLUDE=/usr/share/cassandra/cassandra.in.sh
Environment=CASSANDRA_OWNR=cassandra
User=cassandra
Group=cassandra
Type=forking
ExecStart=/usr/sbin/cassandra -p /var/run/cassandra/cassandra.pid
StandardOutput=journal
StandardError=journal
LimitNOFILE=100000
LimitMEMLOCK=infinity
LimitNPROC=32768
LimitAS=infinity
Restart=always
TimeoutStopSec=180
SuccessExitStatus=143


[Install]
WantedBy=multi-user.target

@Phrozyn
Copy link

Phrozyn commented Apr 3, 2020

Tested on CentOS 8, works!

@nickzakharov
Copy link

On my sysV file I call the following command when stopping cassandra:
nodetool -u cass** -pw pass** -h 127.0.0.1 decommission

Do I need to do this in systemd file as a ExecStopPost command?

@ilyaevseev
Copy link

ilyaevseev commented Oct 11, 2022

Should be useful in forking mode:

TimeoutStartSec=300

But foreground mode seems more stable (imho).

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