I'm trying to create startup / shutdown script for my application, but I do not have experience with that, so I wanted to start with screen (I'll refer to it as "test_screen").
Firstly I thought I'll create script in /etc/init.d only. And I got inspiration from here - https://unix.stackexchange.com/a/20361/29677 .
Basic idea to simuate my appplication is to use
screen -d -m -S test_screen
to startupscreen -S test_screen -X quit
for shutdown- and
screen –list
for status (kind of)
But when I tried /etc/init.d/test_screen start
I got
Reloading systemd: [ OK ]
Starting test_screen (via systemctl): Failed to start test_screen.service: Unit not found.
[FAILED]
So it seems I have to create unit.
I tried with https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Unit_Files.html , so I have my unit file in /etc/systemd/system
:
# cat test_screen.service
[Unit]
Description=Testing `screen` service
[Service]
Type=simple
ExecStart=/bin/screen -d -m -S test_screen
ExecStop=/bin/screen -S test_screen -X quit
Environment=
Restart=always
[Install]
WantedBy=default.target
First question is, should I have /etc/init.d/test_screen start
as ExecStart
or not? Definitely it won't be one liner...
Anyway, it is not running. In /var/log/messages
I see
Sep 19 10:54:58 somehostname systemd: Started Testing `screen` service.
Sep 19 10:54:58 somehostname systemd: Starting Testing `screen` service...
Sep 19 10:54:58 somehostname systemd: test_screen.service holdoff time over, scheduling restart.
Sep 19 10:54:58 somehostname systemd: Started Testing `screen` service.
Sep 19 10:54:58 somehostname systemd: Starting Testing `screen` service...
Sep 19 10:54:58 somehostname systemd: test_screen.service holdoff time over, scheduling restart.
Sep 19 10:54:58 somehostname systemd: Started Testing `screen` service.
Sep 19 10:54:58 somehostname systemd: Starting Testing `screen` service...
Sep 19 10:54:59 somehostname systemd: test_screen.service holdoff time over, scheduling restart.
Sep 19 10:54:59 somehostname systemd: Started Testing `screen` service.
Sep 19 10:54:59 somehostname systemd: Starting Testing `screen` service...
Sep 19 10:54:59 somehostname systemd: test_screen.service holdoff time over, scheduling restart.
Sep 19 10:54:59 somehostname systemd: Started Testing `screen` service.
Sep 19 10:54:59 somehostname systemd: Starting Testing `screen` service...
Sep 19 10:54:59 somehostname systemd: test_screen.service holdoff time over, scheduling restart.
Sep 19 10:54:59 somehostname systemd: start request repeated too quickly for test_screen.service
Sep 19 10:54:59 somehostname systemd: Failed to start Testing `screen` service.
Sep 19 10:54:59 somehostname systemd: Unit test_screen.service entered failed state.
Sep 19 10:54:59 somehostname systemd: test_screen.service failed.
How can I find the reason, why it is entering failed state? All suggestions are welcome.
Type=simple
andType=forking
depending on how your actual application is run will change how you should write the service file. For screen you will wantType=forking
but this wont always be true.