SHC Compiled script fails to run using systemctl - bash

I've got a very simple bash script called test.
#!/bin/bash
while true
do
currdate=$(date +%d/%m/%Y-%H:%M:%S)
echo -e "\n$currdate ..."
sleep 1
done
Running this from the command line works exactly as expected.
I've compiled this with SHC has follows:
shc -r -U -f test.sh -o test
Running this from the command line works as expected.
I've setup to run this using systemctl, added my config file to /etc/init.d and this references test
If test is my un complied bash script, then systemclt start test works fine.
If I swap test and replace it with the complied version, then it fails.
systemctl status shows:
test.service - LSB: Test
Loaded: loaded (/etc/init.d/test; generated; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2020-02-18 15:38:05 GMT; 6s ago
Docs: man:systemd-sysv-generator(8)
Process: 18089 ExecStart=/etc/init.d/test start (code=exited, status=7)
Tasks: 2
CGroup: /system.slice/test.service
├─18096 /home/rocket/test -c >
└─18142 sleep 1
Feb 18 15:38:05 linux-c0a9 systemd[1]: test.service: Control process exited, code=exited status=7
Feb 18 15:38:05 linux-c0a9 systemd[1]: Failed to start LSB: Test.
Feb 18 15:38:05 linux-c0a9 systemd[1]: test.service: Unit entered failed state.
Feb 18 15:38:05 linux-c0a9 systemd[1]: test.service: Failed with result 'exit-code'.
journalctl shows:
Feb 18 15:38:05 linux-c0a9 systemd[1]: Starting LSB: Test...
Feb 18 15:38:05 linux-c0a9 test[18089]: Starting test
Feb 18 15:38:05 linux-c0a9 test[18089]: 18/02/2020-15:38:05 ...
Feb 18 15:38:05 linux-c0a9 test[18089]: ..failed
Feb 18 15:38:05 linux-c0a9 systemd[1]: test.service: Control process exited, code=exited status=7
Feb 18 15:38:05 linux-c0a9 systemd[1]: Failed to start LSB: Test.
Feb 18 15:38:05 linux-c0a9 systemd[1]: test.service: Unit entered failed state.
Feb 18 15:38:05 linux-c0a9 systemd[1]: test.service: Failed with result 'exit-code'.
Does anyone know why this fails and how to stop it failing ?
I'm only using SHC to stop users editing the script, not for any security etc.
Thanks

I think I may have solved this.
My script in /etc/init.d was calling /home/rocket/test
When that is a bash file it's fine, when it's compiled it stops working.
To get it to work I changed test to always be a bash file that calls the compiled test which is in in /home/rocket/bin/test

Related

Elasticsearch won't start and no logs centOS

Hi after downloading the latest rpm for CentIS and and installing for the first time I am getting this error in the logs:
Jun 22 09:47:31 ssd316r.simpleservers.co.uk systemd[1]: Starting Elasticsearch...
Jun 22 09:47:32 ssd316r.simpleservers.co.uk systemd-entrypoint[2501]: ERROR: Temporary file directory [/usr/share/elasticsearch/tmp] does not exist or is not accessible
Jun 22 09:47:32 ssd316r.simpleservers.co.uk systemd[1]: elasticsearch.service: main process exited, code=exited, status=78/n/a
Jun 22 09:47:32 ssd316r.simpleservers.co.uk systemd[1]: Failed to start Elasticsearch.
Jun 22 09:47:32 ssd316r.simpleservers.co.uk systemd[1]: Unit elasticsearch.service entered failed state.
Jun 22 09:47:32 ssd316r.simpleservers.co.uk systemd[1]: elasticsearch.service failed.
Error is due to below log:
Jun 22 09:47:32 ssd316r.simpleservers.co.uk systemd-entrypoint[2501]:
ERROR: Temporary file directory [/usr/share/elasticsearch/tmp] does
not exist or is not accessible
Can you check /usr/share/elasticsearch/tmp is present on your server or not, if not please create this folder at the same location and make sure your elasticsearch process has write access to it.

Compute Engine start node server on instance startup

I am trying to run a discord bot in a node application in a free Compute Engine instance. I am struggling to make a script that actually starts the node app.
I created this script and added it as startup-script metadata from file:
cd code/movo-tron-2000 && npm start &
I checked that the script runs with sudo google_metadata_script_runner --script-type startup --debug, but when I restart the instance, the app doesn't start. Running sudo journalctl -u google-startup-scripts.service prints the following logs:
Apr 20 12:19:08 bot-vm systemd[1]: Starting Google Compute Engine Startup Scripts...
Apr 20 12:19:09 bot-vm startup-script[691]: INFO Starting startup scripts.
Apr 20 12:19:09 bot-vm startup-script[691]: INFO Found startup-script in metadata.
Apr 20 12:19:09 bot-vm startup-script[691]: INFO startup-script: /startup-od52epug/tmpjy_z4vue: line 1: cd: code/mo
Apr 20 12:19:09 bot-vm startup-script[691]: INFO startup-script: Return code 0.
Apr 20 12:19:09 bot-vm startup-script[691]: INFO Finished running startup scripts.
Apr 20 12:19:09 bot-vm systemd[1]: Started Google Compute Engine Startup Scripts.
I see that the script gets executed, but also gets terminated. The app listened for requests, so it shouldn't get terminated in order to run. I assume that the startup script gets run on the same thread as the google compute engine startup script so it gets terminated in order to continue the vm boot. What should I change in my startup script in order to start my app properly and not have it terminated by the instance?
Edit: I set up the following systemd service and script at their corresponding locations
Service:
[Unit]
Description=Start bot
[Service]
ExecStart=/home/me_adi_hf/code/movo-tron-2000/start.sh
[Install]
WantedBy=default.target
Script:
#!/bin/sh
date > /root/bot_report.txt
du -sh /home/ >> /root/bot_report.txt
But when running sudo systemd start bot.service and then checking it's status with sudo systemd status bot.service am getting this output, indicating Exec format error:
bot-start.service - Start bot
Loaded: loaded (/etc/systemd/system/bot-start.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2020-04-21 09:43:01 UTC; 9s ago
Process: 19303 ExecStart=/home/me_adi_hf/code/movo-tron-2000/start.sh (code=exited, status=203/EXEC)
Main PID: 19303 (code=exited, status=203/EXEC)
Apr 21 09:43:01 bot-vm systemd[1]: Started Start bot.
Apr 21 09:43:01 bot-vm systemd[19303]: bot-start.service: Failed at step EXEC spawning /home/me_adi_hf/code/movo-tron-2000/start.sh: Exec format error
Apr 21 09:43:01 bot-vm systemd[1]: bot-start.service: Main process exited, code=exited, status=203/EXEC
Apr 21 09:43:01 bot-vm systemd[1]: bot-start.service: Unit entered failed state.
Apr 21 09:43:01 bot-vm systemd[1]: bot-start.service: Failed with result 'exit-code'.
I am not sure what causes the error, since the service file syntax looks correct

Kibana ssl configuration

I installed elasticsearch and kibana using this guide:
https://opendistro.github.io/for-elasticsearch-docs/docs/install/
I created SSL for domain and using it in kibana.yml config.
server.ssl.enabled: true
server.ssl.key: /etc/elasticsearch/key.pem
server.ssl.certificate: /etc/elasticsearch/cert.pem
But, when I restart the service I am getting below error.
sudo service kibana status
● kibana.service - Kibana
Loaded: loaded (/etc/systemd/system/kibana.service; disabled; vendor preset: enabled)
Active: failed (Result: start-limit-hit) since Tue 2019-05-14 19:39:21 UTC; 833ms ago
Process: 50944 ExecStart=/usr/share/kibana/bin/kibana -c /etc/kibana/kibana.yml (code=exited, status=1/FAILURE)
Main PID: 50944 (code=exited, status=1/FAILURE)
May 14 19:39:21 mts-elk systemd[1]: kibana.service: Unit entered failed state.
May 14 19:39:21 mts-elk systemd[1]: kibana.service: Failed with result 'exit-code'.
May 14 19:39:21 mts-elk systemd[1]: kibana.service: Service hold-off time over, scheduling restart.
May 14 19:39:21 mts-elk systemd[1]: Stopped Kibana.
May 14 19:39:21 mts-elk systemd[1]: kibana.service: Start request repeated too quickly.
May 14 19:39:21 mts-elk systemd[1]: Failed to start Kibana.
May 14 19:39:21 mts-elk systemd[1]: kibana.service: Unit entered failed state.
May 14 19:39:21 mts-elk systemd[1]: kibana.service: Failed with result 'start-limit-hit'.
I don't know where to look for kibana logs other than this.

How to resolve the starting error in sonarqube?

While giving sudo update-rc.d -f sonar remove I'm getting the below error
insserv: warning: script 'K01sonarqube' missing LSB tags and overrides
insserv: warning: script 'sonarqube' missing LSB tags and overrides
insserv: warning: script 'sonar' missing LSB tags and overrides
While starting sonarqube i'm getting
● sonarqube.service - SonarQube service
Loaded: loaded (/etc/systemd/system/sonarqube.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Fri 2018-10-19 12:48:24 IST; 14s ago
Process: 11420 ExecStop=/opt/sonarqube/sonarqube-6.7.5/bin/linux-x86-64/sonar.sh stop (code=exited, status=0/SUCCESS)
Process: 11372 ExecStart=/opt/sonarqube/sonarqube-6.7.5/bin/linux-x86-64/sonar.sh start (code=exited, status=0/SUCCESS)
Main PID: 984 (code=exited, status=1/FAILURE)
Oct 19 12:48:24 master-VB systemd[1]: Started SonarQube service.
Oct 19 12:48:24 master-VB systemd[1]: sonarqube.service: Service hold-off time over, scheduling restart.
Oct 19 12:48:24 master-VB systemd[1]: Stopped SonarQube service.
Oct 19 12:48:24 master-VB systemd[1]: sonarqube.service: Start request repeated too quickly.
Oct 19 12:48:24 master-VB systemd[1]: Failed to start SonarQube service.

elasticsearch connection refused error

I am following this article to install and configure elasticsearch on my system, both the installation and configuration worked fine but when i try to run elasticsearch:
curl -X GET 'http://localhost:9200'
i get this error:
curl: (7) Failed to connect to localhost port 9200: Connection refused
EDIT: 1
after #val suggestion:
sudo systemctl status elasticsearch
it returned as:
elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendo
Active: failed (Result: exit-code) since Wed 2017-05-24 09:11:16 IST; 2h 17mi
Docs: http://www.elastic.co
Process: 5043 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DI
Process: 5039 ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-
Main PID: 5043 (code=exited, status=1/FAILURE)
May 24 09:11:16 ahmed-pc systemd[1]: Starting Elasticsearch...
May 24 09:11:16 ahmed-pc systemd[1]: Started Elasticsearch.
May 24 09:11:16 ahmed-pc systemd[1]: elasticsearch.service: Main process exited,
May 24 09:11:16 ahmed-pc systemd[1]: elasticsearch.service: Unit entered failed
May 24 09:11:16 ahmed-pc systemd[1]: elasticsearch.service: Failed with result '
lines 1-13/13 (END)
Edit 2:
journalctrl -f results
May 25 08:35:31 ahmed-pc systemd[1]: Starting Elasticsearch...
May 25 08:35:31 ahmed-pc systemd[1]: Started Elasticsearch.
May 25 08:35:31 ahmed-pc sudo[6256]: pam_unix(sudo:session): session closed for user root
May 25 08:35:42 ahmed-pc dhclient[3644]: DHCPREQUEST of 192.168.43.121 on wlp3s0 to 192.168.43.1 port 67 (xid=0x4be71b5a)
May 25 08:35:42 ahmed-pc dhclient[3644]: DHCPACK of 192.168.43.121 from 192.168.43.1
May 25 08:35:42 ahmed-pc dhclient[3644]: bound to 192.168.43.121 -- renewal in 1339 seconds.
May 25 08:35:43 ahmed-pc systemd[1]: elasticsearch.service: Main process exited, code=exited, status=1/FAILURE
May 25 08:35:43 ahmed-pc systemd[1]: elasticsearch.service: Unit entered failed state.
May 25 08:35:43 ahmed-pc systemd[1]: elasticsearch.service: Failed with result 'exit-code'.

Resources