[systemd-devel] How to handle errors in systemd

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Wed Apr 2 07:17:20 PDT 2014


On Wed, Apr 02, 2014 at 07:12:57PM +0530, shubham sharma wrote:
> Hi,
> 
> I have recently switched to RHEL7. I had earlier written a sample service
> script "test_service.sh" in the /etc/init.d folder and i used the usual
> method
> $>/etc/init.d/test_service.sh start
> to start the script and
> $>/etc/init.d/test_service.sh stop
> to stop the script.
> 
> the service script test_service.sh returns 0 on success and 1 in case it is
> unable to stop the service due to some reason.
> 
> Now i wanted to use the systemd to start the service on RHEL7. For this, I
> created the file test_service.service with the following details:
> 
> [Unit]
> Description=test_service startup script
> DefaultDependencies=no
> Conflicts=shutdown.target
> 
> [Service]
> Type=oneshot
> ExecStart=/etc/init.d/test_service.sh start
> TimeoutStartSec=0
> ExecStop=/etc/init.d/test_service.sh stop
> RemainAfterExit=yes
> StandardOutput=syslog+console
> StandardError=syslog+console
> SyslogLevel=debug
> SuccessExitStatus=1
> 
> The script test_service.service is running fine when the script
> /etc/init.d/test_service returns 0. However in case the script
> /etc/init.d/test_service returns 1, i am getting the following errors :
> 
> Apr 01 03:06:53 libl038 systemd[1]: test_service.service: control process
> exited, code=exited status=1
> Apr 01 03:06:56 libl038 systemd[1]: Stopped test_service startup script.
> Apr 01 03:06:56 libl038 systemd[1]: Unit test_service.service entered
> failed state.
> 
> and the high-level and low-level unit activation states from the systemctl
> are failed.
> 
> Is there a way in which the return value from test_service.sh service
> script can be handled by the systemd and it display a message that it is
> unable to stop the test_service.service service?
No. When systemd stops a service, it stops it. If necessary, by
killing all processes with signal 9.

But systemd has support for /etc/init.d/ scripts built-in. If your
script has appropriate headers, no unit file is necessary, and you can
just say 'systmectl start/stop test_service', and have systemd invoke
/etc/init.d/test_service start/stop.

Zbyszek


More information about the systemd-devel mailing list