LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-10-2017, 05:42 PM   #1
desbyleo
Member
 
Registered: Feb 2002
Location: Erie, CO
Distribution: Red Hat 7.1
Posts: 94

Rep: Reputation: 15
systemd service stop/start


I'm running OL 7.4.
I'm not an expert of systemd, but I'm trying to get the server to auto start/stop my oracle database.

I've successfully added a systemd service for it. I'm able to start and stop it with systemctl.

On server startup, the service is also started automatically.

My issue is on server shutdown, systemd doesn't seem to stop the service OR... something is else occurs before that crashes the databases (before systemd can gracefully shut it down). I'm used to the old init.d scripts and I simply had to make sure the stop script was first in the order (ie "K01"). I'm new to systemd.

What I have systemd doing is running a shell script to start all the oracle processes I need. And so, once the service "starts", system shows it as "active (exited)."

Code:
[root@duritllora01d ~]# systemctl status dbora
● dbora.service - Oracle Database Services
   Loaded: loaded (/usr/lib/systemd/system/dbora.service; enabled; vendor preset: disabled)
   Active: active (exited) since Tue 2017-10-10 18:16:40 EDT; 17min ago
  Process: 4620 ExecStop=/u11/app/oracle/common/bin/orastop (code=exited, status=0/SUCCESS)
  Process: 4887 ExecStart=/u11/app/oracle/common/bin/orastart (code=exited, status=0/SUCCESS)
 Main PID: 4887 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/dbora.service
I know enough that when it's a "regular" process, it will show as "running." But since the process is simply the shell script that started the other real processes, once that shell script exits, then its "exited." Is this the reason it is not automatically stopping it during shutdown? It doesn't recognize this as a running service?

The systemd service config file is like this:
Code:
[Unit]
Description=Oracle Database Services
Requires=rpc-statd.service network.target nfs.service nfs-mountd.service local-fs.target remote-fs.target
After=syslog.target network.target nfs.service nfs-mountd.service local-fs.target rpc-statd.service remote-fs.target

[Service]
# systemd ignores PAM limits, so set any necessary limits in the service.
# Not really a bug, but a feature.
# https://bugzilla.redhat.com/show_bug.cgi?id=754285
LimitMEMLOCK=infinity
LimitNOFILE=65535

#Type=simple
# idle: similar to simple, the actual execution of the service binary is delayed
#       until all jobs are finished, which avoids mixing the status output with shell output of services.
Type=idle
RemainAfterExit=yes
User=root
ExecStart=/u11/app/oracle/common/bin/orastart
ExecStop=/u11/app/oracle/common/bin/orastop

[Install]
WantedBy=multi-user.target
 
Old 10-18-2017, 11:24 AM   #2
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 513

Rep: Reputation: 95
Hi,

Try to use the below in the [Service] section.

Type=oneshot
RemainAfterExit=yes
 
Old 10-18-2017, 11:57 AM   #3
desbyleo
Member
 
Registered: Feb 2002
Location: Erie, CO
Distribution: Red Hat 7.1
Posts: 94

Original Poster
Rep: Reputation: 15
After investigation, I found what was happening was simply that systemd was killing the database processes before it gets to executing the ExecStop script. Hence why my database logs always shows events that the database crashed during server shutdown.

I think "Type=idle" is definitely not the right type to use. With idle or simple, systemd doesn't seem to "track" the processes that are SPUN OFF by the ExecStart script. Hence the status shows "active(exited)".

I'll test and see if oneshot makes any different, but looking at the manual, I don't see why it would:
Behavior of oneshot is similar to simple; however, it is expected that the process has to exit before systemd starts follow-up units. RemainAfterExit= is particularly useful for this type of service. This is the implied default if neither Type= nor ExecStart= are specified.

Anyway, I got things working using "Type=forking," which now makes sense since the ExecStart is a script that calls command that spins up the database processes:
If set to forking, it is expected that the process configured with ExecStart= will call fork() as part of its start-up. The parent process is expected to exit when start-up is complete and all communication channels are set up. The child continues to run as the main daemon process. This is the behavior of traditional UNIX daemons. If this setting is used, it is recommended to also use the PIDFile= option, so that systemd can identify the main process of the daemon. systemd will proceed with starting follow-up units as soon as the parent process exits.

I did have to make some minor changes to my ExecStart/Stop script. Originally, the ExecStart/Stop scripts were called by root. Then Root su's to the different Oracle owners to shutdown it's database. So originally, I had one systemd service (to start and stop ALL database services on the server). I couldn't get that to work with "type=idle." So now I updated the ExecStart/Stop script and created a systemd service FOR EACH database and specified the database owner is the user= for the service (and type=forking).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
systemd - how to properly stop dhcpcd.service? czezz Linux - Networking 12 05-16-2017 04:40 PM
I need a service to stop or start rc.inet wla2_start(stop) igadoter Slackware 1 04-21-2017 03:12 PM
Systemd service: AUTOSSH.service does not start at boot, how can I fix this? The_Linux_Machine Linux - Newbie 1 07-06-2016 12:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration