Executable which I am trying to run from a daemon script intermittently becomes inaccessible - linux

I have a script written which tries to restart an executable if it is detected as stopped. However on occassion the script is unable to find the executable file, and it becomes accessible as soon as I log back into the machine using putty. Below are the logs for the phenomenon I am trying to describe.
Aug 4 23:41:24 USERNAME systemd[1]: my-scheduler.service: Service hold-off time over, scheduling restart.
Aug 4 23:41:24 USERNAME scheduler_startup[13535]: /usr/local/bin/scheduler_startup.sh: line 3: cd: /home/myUser/myFolder/Scheduler/dist/: No such file or directory
Aug 4 23:41:24 USERNAME scheduler_startup[13535]: /usr/local/bin/scheduler_startup.sh: line 4: ./Schedulercode: No such file or directory
Aug 4 23:41:24 USERNAME systemd[1]: my-scheduler.service: Main process exited, code=exited, status=127/n/a
Aug 4 23:41:24 USERNAME systemd[1]: my-scheduler.service: Unit entered failed state.
Aug 4 23:41:24 USERNAME systemd[1]: my-scheduler.service: Failed with result 'exit-code'.
Aug 4 23:41:29 USERNAME systemd[1]: my-scheduler.service: Service hold-off time over, scheduling restart.
Aug 4 23:41:29 USERNAME scheduler_startup[14213]: /usr/local/bin/scheduler_startup.sh: line 3: cd: /home/myUser/myFolder/Scheduler/dist/: No such file or directory
Aug 4 23:41:29 USERNAME scheduler_startup[14213]: /usr/local/bin/scheduler_startup.sh: line 4: ./Schedulercode: No such file or directory
Aug 4 23:41:29 USERNAME systemd[1]: my-scheduler.service: Main process exited, code=exited, status=127/n/a
Aug 4 23:41:29 USERNAME systemd[1]: my-scheduler.service: Unit entered failed state.
Aug 4 23:41:29 USERNAME systemd[1]: my-scheduler.service: Failed with result 'exit-code'.
Aug 4 23:41:35 USERNAME systemd[1]: my-scheduler.service: Service hold-off time over, scheduling restart.
Aug 4 23:41:35 USERNAME scheduler_startup[14889]: /usr/local/bin/scheduler_startup.sh: line 3: cd: /home/myUser/myFolder/Scheduler/dist/: No such file or directory
Aug 4 23:41:35 USERNAME scheduler_startup[14889]: /usr/local/bin/scheduler_startup.sh: line 4: ./Schedulercode: No such file or directory
Aug 4 23:41:35 USERNAME systemd[1]: my-scheduler.service: Main process exited, code=exited, status=127/n/a
Aug 4 23:41:35 USERNAME systemd[1]: my-scheduler.service: Unit entered failed state.
Aug 4 23:41:35 USERNAME systemd[1]: my-scheduler.service: Failed with result 'exit-code'.
Aug 4 23:41:40 USERNAME systemd[1]: my-scheduler.service: Service hold-off time over, scheduling restart.
Aug 4 23:41:41 USERNAME scheduler_startup[15313]: Scheduler Start - Version = 1.15 #Time: 2021-08-04 23:41:41.805467
As you can see on the last 2 lines, the restart attempt was successful and the application started running as expected. I am trying to find out what causes this temporary blindness to the executable in the system? and why is the file found again as soon as I log back in?
I am using is Ubuntu 20.xx

Related

problems starting service that runs a bash script that in turn runs a python script

