How can we setup a non root install of CABI to allow for systemd service profiles to work correctly.
CABI 7.9.2.4
non root install requires additional items to work correctly
We setup using the following
Non-root user – spectrum
CABI installation location – /opt/CABI
Directory for systemd services - /home/spectrum/.config/systemd/user
The things that are involved with the non-root setup are as follows:
1. Session persistence for the non-root user.
su –
loginctl enable-linger spectrum
2. Setup of the non-root systemd services directory.
su - spectrum
mkdir -p /home/.config/systemd/user
3. Setup of the services, in particular for the non-root user.
Three services are created – tomcat, postgres and cabi
Details of the three files are below…
su – spectrum
cd /home/.config/systemd/user
# Put the three services files in this directory
4. Enabling the systemd services.
su – spectrum
systemctl --user enable postgresql
systemctl --user enable tomcat
systemctl --user enable cabi
systemctl --user daemon-reload
Once you enable the services, that will setup the soft-links for systemd. If you don’t enable them, then the links don’t get setup and so you can’t set things up to autostart upon bootup.
5. Testing the systemd services
su – spectrum
systemctl --user start postgresql
systemctl --user start tomcat
systemctl --user start cabi
systemctl --user status postgresql
systemctl --user status tomcat
systemctl --user status cabi
That should now fix up the setup!
There are a couple of things to add:
Since there are three service files, if you do a ./stopServers.sh from /opt/CABI then it will NOT shutdown everything, in particular postgresql. To shutdown PostGres, you will need to stop it using the systemctl command.
You could disable all of the services except for the cabi service since it has a master script that stops/starts everything. However, I was wanting a little bit of more fine grained control over things.
The service files (below) might not be completely optimized but they are a good start. Make sure that you do NOT specify a user/group in them since this is unnecessary as you are running things as the non-root user anyways.
Model service files are as follows:
# Systemd unit file for postresql (postgresql.service)
[Unit]
SourcePath=/opt/CABI/postgresql
Description=PostgreSQL database server
Before=runlevel3.target
Before=runlevel5.target
Before=shutdown.target
After=network-online.target
Wants=network-online.target
Conflicts=shutdown.target
[Service]
Type=forking
# Maximum number of seconds pg_ctl will wait for postgres to start. Note that
# PGSTARTTIMEOUT should be less than TimeoutSec value.
Environment=PGSTARTTIMEOUT=270
Environment=PGDATA=/opt/CABI/postgresql/data
ExecStart=/opt/CABI/postgresql/bin/pg_ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT}
ExecStop=/opt/CABI/postgresql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/opt/CABI/postgresql/bin/pg_ctl reload -D ${PGDATA} -s
# Give a reasonable amount of time for the server to start up/shut down.
# Ideally, the timeout for starting PostgreSQL server should be handled more
# nicely by pg_ctl in ExecStart, so keep its timeout smaller than this value.
TimeoutSec=300
LimitCORE=infinity
Restart=no
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
[Install]
WantedBy=default.target
# Systemd unit file for tomcat (tomcat.service)
[Unit]
SourcePath=/opt/CABI/apache-tomcat
Description=Apache Tomcat Web Application Container
Before=runlevel3.target
Before=runlevel5.target
Before=shutdown.target
After=syslog.target network-online.target
Wants=network-online.target
Conflicts=shutdown.target
[Service]
Type=forking
Environment=JAVA_HOME=/opt/CABI/java
Environment=CATALINA_PID=/opt/CABI/apache-tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/CABI/apache-tomcat
Environment=CATALINA_BASE=/opt/CABI/apache-tomcat
Environment='CATALINA_OPTS=-Xms4096m -Xmx6144m -server -Xss2m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=/opt/CABI/apache-tomcat/bin/startup.sh
ExecStop=/opt/CABI/apache-tomcat/bin/shutdown.sh
UMask=0007
RestartSec=10
Restart=always
LimitCORE=infinity
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
[Install]
WantedBy=default.target
# Systemd unit file for CABI (cabi.service)
[Unit]
SourcePath=/opt/CABI
Description=CA Business Intelligence
Before=runlevel3.target
Before=runlevel5.target
Before=shutdown.target
After=syslog.target network-online.target
Wants=network-online.target
Conflicts=shutdown.target
[Service]
Type=forking
ExecStart=/opt/CABI/startServers.sh
ExecStop=/opt/CABI/stopServers.sh
UMask=0007
RestartSec=10
Restart=always
LimitCORE=infinity
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
[Install]
WantedBy=default.target