I am trying to start a bottle web app I wrote using systemd. I made the file /etc/systemd/user/bottle.service with the following contents:
[Unit]
Description=Bottled fax service
After=syslog.target
[Service]
Type=simple
User=fax
Group=fax
WorkingDirectory=/home/fax/bottlefax/
ExecStart=/usr/bin/env python3 server.py
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
[Install]
WantedBy=bottle.target
However, when I try to start it, it fails and this is printed in journalctl:
Jun 10 17:33:31 nano systemd[1]: Started Bottled fax service.
Jun 10 17:33:31 nano systemd[1]: Starting Bottled fax service...
Jun 10 17:33:31 nano systemd[2380]: Failed at step GROUP spawning /usr/bin/env: No such process
Jun 10 17:33:31 nano systemd[1]: bottle.service: main process exited, code=exited, status=216/GROUP
Jun 10 17:33:31 nano systemd[1]: Unit bottle.service entered failed state.
Jun 10 17:33:31 nano systemd[1]: bottle.service failed.
How should I fix this?
Edit:
Changing to /usr/bin/python3 as others have suggested results in the same error (changed file though):
Jun 10 18:43:48 nano systemd[1]: Started Bottled fax service.
Jun 10 18:43:48 nano systemd[1]: Starting Bottled fax service...
Jun 10 18:43:48 nano systemd[2579]: Failed at step GROUP spawning /usr/bin/python3: No such process
Jun 10 18:43:48 nano systemd[1]: bottle.service: main process exited, code=exited, status=216/GROUP
Jun 10 18:43:48 nano systemd[1]: Unit bottle.service entered failed state.
Jun 10 18:43:48 nano systemd[1]: bottle.service failed.
I would have commented but I can't :/
Have you tried something like with an absolute path ?
ExecStart=/usr/bin/python3 /path/to/your/server.py
That's the only issue I can see here.
Another possible cause of this error, is if you have created a system user by running adduser --system, and have not created the associated group.
Related
First of all, I am already running a similar Python flask web server on the machine.
I am following this tutorial in order to host a web server with Python Flask.
And in the 5th step (No problem so far), when i test with :
systemctl status myproject
I get
serveurB.service - uWSGI instance to serve serveurB
Loaded: loaded (/etc/systemd/system/serveurB.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2021-06-28 14:25:45 UTC; 1min 53s ago
Process: 7992 ExecStart=/home/sydney/serveurB/serveurB/bin/uwsgi --ini serveurB.ini
(code=exited, status=1/FAILURE)
Main PID: 7992 (code=exited, status=1/FAILURE)
Jun 28 14:25:45 ecocathlon uwsgi[7992]: detected binary path: /home/sydney/serveurB/serveurB/bin/uwsgi
Jun 28 14:25:45 ecocathlon uwsgi[7992]: !!! no internal routing support, rebuild with pcre support !!!
Jun 28 14:25:45 ecocathlon uwsgi[7992]: your processes number limit is 3789
Jun 28 14:25:45 ecocathlon uwsgi[7992]: your memory page size is 4096 bytes
Jun 28 14:25:45 ecocathlon uwsgi[7992]: detected max file descriptor number: 1024
Jun 28 14:25:45 ecocathlon uwsgi[7992]: lock engine: pthread robust mutexes
Jun 28 14:25:45 ecocathlon uwsgi[7992]: thunder lock: disabled (you can enable it with --thunder-lock)
Jun 28 14:25:45 ecocathlon uwsgi[7992]: bind(): Permission denied [core/socket.c line 230]
Jun 28 14:25:45 ecocathlon systemd[1]: serveurB.service: Main process exited, code=exited, status=1/FAILURE
Jun 28 14:25:45 ecocathlon systemd[1]: serveurB.service: Failed with result 'exit-code'.
In which
myproject = serveurB
myprojectenv = serveurB (yes same name, i misstyped that one but i don't think it is the issue)
user = sydney
All my previous steps and files seem correct.
Thanks in advance,
Sydney R.
They key line in the error message is this one:
Jun 28 14:25:45 ecocathlon uwsgi[7992]: bind(): Permission denied [core/socket.c line 230]
bind is the method that will "bind" your socket to a port for listening and you are receiving a "Permission denied" error. That means you are using a low number port (< 1024) and are not root.
I would recommend changing the port to something higher than 1024 since running an app as root can be dangerous. There are other solutions as well but they are out of scope for this answer.
You have to be careful about the naming when setting up your project on digital ocean. The best way to make sure you not getting any naming error just make the project name consistent from the project and when setting up your server as well. For this I would suggest that you double check your nguni service file and see if you actually referenced your uWSGI project.
I have listed below the steps as I entered them. I cannot get the Pi (Raspbian GNU/Linux Buster (10)) to launch alarm.service after startup. When I log into the Pi and launch alarm.service manually from the GUI it works, as does the script it runs -- (The script is written to loop) Only problem is I can't get alarm.service to launch automatically without the GUI. Be great to have it launch last after all other services are up and running.
1. sudo nano /home/pi/alarm_service.py - (fyi: this script runs nicely when i launch it manually from command prompt after pi has booted and i am logged in)
2. sudo nano /etc/systemd/system/alarm.service
[Unit]
Description=Alarm Service
After=multi-user.target
Conflicts=getty#tty1.service
[Service]
Type=simple
ExecStart=/home/pi/alarm_service.py
StandardInput=tty-force
[Install]
WantedBy=multi-user.target
3. sudo chmod 644 /etc/systemd/system/alarm.service
4. sudo systemctl daemon-reload
5. sudo systemctl enable alarm.service
6. sudo systemctl start alarm.service
Error log:
alarm.service - Alarm service Loaded: loaded (/etc/systemd/system/alarm.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Fri 2021-05-14 18:57:24 AEST; 1min 18s ago Process: 501 ExecStart=/home/pi/alarm_service.py (code=exited, status=1/FAILURE) Main PID: 501 (code=exited, status=1/FAILURE)
May 14 18:57:24 raspberrypi alarm_service.py[501]: File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 10 May 14 18:57:24 raspberrypi alarm_service.py[501]: sock = self._create_socket_connection() May 14 18:57:24 raspberrypi alarm_service.py[501]: File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 35 May 14 18:57:24 raspberrypi alarm_service.py[501]: return socket.create_connection(addr, source_address=source, timeout=sel May 14 18:57:24 raspberrypi alarm_service.py[501]: File "/usr/lib/python2.7/socket.py", line 575, in create_connection May 14 18:57:24 raspberrypi alarm_service.py[501]: raise err May 14 18:57:24 raspberrypi alarm_service.py[501]: socket.error: [Errno 101] Network is unreachable May 14 18:57:24 raspberrypi systemd[1]: alarm.service: Main process exited, code=exited, status=1/FAILURE May 14 18:57:24 raspberrypi systemd[1]: alarm.service: Failed with result 'exit-code'. May 14 18:57:24 raspberrypi systemd[1]: Failed to start Alarm service.
The principle I follow is to make the environment that systemd creates for the script to run as similar to what I use to develop it as possible.
For the sake of testing I just ran shutdown -r now on a VM where I do this exact thing. On boot, voila.
$ systemctl status mypython
● mypython.service
Loaded: ...etc.
The file I have set is
less /etc/systemd/system/multi-user.target.wants/mypython.service
Content
[Unit]
Description=mypython
[Service]
WorkingDirectory=/home/me
ExecStart=/usr/bin/python3 /home/me/mypython.py ./config.yaml
Restart=always
RestartSec=5
User=me
Group=me
[Install]
WantedBy=multi-user.target
Hi I recently bought a Raspberry Pi 4
I am trying to program a discord bot for my server
Here is the error
pi#raspberrypi:~ $ sudo nano /lib/systemd/system/discordbot.service
pi#raspberrypi:~ $ sudo systemctl status discordbot.service
● discordbot.service - My Discord Bot Service
Loaded: loaded (/lib/systemd/system/discordbot.service; enabled; vendor preset: enabled)
Active: failed (Result: start-limit-hit) since Wed 2020-06-03 22:28:41 +08; 20min ago
Main PID: 856 (code=exited, status=0/SUCCESS)
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Service RestartSec=100ms expired, scheduling restart.
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Scheduled restart job, restart counter is at 5.
Jun 03 22:28:41 raspberrypi systemd[1]: Stopped My Discord Bot Service.
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Start request repeated too quickly.
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Failed with result 'start-limit-hit'.
Jun 03 22:28:41 raspberrypi systemd[1]: Failed to start My Discord Bot Service.
Here is the log to see my error
pi#raspberrypi:~ $ journalctl -e -u discordbot
Jun 03 22:28:41 raspberrypi systemd[1]: Started My Discord Bot Service.
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Succeeded.
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Service RestartSec=1
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Scheduled restart jo
Jun 03 22:28:41 raspberrypi systemd[1]: Stopped My Discord Bot Service.
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Start request repeat
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Failed with result '
Jun 03 22:28:41 raspberrypi systemd[1]: Failed to start My Discord Bot Service.
[2]+ Stopped journalctl -e -u discordbot
Here is the code for the systemd
[Unit]
Description=My Discord Bot Service
After=network-online.target
[Service]
Type=idle
Restart=always
User=pi
ExecStart=/usr/bin/python3 /home/pi/discordbot/discordbot.py
[Install]
WantedBy=multi-user.target
I have tried to find solutions for hours but none helped
All help is appreciated :)
I'm trying to run a python discord bot when my Raspberry Pi starts up. To do this, I've used a systemd service:
[Unit]
Description=Testing
[Service]
Type=idle
WorkingDirectory=/home/pi
ExecStart=/usr/bin/python3 /home/pi/discord/bug.py
[Install]
WantedBy=multi-user.target
I have done several test using simpler python programs before, and it all works fine. When trying to run the discord bot, it throws an error at the import statement. For testing I run:
sudo systemctl start bugstart
sudo systemctl status bugstart
The output of the status is the following:
bugstart.service - Testing
Loaded: loaded (/lib/systemd/system/bugstart.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2018-08-12 02:08:47 UTC; 1s ago
Process: 1039 ExecStart=/usr/bin/python3 /home/pi/discord/bug.py (code=exited, status=1/FAILURE)
Main PID: 1039 (code=exited, status=1/FAILURE)
Aug 12 02:08:46 raspberrypi systemd[1]: Started Testing.
Aug 12 02:08:47 raspberrypi python3[1039]: Traceback (most recent call last):
Aug 12 02:08:47 raspberrypi python3[1039]: File "/home/pi/discord/bug.py", line 1, in <module>
Aug 12 02:08:47 raspberrypi python3[1039]: import discord
Aug 12 02:08:47 raspberrypi python3[1039]: ImportError: No module named 'discord'
Aug 12 02:08:47 raspberrypi systemd[1]: bugstart.service: Main process exited, code=exited, status=1/FAILURE
Aug 12 02:08:47 raspberrypi systemd[1]: bugstart.service: Unit entered failed state.
Aug 12 02:08:47 raspberrypi systemd[1]: bugstart.service: Failed with result 'exit-code'.
I found out that the commands are run as root, so I figured it might be that the library hand't been installed on root, but I tried importing discord in the command line shell and it worked fine.
I am trying to execute a python3 with systemd in a ubuntu 16.
Following are the configs
[Unit]
Description=email notification server
After=multi-user.target
[Service]
WorkingDirectory=/home/ubuntu/email-noti
Restart=on-failure
ExecStart=/usr/lib/python3 /home/ubuntu/email-noti/email_reader.py
[Install]
WantedBy=multi-user.target
*please note that email_reader.py import a config file and few python3 files from /home/ubuntu/email-noti/
but it always end with following error
● email-noti.service - email notification server
Loaded: loaded (/etc/systemd/system/email-noti.service; enabled; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Tue 2017-03-07 18:00:38 UTC; 6s ago
Process: 11859 ExecStart=/usr/lib/python3 /home/ubuntu/email-noti/email_reader.py (code=exited, status=203/EXEC)
Main PID: 11859 (code=exited, status=203/EXEC)
Mar 07 18:00:38 ip-172-31-24-115 systemd[1]: email-noti.service: Service hold-off time over, scheduling restart.
Mar 07 18:00:38 ip-172-31-24-115 systemd[1]: Stopped email notification server.
Mar 07 18:00:38 ip-172-31-24-115 systemd[1]: email-noti.service: Start request repeated too quickly.
Mar 07 18:00:38 ip-172-31-24-115 systemd[1]: Failed to start email notification server.
but when i manually execute the email_reader.py works totally fine.
Any help appreciated