2

I have been following numerous tutorials on how to write a startup script for systemd (Fedora 25 on Vbox). However, I'm not able to make it work.

Here is the bash script /home/dario/Desktop/unix/SYSTEMD/print_date.sh that I want to run:

#!/bin/bash
date > startup_date

I changed permissions on the file, chmod 755 print_date.sh

I created the service file /etc/systemd/system/print_date.service (this is just the last versions, I tried out many other iterations):

[Unit]
Description=Example startup script
After=multi-user.target

[Service]
Type=forking
ExecStart=/home/dario/Desktop/unix/SYSTEMD/print_date.sh
User=root
Group=root

[Install]
WantedBy=multi-user.target

I run

systemctl daemon-reload
systemctl enable print_date

and to test it out witout rebooting

systemctl start print_date

which gives me the error

[root@dario SYSTEMD]# systemctl start print_date
Job for print_date.service failed because the control process exited with error code.
See "systemctl status print_date.service" and "journalctl -xe" for details.

If I try to debug it with journal -xn the result is:

[root@dario SYSTEMD]# journalctl -xn
-- Logs begin at Wed 2016-12-28 13:03:41 PST, end at Sat 2017-03-18 12:25:39 PDT. --
Mar 18 12:25:35 dario systemd[4143]: print_date.service: Failed at step EXEC spawning /home/dario/Desktop/unix/SYSTEMD/print_date.sh: Permissi
-- Subject: Process /home/dario/Desktop/unix/SYSTEMD/print_date.sh could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- The process /home/dario/Desktop/unix/SYSTEMD/print_date.sh could not be executed and failed.
-- 
-- The error number returned by this process is 13.
Mar 18 12:25:35 dario systemd[1]: print_date.service: Control process exited, code=exited status=203
Mar 18 12:25:35 dario systemd[1]: Failed to start Example startup script.
-- Subject: Unit print_date.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit print_date.service has failed.
-- 
-- The result is failed.
Mar 18 12:25:35 dario systemd[1]: print_date.service: Unit entered failed state.
Mar 18 12:25:35 dario audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=print_date
Mar 18 12:25:35 dario systemd[1]: print_date.service: Failed with result 'exit-code'.
Mar 18 12:25:38 dario dbus-daemon[682]: [system] Activating service name='org.fedoraproject.Setroubleshootd' requested by ':1.36' (uid=0 pid=6
Mar 18 12:25:38 dario dbus-daemon[682]: [system] Successfully activated service 'org.fedoraproject.Setroubleshootd'
  • There might be multiple problems, but try Type=oneshot instead of forking. – VPfB Mar 18 '17 at 19:48
1

I have found a suitable answer for me. However, please elaborate if you have a solution that is not as drastic as mine.

In my case, the problem relies in SELinux default mode, which is set as enforcing. By setting SELinux to permissive I can allow my script to be run at startup (and whenever I test it out with systemctl start ..).

I don't really understand the details of SELinux and it feels like I'm messing with something bigger then me. I invite other people to expand on this solution in a more professional way.

In /etc/selinux/config

set the line

SELINUX = enforcing

to

SELINUX = permissive

It would allow the execution of the startup file. Regards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.