Startup / shutdown script for RedHat Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionHow can I make a script in /etc/init.d start at boot?systemd custom status message?Migrate socat init script to systemdInit script to run a script as specific userRun daemon on startup in Debian once openvpn connection establishedAuto login into router running BusyboxSysV init scripts to systemd migration in RHEL7failure at starting on postgresqlSystemd service starts only one of two processes, but only on OS rebootsystemd: finish the execution of custom shell script before starting nginxsystemd: nginx does not resolve /etc/hosts entries at boot timeRestarting a service on Red Hat and where are the services listed
How do I keep my slimes from escaping their pens?
What's the meaning of 間時肆拾貳 at a car parking sign
Is the Standard Deduction better than Itemized when both are the same amount?
Why was the term "discrete" used in discrete logarithm?
51k Euros annually for a family of 4 in Berlin: Is it enough?
Why aren't air breathing engines used as small first stages
What does the "x" in "x86" represent?
How do I stop a creek from eroding my steep embankment?
How to deal with a team lead who never gives me credit?
Generate an RGB colour grid
Check which numbers satisfy the condition [A*B*C = A! + B! + C!]
Why did the Falcon Heavy center core fall off the ASDS OCISLY barge?
How to call a function with default parameter through a pointer to function that is the return of another function?
Why am I getting the error "non-boolean type specified in a context where a condition is expected" for this request?
Why are there no cargo aircraft with "flying wing" design?
What's the purpose of writing one's academic biography in the third person?
Dating a Former Employee
What causes the vertical darker bands in my photo?
How to find all the available tools in mac terminal?
Error "illegal generic type for instanceof" when using local classes
What does an IRS interview request entail when called in to verify expenses for a sole proprietor small business?
List of Python versions
Identifying polygons that intersect with another layer using QGIS?
Why is "Consequences inflicted." not a sentence?
Startup / shutdown script for RedHat
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionHow can I make a script in /etc/init.d start at boot?systemd custom status message?Migrate socat init script to systemdInit script to run a script as specific userRun daemon on startup in Debian once openvpn connection establishedAuto login into router running BusyboxSysV init scripts to systemd migration in RHEL7failure at starting on postgresqlSystemd service starts only one of two processes, but only on OS rebootsystemd: finish the execution of custom shell script before starting nginxsystemd: nginx does not resolve /etc/hosts entries at boot timeRestarting a service on Red Hat and where are the services listed
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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.
rhel init-script
bumped to the homepage by Community♦ 10 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
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.
rhel init-script
bumped to the homepage by Community♦ 10 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
Why do you need to use screen? Systemd is already capable of backgrounding processes for you so there is no need for terminal multiplexers like screen.
– Michael Daffin
Sep 19 '17 at 9:57
@MichaelDaffin I picked screen just to be able to test with something simple, because I have no experience with startup scripts so far...
– Betlista
Sep 19 '17 at 10:27
Can you give an example of the application you are trying to run? Does it background itself? Sounds like you are using screen as a hack to get around your process not backgrounding itself for old style init scripts but this is not required in systemd. More details on what you are trying to achieve overall would give you better answers.
– Michael Daffin
Sep 19 '17 at 11:06
As a target solution I'm not going to use screen at all, it will be IBM WAS, but for MCVE I cannot ask you to install WAS...
– Betlista
Sep 19 '17 at 11:09
1
The reason I ask is there is a difference betweenType=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.
– Michael Daffin
Sep 19 '17 at 11:39
add a comment |
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.
rhel init-script
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.
rhel init-script
rhel init-script
asked Sep 19 '17 at 8:53
BetlistaBetlista
1065
1065
bumped to the homepage by Community♦ 10 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 10 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
Why do you need to use screen? Systemd is already capable of backgrounding processes for you so there is no need for terminal multiplexers like screen.
– Michael Daffin
Sep 19 '17 at 9:57
@MichaelDaffin I picked screen just to be able to test with something simple, because I have no experience with startup scripts so far...
– Betlista
Sep 19 '17 at 10:27
Can you give an example of the application you are trying to run? Does it background itself? Sounds like you are using screen as a hack to get around your process not backgrounding itself for old style init scripts but this is not required in systemd. More details on what you are trying to achieve overall would give you better answers.
– Michael Daffin
Sep 19 '17 at 11:06
As a target solution I'm not going to use screen at all, it will be IBM WAS, but for MCVE I cannot ask you to install WAS...
– Betlista
Sep 19 '17 at 11:09
1
The reason I ask is there is a difference betweenType=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.
– Michael Daffin
Sep 19 '17 at 11:39
add a comment |
1
Why do you need to use screen? Systemd is already capable of backgrounding processes for you so there is no need for terminal multiplexers like screen.
– Michael Daffin
Sep 19 '17 at 9:57
@MichaelDaffin I picked screen just to be able to test with something simple, because I have no experience with startup scripts so far...
– Betlista
Sep 19 '17 at 10:27
Can you give an example of the application you are trying to run? Does it background itself? Sounds like you are using screen as a hack to get around your process not backgrounding itself for old style init scripts but this is not required in systemd. More details on what you are trying to achieve overall would give you better answers.
– Michael Daffin
Sep 19 '17 at 11:06
As a target solution I'm not going to use screen at all, it will be IBM WAS, but for MCVE I cannot ask you to install WAS...
– Betlista
Sep 19 '17 at 11:09
1
The reason I ask is there is a difference betweenType=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.
– Michael Daffin
Sep 19 '17 at 11:39
1
1
Why do you need to use screen? Systemd is already capable of backgrounding processes for you so there is no need for terminal multiplexers like screen.
– Michael Daffin
Sep 19 '17 at 9:57
Why do you need to use screen? Systemd is already capable of backgrounding processes for you so there is no need for terminal multiplexers like screen.
– Michael Daffin
Sep 19 '17 at 9:57
@MichaelDaffin I picked screen just to be able to test with something simple, because I have no experience with startup scripts so far...
– Betlista
Sep 19 '17 at 10:27
@MichaelDaffin I picked screen just to be able to test with something simple, because I have no experience with startup scripts so far...
– Betlista
Sep 19 '17 at 10:27
Can you give an example of the application you are trying to run? Does it background itself? Sounds like you are using screen as a hack to get around your process not backgrounding itself for old style init scripts but this is not required in systemd. More details on what you are trying to achieve overall would give you better answers.
– Michael Daffin
Sep 19 '17 at 11:06
Can you give an example of the application you are trying to run? Does it background itself? Sounds like you are using screen as a hack to get around your process not backgrounding itself for old style init scripts but this is not required in systemd. More details on what you are trying to achieve overall would give you better answers.
– Michael Daffin
Sep 19 '17 at 11:06
As a target solution I'm not going to use screen at all, it will be IBM WAS, but for MCVE I cannot ask you to install WAS...
– Betlista
Sep 19 '17 at 11:09
As a target solution I'm not going to use screen at all, it will be IBM WAS, but for MCVE I cannot ask you to install WAS...
– Betlista
Sep 19 '17 at 11:09
1
1
The reason I ask is there is a difference between
Type=simple
and Type=forking
depending on how your actual application is run will change how you should write the service file. For screen you will want Type=forking
but this wont always be true.– Michael Daffin
Sep 19 '17 at 11:39
The reason I ask is there is a difference between
Type=simple
and Type=forking
depending on how your actual application is run will change how you should write the service file. For screen you will want Type=forking
but this wont always be true.– Michael Daffin
Sep 19 '17 at 11:39
add a comment |
1 Answer
1
active
oldest
votes
It seems, that I solved it for screen
...
Firstly I removed that Restart=always
parameter.
To make it work I also had to add RemainAfterExit=True
.
With old init scripts it was clear where to have the code. I do not really know what is a proper place to put the rest of code. Should I simply call my script from ExecStart=
?
My additional findings during learning.
status
There is a good question (I meant I was interested too), how to implement status checking - systemd custom status message?
Short answer is, it works (somehow) out f the box = you do not need to care much.
So, for my test_screen service I can call systemctl status test_screen.service
and I'll get
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2017-09-20 12:48:34 CEST; 1s ago
Process: 36633 ExecStart=/bin/screen -d -m -S test_screen (code=exited, status=0/SUCCESS)
Main PID: 36634 (screen)
CGroup: /system.slice/test_screen.service
├─36634 /bin/SCREEN -d -m -S test_screen
└─36635 /bin/sh
Sep 20 12:48:34 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:48:34 somehostname systemd[1]: Started Testing `screen` service.
...strange is, that when I stop it, for status I got failed:
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 12:51:00 CEST; 1s ago
Process: 36805 ExecStop=/bin/screen -S test_screen -X quit (code=exited, status=0/SUCCESS)
Process: 36633 ExecStart=/bin/screen -d -m -S test_screen (code=exited, status=0/SUCCESS)
Main PID: 36634 (code=exited, status=1/FAILURE)
Sep 20 12:48:34 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:48:34 somehostname systemd[1]: Started Testing `screen` service.
Sep 20 12:51:00 somehostname systemd[1]: Stopping Testing `screen` service...
Sep 20 12:51:00 somehostname systemd[1]: test_screen.service: main process exited, code=exited, status=1/FAILURE
Sep 20 12:51:00 somehostname systemd[1]: Stopped Testing `screen` service.
Sep 20 12:51:00 somehostname systemd[1]: Unit test_screen.service entered failed state.
Sep 20 12:51:00 somehostname systemd[1]: test_screen.service failed.
to overcome that I had to have RemainAfterExit=True
(because I tried the suggestion to have Type=forking
and I commented out that RemainAfterExit
option).
list-unit-files
I had an issue, that I'm not able to reproduce now - when I tried systemctl start
the response was something like "No unit file", so I was wondering if there is a need to register it somehow.
No, you do not need to. You can execute systemctl list-unit-files --type=service
and you should see your unit there. My problem was, that ExecStart
parameter was wrong. When I tried the same now I have easier to understand message:
$ systemctl start test_screen.service
Job for test_screen.service failed because the control process exited with error code. See "systemctl status test_screen.service" and "journalctl -xe" for details.
$ systemctl status test_screen.service
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 12:55:53 CEST; 1min 3s ago
Process: 37344 ExecStart=/bin/screen2 -d -m -S test_screen (code=exited, status=203/EXEC)
Main PID: 36634 (code=exited, status=1/FAILURE)
Sep 20 12:55:53 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:55:53 somehostname systemd[37344]: Failed at step EXEC spawning /bin/screen2: No such file or directory
Sep 20 12:55:53 somehostname systemd[1]: test_screen.service: control process exited, code=exited status=203
Sep 20 12:55:53 somehostname systemd[1]: Failed to start Testing `screen` service.
Sep 20 12:55:53 somehostname systemd[1]: Unit test_screen.service entered failed state.
Sep 20 12:55:53 somehostname systemd[1]: test_screen.service failed.
Executing script
I tried to modify my test_screen to call script
$ cat /etc/systemd/system/test_screen_script.service
[Unit]
Description=Testing `screen` service
[Service]
Type=forking
ExecStart=/root/test_screen_start.sh
ExecStop=/root/test_screen_stop.sh
#Environment=
#Restart=always
RemainAfterExit=True
[Install]
WantedBy=default.target
while scripts are just wrapped for previous calls
$ cat /root/test_screen_start.sh
/bin/screen -d -m -S test_screen
$ cat /root/test_screen_stop.sh
/bin/screen -S test_screen -X quit
when I did that, it is not starting up:
$ systemctl start test_screen_script
Job for test_screen_script.service failed because the control process exited with error code. See "systemctl status test_screen_script.service" and "journalctl -xe" for details.
$ systemctl status test_screen_script.service
● test_screen_script.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen_script.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 15:47:59 CEST; 8s ago
Process: 63582 ExecStart=/root/test_screen_start.sh (code=exited, status=203/EXEC)
Main PID: 60698 (code=exited, status=0/SUCCESS)
Sep 20 15:47:59 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 15:47:59 somehostname systemd[63582]: Failed at step EXEC spawning /root/test_screen_start.sh: Exec format error
Sep 20 15:47:59 somehostname systemd[1]: test_screen_script.service: control process exited, code=exited status=203
Sep 20 15:47:59 somehostname systemd[1]: Failed to start Testing `screen` service.
Sep 20 15:47:59 somehostname systemd[1]: Unit test_screen_script.service entered failed state.
Sep 20 15:47:59 somehostname systemd[1]: test_screen_script.service failed.
It would be good is someone can describe the reason. Fix for that is to add #!/bin/bash
.
References
- I found that
list-unit-files
here: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f393138%2fstartup-shutdown-script-for-redhat%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It seems, that I solved it for screen
...
Firstly I removed that Restart=always
parameter.
To make it work I also had to add RemainAfterExit=True
.
With old init scripts it was clear where to have the code. I do not really know what is a proper place to put the rest of code. Should I simply call my script from ExecStart=
?
My additional findings during learning.
status
There is a good question (I meant I was interested too), how to implement status checking - systemd custom status message?
Short answer is, it works (somehow) out f the box = you do not need to care much.
So, for my test_screen service I can call systemctl status test_screen.service
and I'll get
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2017-09-20 12:48:34 CEST; 1s ago
Process: 36633 ExecStart=/bin/screen -d -m -S test_screen (code=exited, status=0/SUCCESS)
Main PID: 36634 (screen)
CGroup: /system.slice/test_screen.service
├─36634 /bin/SCREEN -d -m -S test_screen
└─36635 /bin/sh
Sep 20 12:48:34 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:48:34 somehostname systemd[1]: Started Testing `screen` service.
...strange is, that when I stop it, for status I got failed:
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 12:51:00 CEST; 1s ago
Process: 36805 ExecStop=/bin/screen -S test_screen -X quit (code=exited, status=0/SUCCESS)
Process: 36633 ExecStart=/bin/screen -d -m -S test_screen (code=exited, status=0/SUCCESS)
Main PID: 36634 (code=exited, status=1/FAILURE)
Sep 20 12:48:34 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:48:34 somehostname systemd[1]: Started Testing `screen` service.
Sep 20 12:51:00 somehostname systemd[1]: Stopping Testing `screen` service...
Sep 20 12:51:00 somehostname systemd[1]: test_screen.service: main process exited, code=exited, status=1/FAILURE
Sep 20 12:51:00 somehostname systemd[1]: Stopped Testing `screen` service.
Sep 20 12:51:00 somehostname systemd[1]: Unit test_screen.service entered failed state.
Sep 20 12:51:00 somehostname systemd[1]: test_screen.service failed.
to overcome that I had to have RemainAfterExit=True
(because I tried the suggestion to have Type=forking
and I commented out that RemainAfterExit
option).
list-unit-files
I had an issue, that I'm not able to reproduce now - when I tried systemctl start
the response was something like "No unit file", so I was wondering if there is a need to register it somehow.
No, you do not need to. You can execute systemctl list-unit-files --type=service
and you should see your unit there. My problem was, that ExecStart
parameter was wrong. When I tried the same now I have easier to understand message:
$ systemctl start test_screen.service
Job for test_screen.service failed because the control process exited with error code. See "systemctl status test_screen.service" and "journalctl -xe" for details.
$ systemctl status test_screen.service
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 12:55:53 CEST; 1min 3s ago
Process: 37344 ExecStart=/bin/screen2 -d -m -S test_screen (code=exited, status=203/EXEC)
Main PID: 36634 (code=exited, status=1/FAILURE)
Sep 20 12:55:53 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:55:53 somehostname systemd[37344]: Failed at step EXEC spawning /bin/screen2: No such file or directory
Sep 20 12:55:53 somehostname systemd[1]: test_screen.service: control process exited, code=exited status=203
Sep 20 12:55:53 somehostname systemd[1]: Failed to start Testing `screen` service.
Sep 20 12:55:53 somehostname systemd[1]: Unit test_screen.service entered failed state.
Sep 20 12:55:53 somehostname systemd[1]: test_screen.service failed.
Executing script
I tried to modify my test_screen to call script
$ cat /etc/systemd/system/test_screen_script.service
[Unit]
Description=Testing `screen` service
[Service]
Type=forking
ExecStart=/root/test_screen_start.sh
ExecStop=/root/test_screen_stop.sh
#Environment=
#Restart=always
RemainAfterExit=True
[Install]
WantedBy=default.target
while scripts are just wrapped for previous calls
$ cat /root/test_screen_start.sh
/bin/screen -d -m -S test_screen
$ cat /root/test_screen_stop.sh
/bin/screen -S test_screen -X quit
when I did that, it is not starting up:
$ systemctl start test_screen_script
Job for test_screen_script.service failed because the control process exited with error code. See "systemctl status test_screen_script.service" and "journalctl -xe" for details.
$ systemctl status test_screen_script.service
● test_screen_script.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen_script.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 15:47:59 CEST; 8s ago
Process: 63582 ExecStart=/root/test_screen_start.sh (code=exited, status=203/EXEC)
Main PID: 60698 (code=exited, status=0/SUCCESS)
Sep 20 15:47:59 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 15:47:59 somehostname systemd[63582]: Failed at step EXEC spawning /root/test_screen_start.sh: Exec format error
Sep 20 15:47:59 somehostname systemd[1]: test_screen_script.service: control process exited, code=exited status=203
Sep 20 15:47:59 somehostname systemd[1]: Failed to start Testing `screen` service.
Sep 20 15:47:59 somehostname systemd[1]: Unit test_screen_script.service entered failed state.
Sep 20 15:47:59 somehostname systemd[1]: test_screen_script.service failed.
It would be good is someone can describe the reason. Fix for that is to add #!/bin/bash
.
References
- I found that
list-unit-files
here: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
add a comment |
It seems, that I solved it for screen
...
Firstly I removed that Restart=always
parameter.
To make it work I also had to add RemainAfterExit=True
.
With old init scripts it was clear where to have the code. I do not really know what is a proper place to put the rest of code. Should I simply call my script from ExecStart=
?
My additional findings during learning.
status
There is a good question (I meant I was interested too), how to implement status checking - systemd custom status message?
Short answer is, it works (somehow) out f the box = you do not need to care much.
So, for my test_screen service I can call systemctl status test_screen.service
and I'll get
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2017-09-20 12:48:34 CEST; 1s ago
Process: 36633 ExecStart=/bin/screen -d -m -S test_screen (code=exited, status=0/SUCCESS)
Main PID: 36634 (screen)
CGroup: /system.slice/test_screen.service
├─36634 /bin/SCREEN -d -m -S test_screen
└─36635 /bin/sh
Sep 20 12:48:34 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:48:34 somehostname systemd[1]: Started Testing `screen` service.
...strange is, that when I stop it, for status I got failed:
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 12:51:00 CEST; 1s ago
Process: 36805 ExecStop=/bin/screen -S test_screen -X quit (code=exited, status=0/SUCCESS)
Process: 36633 ExecStart=/bin/screen -d -m -S test_screen (code=exited, status=0/SUCCESS)
Main PID: 36634 (code=exited, status=1/FAILURE)
Sep 20 12:48:34 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:48:34 somehostname systemd[1]: Started Testing `screen` service.
Sep 20 12:51:00 somehostname systemd[1]: Stopping Testing `screen` service...
Sep 20 12:51:00 somehostname systemd[1]: test_screen.service: main process exited, code=exited, status=1/FAILURE
Sep 20 12:51:00 somehostname systemd[1]: Stopped Testing `screen` service.
Sep 20 12:51:00 somehostname systemd[1]: Unit test_screen.service entered failed state.
Sep 20 12:51:00 somehostname systemd[1]: test_screen.service failed.
to overcome that I had to have RemainAfterExit=True
(because I tried the suggestion to have Type=forking
and I commented out that RemainAfterExit
option).
list-unit-files
I had an issue, that I'm not able to reproduce now - when I tried systemctl start
the response was something like "No unit file", so I was wondering if there is a need to register it somehow.
No, you do not need to. You can execute systemctl list-unit-files --type=service
and you should see your unit there. My problem was, that ExecStart
parameter was wrong. When I tried the same now I have easier to understand message:
$ systemctl start test_screen.service
Job for test_screen.service failed because the control process exited with error code. See "systemctl status test_screen.service" and "journalctl -xe" for details.
$ systemctl status test_screen.service
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 12:55:53 CEST; 1min 3s ago
Process: 37344 ExecStart=/bin/screen2 -d -m -S test_screen (code=exited, status=203/EXEC)
Main PID: 36634 (code=exited, status=1/FAILURE)
Sep 20 12:55:53 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:55:53 somehostname systemd[37344]: Failed at step EXEC spawning /bin/screen2: No such file or directory
Sep 20 12:55:53 somehostname systemd[1]: test_screen.service: control process exited, code=exited status=203
Sep 20 12:55:53 somehostname systemd[1]: Failed to start Testing `screen` service.
Sep 20 12:55:53 somehostname systemd[1]: Unit test_screen.service entered failed state.
Sep 20 12:55:53 somehostname systemd[1]: test_screen.service failed.
Executing script
I tried to modify my test_screen to call script
$ cat /etc/systemd/system/test_screen_script.service
[Unit]
Description=Testing `screen` service
[Service]
Type=forking
ExecStart=/root/test_screen_start.sh
ExecStop=/root/test_screen_stop.sh
#Environment=
#Restart=always
RemainAfterExit=True
[Install]
WantedBy=default.target
while scripts are just wrapped for previous calls
$ cat /root/test_screen_start.sh
/bin/screen -d -m -S test_screen
$ cat /root/test_screen_stop.sh
/bin/screen -S test_screen -X quit
when I did that, it is not starting up:
$ systemctl start test_screen_script
Job for test_screen_script.service failed because the control process exited with error code. See "systemctl status test_screen_script.service" and "journalctl -xe" for details.
$ systemctl status test_screen_script.service
● test_screen_script.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen_script.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 15:47:59 CEST; 8s ago
Process: 63582 ExecStart=/root/test_screen_start.sh (code=exited, status=203/EXEC)
Main PID: 60698 (code=exited, status=0/SUCCESS)
Sep 20 15:47:59 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 15:47:59 somehostname systemd[63582]: Failed at step EXEC spawning /root/test_screen_start.sh: Exec format error
Sep 20 15:47:59 somehostname systemd[1]: test_screen_script.service: control process exited, code=exited status=203
Sep 20 15:47:59 somehostname systemd[1]: Failed to start Testing `screen` service.
Sep 20 15:47:59 somehostname systemd[1]: Unit test_screen_script.service entered failed state.
Sep 20 15:47:59 somehostname systemd[1]: test_screen_script.service failed.
It would be good is someone can describe the reason. Fix for that is to add #!/bin/bash
.
References
- I found that
list-unit-files
here: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
add a comment |
It seems, that I solved it for screen
...
Firstly I removed that Restart=always
parameter.
To make it work I also had to add RemainAfterExit=True
.
With old init scripts it was clear where to have the code. I do not really know what is a proper place to put the rest of code. Should I simply call my script from ExecStart=
?
My additional findings during learning.
status
There is a good question (I meant I was interested too), how to implement status checking - systemd custom status message?
Short answer is, it works (somehow) out f the box = you do not need to care much.
So, for my test_screen service I can call systemctl status test_screen.service
and I'll get
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2017-09-20 12:48:34 CEST; 1s ago
Process: 36633 ExecStart=/bin/screen -d -m -S test_screen (code=exited, status=0/SUCCESS)
Main PID: 36634 (screen)
CGroup: /system.slice/test_screen.service
├─36634 /bin/SCREEN -d -m -S test_screen
└─36635 /bin/sh
Sep 20 12:48:34 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:48:34 somehostname systemd[1]: Started Testing `screen` service.
...strange is, that when I stop it, for status I got failed:
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 12:51:00 CEST; 1s ago
Process: 36805 ExecStop=/bin/screen -S test_screen -X quit (code=exited, status=0/SUCCESS)
Process: 36633 ExecStart=/bin/screen -d -m -S test_screen (code=exited, status=0/SUCCESS)
Main PID: 36634 (code=exited, status=1/FAILURE)
Sep 20 12:48:34 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:48:34 somehostname systemd[1]: Started Testing `screen` service.
Sep 20 12:51:00 somehostname systemd[1]: Stopping Testing `screen` service...
Sep 20 12:51:00 somehostname systemd[1]: test_screen.service: main process exited, code=exited, status=1/FAILURE
Sep 20 12:51:00 somehostname systemd[1]: Stopped Testing `screen` service.
Sep 20 12:51:00 somehostname systemd[1]: Unit test_screen.service entered failed state.
Sep 20 12:51:00 somehostname systemd[1]: test_screen.service failed.
to overcome that I had to have RemainAfterExit=True
(because I tried the suggestion to have Type=forking
and I commented out that RemainAfterExit
option).
list-unit-files
I had an issue, that I'm not able to reproduce now - when I tried systemctl start
the response was something like "No unit file", so I was wondering if there is a need to register it somehow.
No, you do not need to. You can execute systemctl list-unit-files --type=service
and you should see your unit there. My problem was, that ExecStart
parameter was wrong. When I tried the same now I have easier to understand message:
$ systemctl start test_screen.service
Job for test_screen.service failed because the control process exited with error code. See "systemctl status test_screen.service" and "journalctl -xe" for details.
$ systemctl status test_screen.service
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 12:55:53 CEST; 1min 3s ago
Process: 37344 ExecStart=/bin/screen2 -d -m -S test_screen (code=exited, status=203/EXEC)
Main PID: 36634 (code=exited, status=1/FAILURE)
Sep 20 12:55:53 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:55:53 somehostname systemd[37344]: Failed at step EXEC spawning /bin/screen2: No such file or directory
Sep 20 12:55:53 somehostname systemd[1]: test_screen.service: control process exited, code=exited status=203
Sep 20 12:55:53 somehostname systemd[1]: Failed to start Testing `screen` service.
Sep 20 12:55:53 somehostname systemd[1]: Unit test_screen.service entered failed state.
Sep 20 12:55:53 somehostname systemd[1]: test_screen.service failed.
Executing script
I tried to modify my test_screen to call script
$ cat /etc/systemd/system/test_screen_script.service
[Unit]
Description=Testing `screen` service
[Service]
Type=forking
ExecStart=/root/test_screen_start.sh
ExecStop=/root/test_screen_stop.sh
#Environment=
#Restart=always
RemainAfterExit=True
[Install]
WantedBy=default.target
while scripts are just wrapped for previous calls
$ cat /root/test_screen_start.sh
/bin/screen -d -m -S test_screen
$ cat /root/test_screen_stop.sh
/bin/screen -S test_screen -X quit
when I did that, it is not starting up:
$ systemctl start test_screen_script
Job for test_screen_script.service failed because the control process exited with error code. See "systemctl status test_screen_script.service" and "journalctl -xe" for details.
$ systemctl status test_screen_script.service
● test_screen_script.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen_script.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 15:47:59 CEST; 8s ago
Process: 63582 ExecStart=/root/test_screen_start.sh (code=exited, status=203/EXEC)
Main PID: 60698 (code=exited, status=0/SUCCESS)
Sep 20 15:47:59 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 15:47:59 somehostname systemd[63582]: Failed at step EXEC spawning /root/test_screen_start.sh: Exec format error
Sep 20 15:47:59 somehostname systemd[1]: test_screen_script.service: control process exited, code=exited status=203
Sep 20 15:47:59 somehostname systemd[1]: Failed to start Testing `screen` service.
Sep 20 15:47:59 somehostname systemd[1]: Unit test_screen_script.service entered failed state.
Sep 20 15:47:59 somehostname systemd[1]: test_screen_script.service failed.
It would be good is someone can describe the reason. Fix for that is to add #!/bin/bash
.
References
- I found that
list-unit-files
here: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
It seems, that I solved it for screen
...
Firstly I removed that Restart=always
parameter.
To make it work I also had to add RemainAfterExit=True
.
With old init scripts it was clear where to have the code. I do not really know what is a proper place to put the rest of code. Should I simply call my script from ExecStart=
?
My additional findings during learning.
status
There is a good question (I meant I was interested too), how to implement status checking - systemd custom status message?
Short answer is, it works (somehow) out f the box = you do not need to care much.
So, for my test_screen service I can call systemctl status test_screen.service
and I'll get
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2017-09-20 12:48:34 CEST; 1s ago
Process: 36633 ExecStart=/bin/screen -d -m -S test_screen (code=exited, status=0/SUCCESS)
Main PID: 36634 (screen)
CGroup: /system.slice/test_screen.service
├─36634 /bin/SCREEN -d -m -S test_screen
└─36635 /bin/sh
Sep 20 12:48:34 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:48:34 somehostname systemd[1]: Started Testing `screen` service.
...strange is, that when I stop it, for status I got failed:
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 12:51:00 CEST; 1s ago
Process: 36805 ExecStop=/bin/screen -S test_screen -X quit (code=exited, status=0/SUCCESS)
Process: 36633 ExecStart=/bin/screen -d -m -S test_screen (code=exited, status=0/SUCCESS)
Main PID: 36634 (code=exited, status=1/FAILURE)
Sep 20 12:48:34 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:48:34 somehostname systemd[1]: Started Testing `screen` service.
Sep 20 12:51:00 somehostname systemd[1]: Stopping Testing `screen` service...
Sep 20 12:51:00 somehostname systemd[1]: test_screen.service: main process exited, code=exited, status=1/FAILURE
Sep 20 12:51:00 somehostname systemd[1]: Stopped Testing `screen` service.
Sep 20 12:51:00 somehostname systemd[1]: Unit test_screen.service entered failed state.
Sep 20 12:51:00 somehostname systemd[1]: test_screen.service failed.
to overcome that I had to have RemainAfterExit=True
(because I tried the suggestion to have Type=forking
and I commented out that RemainAfterExit
option).
list-unit-files
I had an issue, that I'm not able to reproduce now - when I tried systemctl start
the response was something like "No unit file", so I was wondering if there is a need to register it somehow.
No, you do not need to. You can execute systemctl list-unit-files --type=service
and you should see your unit there. My problem was, that ExecStart
parameter was wrong. When I tried the same now I have easier to understand message:
$ systemctl start test_screen.service
Job for test_screen.service failed because the control process exited with error code. See "systemctl status test_screen.service" and "journalctl -xe" for details.
$ systemctl status test_screen.service
● test_screen.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 12:55:53 CEST; 1min 3s ago
Process: 37344 ExecStart=/bin/screen2 -d -m -S test_screen (code=exited, status=203/EXEC)
Main PID: 36634 (code=exited, status=1/FAILURE)
Sep 20 12:55:53 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 12:55:53 somehostname systemd[37344]: Failed at step EXEC spawning /bin/screen2: No such file or directory
Sep 20 12:55:53 somehostname systemd[1]: test_screen.service: control process exited, code=exited status=203
Sep 20 12:55:53 somehostname systemd[1]: Failed to start Testing `screen` service.
Sep 20 12:55:53 somehostname systemd[1]: Unit test_screen.service entered failed state.
Sep 20 12:55:53 somehostname systemd[1]: test_screen.service failed.
Executing script
I tried to modify my test_screen to call script
$ cat /etc/systemd/system/test_screen_script.service
[Unit]
Description=Testing `screen` service
[Service]
Type=forking
ExecStart=/root/test_screen_start.sh
ExecStop=/root/test_screen_stop.sh
#Environment=
#Restart=always
RemainAfterExit=True
[Install]
WantedBy=default.target
while scripts are just wrapped for previous calls
$ cat /root/test_screen_start.sh
/bin/screen -d -m -S test_screen
$ cat /root/test_screen_stop.sh
/bin/screen -S test_screen -X quit
when I did that, it is not starting up:
$ systemctl start test_screen_script
Job for test_screen_script.service failed because the control process exited with error code. See "systemctl status test_screen_script.service" and "journalctl -xe" for details.
$ systemctl status test_screen_script.service
● test_screen_script.service - Testing `screen` service
Loaded: loaded (/etc/systemd/system/test_screen_script.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-09-20 15:47:59 CEST; 8s ago
Process: 63582 ExecStart=/root/test_screen_start.sh (code=exited, status=203/EXEC)
Main PID: 60698 (code=exited, status=0/SUCCESS)
Sep 20 15:47:59 somehostname systemd[1]: Starting Testing `screen` service...
Sep 20 15:47:59 somehostname systemd[63582]: Failed at step EXEC spawning /root/test_screen_start.sh: Exec format error
Sep 20 15:47:59 somehostname systemd[1]: test_screen_script.service: control process exited, code=exited status=203
Sep 20 15:47:59 somehostname systemd[1]: Failed to start Testing `screen` service.
Sep 20 15:47:59 somehostname systemd[1]: Unit test_screen_script.service entered failed state.
Sep 20 15:47:59 somehostname systemd[1]: test_screen_script.service failed.
It would be good is someone can describe the reason. Fix for that is to add #!/bin/bash
.
References
- I found that
list-unit-files
here: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
edited Sep 20 '17 at 13:50
answered Sep 19 '17 at 11:13
BetlistaBetlista
1065
1065
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f393138%2fstartup-shutdown-script-for-redhat%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
-init-script, rhel
1
Why do you need to use screen? Systemd is already capable of backgrounding processes for you so there is no need for terminal multiplexers like screen.
– Michael Daffin
Sep 19 '17 at 9:57
@MichaelDaffin I picked screen just to be able to test with something simple, because I have no experience with startup scripts so far...
– Betlista
Sep 19 '17 at 10:27
Can you give an example of the application you are trying to run? Does it background itself? Sounds like you are using screen as a hack to get around your process not backgrounding itself for old style init scripts but this is not required in systemd. More details on what you are trying to achieve overall would give you better answers.
– Michael Daffin
Sep 19 '17 at 11:06
As a target solution I'm not going to use screen at all, it will be IBM WAS, but for MCVE I cannot ask you to install WAS...
– Betlista
Sep 19 '17 at 11:09
1
The reason I ask is there is a difference between
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.– Michael Daffin
Sep 19 '17 at 11:39