I have the following service file, enable, and start files located in /home/pi/poolboy/service:
[Unit]
Description=Pool Boy
After=network-online.target
[Service]
ExecStart=/home/pi/poolboy/start
WorkingDirectory=/home/pi/poolboy
StandardOutput=inherit
StandardError=inherit
Restart=always
[Install]
WantedBy=multi-user.target
I have an "enable" script to install it:
#!/bin/bash
sudo cp /home/pi/poolboy/service/poolboy.service /lib/systemd/system/
sudo systemctl enable poolboy.service
I have a "start" script to start the service:
#!/bin/bash
sudo systemctl start poolboy.service
the actual start script that runs the application (and is called by the service) is located in /home/pi/poolboy:
#!/bin/bash
cd "$(dirname "$0")"
VENV=venv
echo 'checking for ' $VENV
if [ ! -d $VENV ]
then
echo $VENV ' does not exist... initially creating it'
python3 -m venv $VENV
echo 'activating the virtual environment'
source venv/bin/activate
echo 'installing libraries from requirements.txt'
pip3 install -r requirements.txt
else
source $VENV/bin/activate
fi
echo 'starting...'
sudo $VENV/bin/python3 poolboy.py --standalone
After running the enable script I run the start script. I get the following output in my /var/log/syslog:
Jun 19 22:10:43 poolboy systemd[1]: Started Pool Boy.
Jun 19 22:10:43 poolboy systemd[1]: poolBoy.service: Main process exited, code=exited, status=200/CHDIR
Jun 19 22:10:43 poolboy systemd[1]: poolBoy.service: Failed with result 'exit-code'.
Jun 19 22:10:43 poolboy systemd[1]: poolBoy.service: Service RestartSec=100ms expired, scheduling restart.
Jun 19 22:10:43 poolboy systemd[1]: poolBoy.service: Scheduled restart job, restart counter is at 1.
Jun 19 22:10:43 poolboy systemd[1]: Stopped Pool Boy.
Jun 19 22:10:43 poolboy systemd[1]: Started Pool Boy.
Jun 19 22:10:43 poolboy systemd[4980]: poolBoy.service: Changing to the requested working directory failed: No such file or directory
Jun 19 22:10:43 poolboy systemd[4980]: poolBoy.service: Failed at step CHDIR spawning /usr/bin/python3: No such file or directory
Jun 19 22:10:43 poolboy systemd[1]: poolBoy.service: Main process exited, code=exited, status=200/CHDIR
Jun 19 22:10:43 poolboy systemd[1]: poolBoy.service: Failed with result 'exit-code'.
Jun 19 22:10:43 poolboy systemd[1]: poolBoy.service: Service RestartSec=100ms expired, scheduling restart.
Jun 19 22:10:43 poolboy systemd[1]: poolBoy.service: Scheduled restart job, restart counter is at 2.
Jun 19 22:10:43 poolboy systemd[1]: Stopped Pool Boy.
Jun 19 22:10:43 poolboy systemd[1]: Started Pool Boy.
Jun 19 22:10:43 poolboy systemd[4981]: poolBoy.service: Changing to the requested working directory failed: No such file or directory
Jun 19 22:10:43 poolboy systemd[4981]: poolBoy.service: Failed at step CHDIR spawning /usr/bin/python3: No such file or directory
Jun 19 22:10:43 poolboy systemd[1]: poolBoy.service: Main process exited, code=exited, status=200/CHDIR
Jun 19 22:10:43 poolboy systemd[1]: poolBoy.service: Failed with result 'exit-code'.
Jun 19 22:10:44 poolboy systemd[1]: poolBoy.service: Service RestartSec=100ms expired, scheduling restart.
Jun 19 22:10:44 poolboy systemd[1]: poolBoy.service: Scheduled restart job, restart counter is at 3.
Jun 19 22:10:44 poolboy systemd[1]: Stopped Pool Boy.
Jun 19 22:10:44 poolboy systemd[1]: Started Pool Boy.
Jun 19 22:10:44 poolboy systemd[4982]: poolBoy.service: Changing to the requested working directory failed: No such file or directory
Jun 19 22:10:44 poolboy systemd[4982]: poolBoy.service: Failed at step CHDIR spawning /usr/bin/python3: No such file or directory
Jun 19 22:10:44 poolboy systemd[1]: poolBoy.service: Main process exited, code=exited, status=200/CHDIR
Jun 19 22:10:44 poolboy systemd[1]: poolBoy.service: Failed with result 'exit-code'.
Jun 19 22:10:44 poolboy systemd[1]: poolBoy.service: Service RestartSec=100ms expired, scheduling restart.
Jun 19 22:10:44 poolboy systemd[1]: poolBoy.service: Scheduled restart job, restart counter is at 4.
Jun 19 22:10:44 poolboy systemd[1]: Stopped Pool Boy.
Jun 19 22:10:44 poolboy systemd[4984]: poolBoy.service: Changing to the requested working directory failed: No such file or directory
Jun 19 22:10:44 poolboy systemd[1]: Started Pool Boy.
Jun 19 22:10:44 poolboy systemd[4984]: poolBoy.service: Failed at step CHDIR spawning /usr/bin/python3: No such file or directory
Jun 19 22:10:44 poolboy systemd[1]: poolBoy.service: Main process exited, code=exited, status=200/CHDIR
Jun 19 22:10:44 poolboy systemd[1]: poolBoy.service: Failed with result 'exit-code'.
Jun 19 22:10:44 poolboy systemd[1]: poolBoy.service: Service RestartSec=100ms expired, scheduling restart.
Jun 19 22:10:44 poolboy systemd[1]: poolBoy.service: Scheduled restart job, restart counter is at 5.
Jun 19 22:10:44 poolboy systemd[1]: Stopped Pool Boy.
Jun 19 22:10:44 poolboy systemd[1]: poolBoy.service: Start request repeated too quickly.
Jun 19 22:10:44 poolboy systemd[1]: poolBoy.service: Failed with result 'exit-code'.
Jun 19 22:10:44 poolboy systemd[1]: Failed to start Pool Boy.
After replacing poolBoy with poolboy, it looks better, but the application is still not starting:
Jun 20 11:09:28 poolboy systemd[1]: Started Pool Boy.
Jun 20 11:09:28 poolboy start[1373]: checking for venv
Jun 20 11:09:28 poolboy start[1373]: starting...
Jun 20 11:09:28 poolboy systemd[1]: poolboy.service: Succeeded.
Jun 20 11:09:58 poolboy systemd[1]: poolboy.service: Service RestartSec=30s expired, scheduling restart.
Jun 20 11:09:58 poolboy systemd[1]: poolboy.service: Scheduled restart job, restart counter is at 12.
Jun 20 11:09:58 poolboy systemd[1]: Stopped Pool Boy.
Jun 20 11:09:58 poolboy systemd[1]: Started Pool Boy.
Jun 20 11:09:58 poolboy start[1447]: checking for venv
Jun 20 11:09:58 poolboy start[1447]: starting...
Jun 20 11:09:58 poolboy systemd[1]: poolboy.service: Succeeded.
Jun 20 11:10:28 poolboy systemd[1]: poolboy.service: Service RestartSec=30s expired, scheduling restart.
Jun 20 11:10:28 poolboy systemd[1]: poolboy.service: Scheduled restart job, restart counter is at 13.
Jun 20 11:10:28 poolboy systemd[1]: Stopped Pool Boy.
Jun 20 11:10:28 poolboy systemd[1]: Started Pool Boy.
Jun 20 11:10:28 poolboy start[1521]: checking for venv
Jun 20 11:10:28 poolboy start[1521]: starting...
Jun 20 11:10:28 poolboy systemd[1]: poolboy.service: Succeeded.
Jun 20 11:10:58 poolboy systemd[1]: poolboy.service: Service RestartSec=30s expired, scheduling restart.
Jun 20 11:10:58 poolboy systemd[1]: poolboy.service: Scheduled restart job, restart counter is at 14.
Jun 20 11:10:58 poolboy systemd[1]: Stopped Pool Boy.
Jun 20 11:10:58 poolboy systemd[1]: Started Pool Boy.
Jun 20 11:10:59 poolboy start[1595]: checking for venv
Jun 20 11:10:59 poolboy start[1595]: starting...
Jun 20 11:10:59 poolboy systemd[1]: poolboy.service: Succeeded.
Jun 20 11:11:01 poolboy kernel: [ 458.537483]
Jun 20 11:11:01 poolboy kernel: [ 458.537513] WARN::dwc_otg_hcd_urb_dequeue:639: Timed out waiting for FSM NP transfer to complete on 5
Jun 20 11:11:13 poolboy kernel: [ 470.441646]
Jun 20 11:11:13 poolboy kernel: [ 470.441682] WARN::dwc_otg_hcd_urb_dequeue:639: Timed out waiting for FSM NP transfer to complete on 5
Jun 20 11:11:29 poolboy systemd[1]: poolboy.service: Service RestartSec=30s expired, scheduling restart.
Jun 20 11:11:29 poolboy systemd[1]: poolboy.service: Scheduled restart job, restart counter is at 15.
Jun 20 11:11:29 poolboy systemd[1]: Stopped Pool Boy.
Jun 20 11:11:29 poolboy systemd[1]: Started Pool Boy.
Jun 20 11:11:29 poolboy start[1670]: checking for venv
Jun 20 11:11:29 poolboy start[1670]: starting...
Jun 20 11:11:29 poolboy systemd[1]: poolboy.service: Succeeded.
Any suggestions?
duh... my /home/pi/poolboy/start script had an & in the last line :-/
Now working with the above files

