Long story short, systemd is a Service Control Manager present in CentOS 7, Red Hat 7, SUSE v12 and lately in Debian and Ubuntu Linux distributions. Previously, Linux distros used System V based rc files or xinetd for service management but it seems to be greatly limited, so all the big Linux distributions are moving towards systemd.
In systemd, you don’t use shell script commands to start and stop your service, rather you need to build a “service” file with specific syntax that gives directives to systemd to manage your service.
A few directories to be aware of:
/usr/lib/systemd/system/ | Directory for your service file. |
/etc/sysconfig/ | Directory for your service’s Environment file. |
Create service file for Informix
You will need to created the following file, usually called informix.service in the /usr/lib/systemd/system/ directory.
[Unit]
Description=Informix IDS Database Server
Documentation=file:/opt/IBM/informix/release/en_us/0333 http://www.ibm.com/software/data/informix/library.html
Wants=network-online.target
After=network.target network-online.target
[Service]
Type=oneshot
User=informix
Group=informix
RemainAfterExit=yes
EnvironmentFile=/etc/sysconfig/informix_service
ExecStart=/opt/IBM/informix/bin/oninit
ExecStop=/opt/IBM/informix/bin/onmode -ky
#Restart=on-abort
[Install]
WantedBy=multi-user.target
The [Unit] section is an identifier.
The [Service] section is where your systemd directives go.
The [Install] section controls when your program is run…in this case, “multi-user.target” refers to runlevel 3, just like the old rc3.d did.
EnvironmentFile is the file where any Environmental Variables required by Informix to run (ie, INFORMIXDIR) are defined.
ExecStart is the command that starts your service. For Informix that’s the program oninit.
ExecStop is the command that stops your service. For Informix that’s onmode.
RemainAfterExit allows systemd to consider service started properly even oninit program exists. You need this parameter to be ser because Informix uses some tricks in their starting process, so Type=forking can’t be used.
The filenames and program names MUST be absolute pathnames. Even though I defined Environment Variables in my EnvironmentFile, I couldn’t get them to work in the pathnames for the ExecStart or ExecStop programs.
Create configuration file for Informix service
Since oninit won’t run unless it can find some things in the Environment, I wrote a small file called informix_service (you can name it anything you want) and placed it in the /etc/sysconfig/ directory. Here is my informix_service EnvironmentFile:
# informix.service environmental variables
INFORMIXDIR=/opt/IBM/informix
INFORMIXSERVER=ol_informix1210
ONCONFIG=onconfig.ol_informix1210
INFORMIXSQLHOSTS=/opt/IBM/informix/etc/sqlhosts.ol_informix1210
Of course, substitute your directory names and file names as needed.
Manage Informix service
Start de informix service:
# systemctl start informix
You can use onstat to see if it started, or run:
# systemctl status informix
To stop the informix service:
# systemctl stop informix
Start the service at boot:
# systemctl enable informix
ln -s '/etc/systemd/system/informix.service' '/etc/systemd/system/multi-user.target.wants/informix.service'
If you want to disable start the service at boot:
# systemctl disable informix
If everything runs okay manually, reboot your system after enabling the service. Hopefully, everything will work for you.
Vicente Salvador
Hi,
here is how you can use the env. variables directly in the [Service] section (thanks go to my colleague for his investigation):
[Service]
…
Environment=”ENV_FILE=/usr/informix/etc/env_file”
ExecStart=/bin/sh -a -c ‘source $ENV_FILE && $INFORMIXDIR/bin/oninit -v’
ExecStop=/bin/sh -a -c ‘source $ENV_FILE && $INFORMIXDIR/bin/onmode -uky’
…
# end of [Service]
where the /usr/informix/etc/env_file obviously has the same content as your informix_service file
Very useful to a problem I was facing, thanks a lot
Very seful but one question, how to start informix for the same port of sqlhost??
because start for other port..
regards
Jose