problems starting service that runs a bash script that in turn runs a python script - python-3.x

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

Related

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'.

Systemd does not activate service?

I need to leave a service on systemd running because it doesn't activate? For what reason this happens since I follow the recommendation of the documentation, below are the codes:
Code of the Service :
# Contents of /etc/systemd/system/quark.service
[Unit]
Description=Quark
After=network.target
[Service]
Type=simple
User=cto
ExecStart=/usr/local/bin/python3.9 /var/net/
Restart=always
[Install]
WantedBy=multi-user.target
Status Code :
● quark.service - Quark
Loaded: loaded (/etc/systemd/system/quark.service; enabled; vendor preset: en
Active: failed (Result: exit-code) since Mon 2021-06-21 15:20:34 UTC; 8s ago
Process: 1467 ExecStart=/usr/local/bin/python3.9 /var/net/ (code=exited, statu
Main PID: 1467 (code=exited, status=1/FAILURE)
Jun 21 15:20:34 webstrucs systemd[1]: quark.service: Main process exited, code=e
Jun 21 15:20:34 webstrucs systemd[1]: quark.service: Failed with result 'exit-co
Jun 21 15:20:34 webstrucs systemd[1]: quark.service: Service RestartSec=100ms ex
Jun 21 15:20:34 webstrucs systemd[1]: quark.service: Scheduled restart job, rest
Jun 21 15:20:34 webstrucs systemd[1]: Stopped Quark.
Jun 21 15:20:34 webstrucs systemd[1]: quark.service: Start request repeated too
Jun 21 15:20:34 webstrucs systemd[1]: quark.service: Failed with result 'exit-co
Jun 21 15:20:34 webstrucs systemd[1]: Failed to start Quark.
The ExecStart should be the command to be executed:
systemd manpages:
ExecStart=
Commands with their arguments that are executed when this service is started.
This stanza:
ExecStart=/usr/local/bin/python3.9 /var/net/
Should be:
ExecStart=/usr/local/bin/python3.9 path_to_python_script.py

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.

Taskserver fails to start on NixOS

I have a NixOS 17.03 server with the taskserver package. The taskserver service do not start anymore (it used to start, but I can't track the precise moment when it stopped working).
Here is the portion of my configuration.nix related to taskserver :
services.taskserver.enable = true;
services.taskserver.fqdn = config.networking.hostName;
services.taskserver.listenHost = config.networking.hostName;
services.taskserver.organisations.myorga.users = [ "henri" ];
Ande the error details :
systemctl status taskserver
● taskserver.service - Taskwarrior Server
Loaded: loaded (/nix/store/dy9rz3al85s6rxifrwqmm6sf3nsnb6wz-unit-taskserver.service/taskserver.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2017-05-27 19:52:27 CEST; 15min ago
Process: 5241 ExecStart=taskd server --ca.cert=/var/lib/taskserver/keys/ca.cert --ciphers= --client.allow= --client.deny= --confirmation=true --daemon=false --debug=false --extensions= --ip.log=false --log=- --queue.size=10 --request.limit=1048576 --server.cert=/var/lib/taskserver/keys/server.cert --server.crl=/var/lib/taskserver/keys/server.crl --server.key=/var/lib/taskserver/keys/server.key --server=myserver:53589 --trust=strict (code=exited, status=255)
Process: 5239 ExecStartPre=/nix/store/29h8k2nld3cwmvqiqml125jxm7ndl62j-unit-script/bin/taskserver-pre-start (code=exited, status=0/SUCCESS)
Main PID: 5241 (code=exited, status=255)
May 27 19:52:27 myserver systemd[1]: taskserver.service: Main process exited, code=exited, status=255/n/a
May 27 19:52:27 myserver systemd[1]: taskserver.service: Unit entered failed state.
May 27 19:52:27 myserver systemd[1]: taskserver.service: Failed with result 'exit-code'.
May 27 19:52:27 myserver systemd[1]: taskserver.service: Service hold-off time over, scheduling restart.
May 27 19:52:27 myserver systemd[1]: Stopped Taskwarrior Server.
May 27 19:52:27 myserver systemd[1]: taskserver.service: Start request repeated too quickly.
May 27 19:52:27 myserver systemd[1]: Failed to start Taskwarrior Server.
May 27 19:52:27 myserver systemd[1]: taskserver.service: Unit entered failed state.
May 27 19:52:27 myserver systemd[1]: taskserver.service: Failed with result 'exit-code'.
journalctl :
May 27 19:52:27 myserver systemd[1]: Starting Initialize CA for TaskServer...
May 27 19:52:27 myserver systemd[1]: Started Initialize CA for TaskServer.
May 27 19:52:27 myserver systemd[1]: Starting Taskwarrior Server...
May 27 19:52:27 myserver systemd[1]: Started Taskwarrior Server.
May 27 19:52:27 myserver taskd[5241]: ERROR: Could not read include file '/nix/store/8g6zs5xf1yvbkv8nzjgjqc3zgwjfy8a8-taskdrc'.
May 27 19:52:27 myserver systemd[1]: taskserver.service: Main process exited, code=exited, status=255/n/a
May 27 19:52:27 myserver systemd[1]: taskserver.service: Unit entered failed state.
May 27 19:52:27 myserver systemd[1]: taskserver.service: Failed with result 'exit-code'.
May 27 19:52:27 myserver systemd[1]: taskserver.service: Service hold-off time over, scheduling restart.
May 27 19:52:27 myserver systemd[1]: Stopped Taskwarrior Server.
May 27 19:52:27 myserver systemd[1]: taskserver-ca.service: Start request repeated too quickly.
May 27 19:52:27 myserver systemd[1]: Failed to start Initialize CA for TaskServer.
May 27 19:52:27 myserver systemd[1]: taskserver-ca.service: Unit entered failed state.
May 27 19:52:27 myserver systemd[1]: taskserver-ca.service: Failed with result 'start-limit-hit'.
May 27 19:52:27 myserver systemd[1]: taskserver.service: Start request repeated too quickly.
May 27 19:52:27 myserver systemd[1]: Failed to start Taskwarrior Server.
May 27 19:52:27 myserver systemd[1]: taskserver.service: Unit entered failed state.
May 27 19:52:27 myserver systemd[1]: taskserver.service: Failed with result 'exit-code'.
The /nix/store/8g6zs5xf1yvbkv8nzjgjqc3zgwjfy8a8-taskdrc does not exists indeed. I tried to clean the store, to update and rebuild the packages, and even to upgrade to nixos-unstable, to no avail.
Technical details
System: NixOS 17.03.1203.58e227052d (Gorilla)
Nix version: 1.11.8
Nixpkgs version: 17.03.1203.58e227052d
Sandboxing enabled: false
The latest 17.03 branch has no references to taskdrc, because that file was removed.
But, reading that commit we can see, that reference to taskdrc file is written to ${cfg.dataDir}/config file. So, most likely, you should remove that include /nix/store/...-tasdrc line from your config for service to start.
The reason, why you have experienced such a breakage is that Hydra (NixOS CI) doesn't assume currently, that NixOS is sometimes upgraded and such migrations should be tested too.

Deploy kubernetes cluster on Azure

I tried to create kubernetes cluster(v1.2.3) on azure with coreos cluster. I followed the documentation (http://kubernetes.io/docs/getting-started-guides/coreos/azure/)
Then I cloned the repo( git clone https://github.com/kubernetes/kubernetes). And I did a minor change in file( docs/getting-started-guides/coreos/azure/cloud_config_templates/kubernetes-cluster-main-nodes-template.yml) changed the kube version from v1.1.2 to v1.2.3.
And then I created the cluster by running the file(./create-kubernetes-cluster.js), cluster is successfully created for me. But in master node API server didn't get started..
I checked the log it was showing - Cloud provider could not be initialized: unknown cloud provider "vagrant".. I could not catch why this issue was coming..
This is my Log of -> kube-apiserver.service
-- Logs begin at Sat 2016-07-23 12:41:36 UTC, end at Sat 2016-07-23 12:44:19 UTC. --
Jul 23 12:43:06 anudemon-master-00 systemd[1]: Started Kubernetes API Server.
Jul 23 12:43:06 anudemon-master-00 kube-apiserver[1964]: I0723 12:43:06.299966 1964 server.go:188] Will report 172.16.0.4 as public IP address.
Jul 23 12:43:06 anudemon-master-00 kube-apiserver[1964]: F0723 12:43:06.300057 1964 server.go:211] Cloud provider could not be initialized: unknown cloud provider "vagrant"
Jul 23 12:43:06 anudemon-master-00 systemd[1]: kube-apiserver.service: Main process exited, code=exited, status=255/n/a
Jul 23 12:43:06 anudemon-master-00 systemd[1]: kube-apiserver.service: Unit entered failed state.
Jul 23 12:43:06 anudemon-master-00 systemd[1]: kube-apiserver.service: Failed with result 'exit-code'.
Jul 23 12:43:16 anudemon-master-00 systemd[1]: kube-apiserver.service: Service hold-off time over, scheduling restart.
Jul 23 12:43:16 anudemon-master-00 systemd[1]: Stopped Kubernetes API Server.
Jul 23 12:43:16 anudemon-master-00 kube-apiserver[2015]: I0723 12:43:16.428476 2015 server.go:188] Will report 172.16.0.4 as public IP address.
Jul 23 12:43:16 anudemon-master-00 kube-apiserver[2015]: F0723 12:43:16.428534 2015 server.go:211] Cloud provider could not be initialized: unknown cloud provider "vagrant"
Jul 23 12:43:16 anudemon-master-00 systemd[1]: Started Kubernetes API Server.
Jul 23 12:43:16 anudemon-master-00 systemd[1]: kube-apiserver.service: Main process exited, code=exited, status=255/n/a
Jul 23 12:43:16 anudemon-master-00 systemd[1]: kube-apiserver.service: Unit entered failed state.
Jul 23 12:43:16 anudemon-master-00 systemd[1]: kube-apiserver.service: Failed with result 'exit-code'.
Jul 23 12:43:26 anudemon-master-00 systemd[1]: kube-apiserver.service: Service hold-off time over, scheduling restart.
Jul 23 12:43:26 anudemon-master-00 systemd[1]: Stopped Kubernetes API Server.
Jul 23 12:43:26 anudemon-master-00 systemd[1]: Started Kubernetes API Server.
Jul 23 12:43:26 anudemon-master-00 kube-apiserver[2024]: I0723 12:43:26.756551 2024 server.go:188] Will report 172.16.0.4 as public IP address.
Jul 23 12:43:26 anudemon-master-00 kube-apiserver[2024]: F0723 12:43:26.756654 2024 server.go:211] Cloud provider could not be initialized: unknown cloud provider "vagrant"
Jul 23 12:43:26 anudemon-master-00 systemd[1]: kube-apiserver.service: Main process exited, code=exited, status=255/n/a
Jul 23 12:43:26 anudemon-master-00 systemd[1]: kube-apiserver.service: Unit entered failed state.
Jul 23 12:43:26 anudemon-master-00 systemd[1]: kube-apiserver.service: Failed with result 'exit-code'.
Jul 23 12:43:36 anudemon-master-00 systemd[1]: kube-apiserver.service: Service hold-off time over, scheduling restart.
Jul 23 12:43:36 anudemon-master-00 systemd[1]: Stopped Kubernetes API Server.
Jul 23 12:43:36 anudemon-master-00 systemd[1]: Started Kubernetes API Server.
Jul 23 12:43:36 anudemon-master-00 kube-apiserver[2039]: I0723 12:43:36.872849 2039 server.go:188] Will report 172.16.0.4 as public IP address.
Have you had a look at kuberenetes-anywhere (https://github.com/kubernetes/kubernetes-anywhere)? Much work has been done there and now probably has all the right bits to deploy out your cluster with Azure specific cloud provider integrations.

Resources