[SOLVED] Awk command giving issue for .service file execution
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Awk command giving issue for .service file execution
I have centos 7. Thus in the /lib/systemd/system I created a new .service as below.
When I am using awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }' this command in it does not execute the command. But when I run from command prompt that works fine.
Quote:
[Unit]
Description=Server 11000 Process Restart Upstart Script
After=auditd.service systemd-user-sessions.service time-sync.target
When I start the service e.g. systemctl start server11000.service it just starts. But when I type systemctl status server11000.service below is the output.
Quote:
Server 11000 Process Restart Upstart Script
Loaded: loaded (/usr/lib/systemd/system/server11000.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since Sun 2019-05-26 01:31:10 +08; 1s ago
Process: 26515 ExecStart=/bin/bash /usr/local/serverBash_11000.sh | awk { print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); } | rotatelogs /usr/local/server11000/log/service.log 30M (code=exited, status=127)
Main PID: 26515 (code=exited, status=127)
CGroup: /system.slice/server11000.service
└─43576 java -cp .:./jars/* server11000
May 26 01:33:16 localhost.localdomain systemd[1]: Unit server11000.service entered failed state.
May 26 01:33:16 localhost.localdomain systemd[1]: server11000.service failed.
Hi Scasey & Michaelk,
Actually currently my serverBash_11000.sh is as below. So your suggestion is as to add the command in this bash ? Or should I create another script and put the command in it and leave this script as it is? Sorry a bit confused here.
Hi Scasey & Michaelk,
Actually currently my serverBash_11000.sh is as below. So your suggestion is as to add the command in this bash ? Or should I create another script and put the command in it and leave this script as it is? Sorry a bit confused here.
Will adding the pipe to /bin/awk, etc. after the java do what you what you want?
(Note: should have the absolute path to clear and java in that script as well)
If not, then create a new script containing the commands you already have and ExecStart that script.
Hi Scasey,
I notice using the awk piping I do miss some earlier missing example when I start my application it get connection pooling.
May 26, 2019 2:52:03 AM com.zaxxer.hikari.HikariDataSource <init>
INFO: HikariPool-1 - Starting...
May 26, 2019 2:52:04 AM com.zaxxer.hikari.HikariDataSource <init>
INFO: HikariPool-1 - Start completed.
But this is not shown in the logs file. Just to confirm must I create a file called service.log first?
Quote:
Will adding the pipe to /bin/awk, etc. after the java do what you what you want?
(Note: should have the absolute path to clear and java in that script as well)
I am not so clear on this ? What are you trying to confirm on this ?
Quote:
If not, then create a new script containing the commands you already have and ExecStart that script.
Yes in the meantime I have tested already this method seems to be working.
Hi Scasey,
Just wonrdering what I did correct and efficient right. I created another .sh file and in it I put this /bin/bash /usr/local/serverBash_11000.sh | /bin/awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }' | /sbin/rotatelogs /usr/local/server11000. So automatically this calls the serverBash_11000.sh bash file. You were saying regarding clear I should use the path I dont get you on that or should I remove the clear key word?
So automatically this calls the serverBash_11000.sh bash file. You were saying regarding clear I should use the path I dont get you on that or should I remove the clear key word?
Please use [code]code tags when posting code or output.
You said that serverBash_11000.sh contained a clear command and a java command. All I was saying is that you should use absolute paths to those commands as well. That insures the commands can always be found.
I don't know exactly what you're trying to accomplish, so I don't know if the clear command is appropriate..
Hi Scasey,
Sorry for me missing on the code tag earlier.
Actually what I am trying to achieve is previously I used to have a java daemon wrapper to run a socket server based on java. Since the wrapper have not been update and has issues on new centos 7, thus I did a research and found this new method using service so I am very new to it and learning . I used to use monit to monitor it incase it goes down and able to email me. Hope I am clearer now.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.