Systemd

From CLONWiki
Jump to navigation Jump to search

Creating service in systemd (RHEL7 and up)

NOTE: on Centos5 for DiagGuiServer, described below, placing startup into rc.local works better - no extra environment settings from clasrun user is required, probably because of rc.local executed AFTER all systemd services, have to understand. Example of the working /etc/rc.d/rc.local:

touch /var/lock/subsys/local

rm -f /var/log/DiagGuiServer.log
touch /var/log/DiagGuiServer.log
chmod 777 /var/log/DiagGuiServer.log
su clasrun -c "DiagGuiServer init >> /var/log/DiagGuiServer.log &"


NOTES:

systemctl list-units | grep -o '.*\.mount'


DiagGuiServer example (VME)

Create file /usr/lib/systemd/system/DiagGuiServer.service with following contents:

[Unit]
Description=DiagGuiServer
#After=network.target
#Requires=autofs.service
#Requires=nfs-utils.service nfs-lock.service autofs.service
#Requires=autofs.service
#After=network.target apps.mount home.mount usr-clas12.mount usr-local.mount
#After=-.mount
#RequiresMountsFor=/usr/clas12/release/2.0.0/coda/Linux_x86_64_RHEL7_vme/bin
#Wants=remote-fs.target
#After=remote-fs.target
#ConditionPathExists=/usr/clas12/release/2.0.0/coda/Linux_x86_64_RHEL7_vme/bin 
[Service]
Type=simple
User=clasrun
Group=onliners
ExecStart=/usr/clas12/release/2.0.0/coda/Linux_x86_64_RHEL7_vme/bin/DiagGuiServer init
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target


NOTE: various commented out settings in [Unit] section were tried to make sure DiagGuiServer service run after everything else is ready (in particular automounts), but nothing really worked; solution was to allow restart on failure in section [Service], so after a couple of failures service DiagGuiServer finally starts.


Create directory /etc/systemd/system/DiagGuiServer.service.d/

Create file /etc/systemd/system/DiagGuiServer.service.d/override.conf with following contents:

[Service]
Environment="LD_LIBRARY_PATH=/apps/gcc/11.5.0/lib:/apps/gcc/11.5.0/lib64:/usr/lib:/usr/local/lib:/usr/local/activemq/lib:/usr/clas12/release/2.0.0/coda/Linux_x86_64_RHEL7_vme/lib:/usr/clas12/release/2.0.0/clon/Linux_x86_64_RHEL7_vme/lib:/usr/clas12/release/2.0.0/clon/lib"
Environment="IPC_HOST=clon00"
Environment="MYSQL_HOST=clondb1"
Environment="EXPID=clasrun"
Environment="CLON_PARMS=/usr/clas12/release/2.0.0/parms"

Following commands can be used to control service:

systemctl daemon-reload
systemctl start DiagGuiServer
systemctl stop DiagGuiServer
systemctl status DiagGuiServer

In case of problems, useful command:

journalctl -u DiagGuiServer

To start service at boot time, execute command:

systemctl enable DiagGuiServer

following message should come up on screen:

Created symlink from /etc/systemd/system/multi-user.target.wants/DiagGuiServer.service to /usr/lib/systemd/system/DiagGuiServer.service.

DiagGui example (VTP)

Create file /usr/lib/systemd/system/DiagGuiServer.service with following contents:

[Service]
##
## see /etc/systemd/system/DiagGuiServer.service.d/override.conf
##Environment="LD_LIBRARY_PATH=/usr/clas12/release/2.0.0/coda/Linux_armv7l_RHEL7/lib:/usr/local/activemq/lib" "SESSION=clasprod" "EXPID=clasrun" "IPC_HOST=clon00" "CLON_PARMS=/usr/clas12/release/2.0.0/parms" "MYSQL_HOST=clondb1"
##
User=clasrun
Group=onliners
Type=simple
ExecStart=/usr/clas12/release/2.0.0/coda/Linux_armv7l_RHEL7/bin/vtpserver
Restart=no

[Install]
WantedBy=multi-user.target

Create directory /etc/systemd/system/DiagGuiServer.service.d/.

Create file /etc/systemd/system/DiagGuiServer.service.d/override.conf with following contents:

[Service]
Environment="LD_LIBRARY_PATH=/usr/clas12/release/2.0.0/coda/Linux_armv7l_RHEL7/lib:/usr/local/activemq/lib"
Environment="SESSION=clasprod"
Environment="EXPID=clasrun"
Environment="IPC_HOST=clon00"
Environment="CLON_PARMS=/usr/clas12/release/2.0.0/parms"
Environment="MYSQL_HOST=clondb1"

Following commands can be used to control service:

systemctl daemon-reload
systemctl start DiagGuiServer
systemctl stop DiagGuiServer
systemctl status DiagGuiServer

In case of problems, useful command:

journalctl -u DiagGuiServer

To start service at boot time, execute command:

systemctl enable DiagGuiServer

following message should come up on screen:

Created symlink from /etc/systemd/system/multi-user.target.wants/DiagGuiServer.service to /usr/lib/systemd/system/DiagGuiServer.service.