How to execute sh script using system service on Linux (rhel 7)
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have linux script that starts up my service:
/home/MyApp/MyAppStart.sh
java -jar -Dspring.profiles.active=dev $home/MyApp/MyApp.jar /tmp 2>> /dev/null >> /dev/null & echo $! > /home/MyApp/MyApp-pid
I have a systemd service that will execute the same command when we start the service:
/etc/systemd/system/MyApp.service
[Unit]
Description=My App name
After=syslog.target
[Service]
User=root
Group=root
ExecStart=java -jar -Dspring.profiles.active=dev $home/MyApp/MyApp.jar /tmp 2>> /dev/null >> /dev/null & echo $! > /home/MyApp/MyApp-pid
StandardOutput=file:/home/logs/stdout
StandardError=file:/home/logs/stderr
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
Question 1:
What I want from the command is start up the jar, print output to console and to a file, print process ID to a file.
Question 2:
I do not see any logs under /home/logs. How do I fix this?
Question 3:
MyApp.service needs to take Environment name (dev/sys/prod) as input. How do I achieve this? If this cannot be achieved, is there a work around?
Question 4:
MyAppStart.sh and MyApp.service do the same thing i.e. I can get the jar running by either executing the bash script or starting up the service.
Instead of having 2 ways to start the jar, can I use just one. I definitely need the systemd service, so can I modify the start-script to execute the service?
linux shell-script rhel systemd services
New contributor
add a comment |Â
up vote
0
down vote
favorite
I have linux script that starts up my service:
/home/MyApp/MyAppStart.sh
java -jar -Dspring.profiles.active=dev $home/MyApp/MyApp.jar /tmp 2>> /dev/null >> /dev/null & echo $! > /home/MyApp/MyApp-pid
I have a systemd service that will execute the same command when we start the service:
/etc/systemd/system/MyApp.service
[Unit]
Description=My App name
After=syslog.target
[Service]
User=root
Group=root
ExecStart=java -jar -Dspring.profiles.active=dev $home/MyApp/MyApp.jar /tmp 2>> /dev/null >> /dev/null & echo $! > /home/MyApp/MyApp-pid
StandardOutput=file:/home/logs/stdout
StandardError=file:/home/logs/stderr
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
Question 1:
What I want from the command is start up the jar, print output to console and to a file, print process ID to a file.
Question 2:
I do not see any logs under /home/logs. How do I fix this?
Question 3:
MyApp.service needs to take Environment name (dev/sys/prod) as input. How do I achieve this? If this cannot be achieved, is there a work around?
Question 4:
MyAppStart.sh and MyApp.service do the same thing i.e. I can get the jar running by either executing the bash script or starting up the service.
Instead of having 2 ways to start the jar, can I use just one. I definitely need the systemd service, so can I modify the start-script to execute the service?
linux shell-script rhel systemd services
New contributor
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have linux script that starts up my service:
/home/MyApp/MyAppStart.sh
java -jar -Dspring.profiles.active=dev $home/MyApp/MyApp.jar /tmp 2>> /dev/null >> /dev/null & echo $! > /home/MyApp/MyApp-pid
I have a systemd service that will execute the same command when we start the service:
/etc/systemd/system/MyApp.service
[Unit]
Description=My App name
After=syslog.target
[Service]
User=root
Group=root
ExecStart=java -jar -Dspring.profiles.active=dev $home/MyApp/MyApp.jar /tmp 2>> /dev/null >> /dev/null & echo $! > /home/MyApp/MyApp-pid
StandardOutput=file:/home/logs/stdout
StandardError=file:/home/logs/stderr
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
Question 1:
What I want from the command is start up the jar, print output to console and to a file, print process ID to a file.
Question 2:
I do not see any logs under /home/logs. How do I fix this?
Question 3:
MyApp.service needs to take Environment name (dev/sys/prod) as input. How do I achieve this? If this cannot be achieved, is there a work around?
Question 4:
MyAppStart.sh and MyApp.service do the same thing i.e. I can get the jar running by either executing the bash script or starting up the service.
Instead of having 2 ways to start the jar, can I use just one. I definitely need the systemd service, so can I modify the start-script to execute the service?
linux shell-script rhel systemd services
New contributor
I have linux script that starts up my service:
/home/MyApp/MyAppStart.sh
java -jar -Dspring.profiles.active=dev $home/MyApp/MyApp.jar /tmp 2>> /dev/null >> /dev/null & echo $! > /home/MyApp/MyApp-pid
I have a systemd service that will execute the same command when we start the service:
/etc/systemd/system/MyApp.service
[Unit]
Description=My App name
After=syslog.target
[Service]
User=root
Group=root
ExecStart=java -jar -Dspring.profiles.active=dev $home/MyApp/MyApp.jar /tmp 2>> /dev/null >> /dev/null & echo $! > /home/MyApp/MyApp-pid
StandardOutput=file:/home/logs/stdout
StandardError=file:/home/logs/stderr
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
Question 1:
What I want from the command is start up the jar, print output to console and to a file, print process ID to a file.
Question 2:
I do not see any logs under /home/logs. How do I fix this?
Question 3:
MyApp.service needs to take Environment name (dev/sys/prod) as input. How do I achieve this? If this cannot be achieved, is there a work around?
Question 4:
MyAppStart.sh and MyApp.service do the same thing i.e. I can get the jar running by either executing the bash script or starting up the service.
Instead of having 2 ways to start the jar, can I use just one. I definitely need the systemd service, so can I modify the start-script to execute the service?
linux shell-script rhel systemd services
linux shell-script rhel systemd services
New contributor
New contributor
New contributor
asked 6 mins ago
user1478392
11
11
New contributor
New contributor
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
user1478392 is a new contributor. Be nice, and check out our Code of Conduct.
user1478392 is a new contributor. Be nice, and check out our Code of Conduct.
user1478392 is a new contributor. Be nice, and check out our Code of Conduct.
user1478392 is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f479226%2fhow-to-execute-sh-script-using-system-service-on-linux-rhel-7%23new-answer', 'question_page');
);
Post as a guest
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
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
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