Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-10-2017, 06:42 PM   #1
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)."

[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:
Description=Oracle Database Services
Requires=rpc-statd.service nfs.service nfs-mountd.service nfs.service nfs-mountd.service rpc-statd.service

# systemd ignores PAM limits, so set any necessary limits in the service.
# Not really a bug, but a feature.

# 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.

Old 10-18-2017, 12:24 PM   #2
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 525

Rep: Reputation: 95

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

Old 10-18-2017, 12:57 PM   #3
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).


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 05:40 PM
I need a service to stop or start rc.inet wla2_start(stop) igadoter Slackware 1 04-21-2017 04: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 01:00 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:17 AM.

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