Trying to run Gunicorn on the server gives Error

from app import app as application
if __name__ == "__main__":
application.run(host='0.0.0.0')
Mar 31 10:48:52 guest gunicorn[115225]: raise HaltServer(reason, self.APP_LOAD_ERROR)
Mar 31 10:48:52 guest gunicorn[115225]: gunicorn.errors.HaltServer: <HaltServer 'App failed to load.' 4>
Mar 31 10:48:52 guest systemd[1]: app.service: Main process exited, code=exited, status=1/FAILURE
Mar 31 10:48:52 guest systemd[1]: app.service: Failed with result 'exit-code'.

How to auto-mount veracrypt device-hosted volume with systemd after login on Linux Mint?

I created /etc/systemd/system/veracrypt-automount-devices.service:
[Unit]
Description=VeraCrypt auto-mount device-hosted volumes
[Service]
Type=forking
ExecStartPre=/bin/sleep 300
ExecStart=/usr/bin/veracrypt --auto-mount=devices /media/veracrypt1
[Install]
WantedBy=multi-user.target
Then I did:
sudo systemctl daemon-reload
sudo systemctl enable veracrypt-automount-devices
sudo systemctl status veracrypt-automount-devices
● veracrypt-automount-devices.service - VeraCrypt auto-mount device-hosted volumes
Loaded: loaded (/etc/systemd/system/veracrypt-automount-devices.service; enabled; vendor preset: enabled)
Active: failed (Result: timeout) since Sat 2020-06-06 17:28:59 CEST; 8min ago
Process: 967 ExecStartPre=/bin/sleep 300 (code=killed, signal=TERM)
Jun 06 17:27:29 username-computername systemd[1]: Starting VeraCrypt auto-mount device-hosted volumes...
Jun 06 17:28:59 username-computername systemd[1]: veracrypt-automount-devices.service: Start-pre operation timed out. Terminating.
Jun 06 17:28:59 username-computername systemd[1]: veracrypt-automount-devices.service: Failed with result 'timeout'.
Jun 06 17:28:59 username-computername systemd[1]: Failed to start VeraCrypt auto-mount device-hosted volumes.
As you can see, it doesn't work.
If I grep syslog, here is what I find:
Jun 6 16:56:08 username-computername systemd[1]: veracrypt-automount-devices.service: Control process exited, code=exited status=1
Jun 6 16:56:08 username-computername veracrypt[969]: Enter password:
Jun 6 16:56:08 username-computername systemd[1]: veracrypt-automount-devices.service: Failed with result 'exit-code'.
Jun 6 17:28:59 username-computername systemd[1]: veracrypt-automount-devices.service: Start-pre operation timed out. Terminating.
Jun 6 17:28:59 username-computername systemd[1]: veracrypt-automount-devices.service: Failed with result 'timeout'.
Basically, what I want is to be asked for the password to decrypt the device-hosted volume after I logged in with my username and password in Linux Mint.
I found how to do it. I put the veracrypt command in ~/.profile to execute the program on login. See https://askubuntu.com/a/270050/787567.

Unable to start filebeat.error missing fileld

Below is my filebeat.yml file , I am unable to start service getting error
filebeat.prospectors:
- input_type: log
** paths:**
** - /opt/apache-tomcat-7.0.82/logs/*.log**
document_type: apache-access
fields_under_root: true
output.logstash:
** hosts: '${host}'**
host is environment variable i did export host="10.2.3.1:5044"
Apr 10 06:59:35 node1 filebeat[401]: Exiting: error initializing publisher: missing field accessing 'output.logstash.hosts' (source:'/etc/filebeat/filebeat.yml')
Apr 10 06:59:35 node1 systemd[1]: filebeat.service: main process exited, code=exited, status=1/FAILURE
Apr 10 06:59:35 node1 systemd[1]: Unit filebeat.service entered failed state.
Apr 10 06:59:35 node1 systemd[1]: filebeat.service failed.
Apr 10 06:59:35 node1 systemd[1]: filebeat.service holdoff time over, scheduling restart.
Apr 10 06:59:35 node1 systemd[1]: start request repeated too quickly for filebeat.service
Apr 10 06:59:35 node1 systemd[1]: Failed to start filebeat.
Apr 10 06:59:35 node1 systemd[1]: Unit filebeat.service entered failed state.
Apr 10 06:59:35 node1 systemd[1]: filebeat.service failed.``
I found solution, That's the issue is Systemd does not pass environment variables. I started filebeat as ./filebeat -e -c filebeat.yml it worked for me
By looking at this I see multiple syntax differences to your configuration. There are some examples at the bottom of the page even for hosts.
https://www.elastic.co/guide/en/beats/filebeat/1.2/using-environ-vars.html
Hope it helps.

Error starting Apache 2.4.6 on OpenSuse 13.1

When I try to start the apache this happens:
Job for apache2.service failed. See ‘systemctl status apache2.service’ and ‘journalctl -xn’ for details.
system.ctl status apache2.service -l returns me this:
Mar 24 23:41:57 glauber-pc.site start_apache2[3249]: httpd2-prefork: Syntax error on line 179 of /etc/apache2/httpd.conf: Syntax error on line 102 of /etc/apache2/default-server.conf: Syntax error on line 1 of /etc/apache2/conf.d/mod_evasive.conf: Cannot load /usr/lib64/apache2/mod_evasive20.so into server: /usr/lib64/apache2/mod_evasive20.so: cannot open shared object file: No such file or directory
Mar 24 23:41:57 glauber-pc.site systemd[1]: apache2.service: main process exited, code=exited, status=1/FAILURE
Mar 24 23:41:57 glauber-pc.site systemd[1]: Failed to start The Apache Webserver.
Mar 24 23:41:57 glauber-pc.site systemd[1]: Unit apache2.service entered failed state.
Everything seems right in those lines, any clue what it can be?
Change the first line in
/etc/apache2/conf.d/mod_evasive.conf
to
LoadModule evasive20_module /usr/lib64/apache2/mod_evasive24.so
(...24.so instead of ...20.so)

Resources