How to setup a systemd service with root access?
up vote
1
down vote
favorite
Description
I am trying to make a systemd service file to run a python script to print something using thermal printer. escpos is the library I am using to access the control of thermal printer. However escpos require sudo to access the usb device.
Question
How to make a systemd service file such that the exec command get the root access? Base on some answer on internet, if I don't set anything to User, the default exec should get root access automatically. But I still getting trouble to make my program run. Hope anyone can help me to spot my mistake.
Code
python
File: /usr/local/etc/test/testPrint.py
from escpos.printer import Usb
#require escpos use "pip install python-escpos" to install the library
""" Seiko Epson Corp. Receipt Printer (EPSON TM-T88III) """
p = Usb(0x4b43, 0x3538, 0, 0x82, 0x02)
p.text("Hello Worldn")
p.text("nnn")
p.cut()
I can run sudo python3 /usr/local/etc/test/testPrint.py
and print the text from the thermal printer without any problem.
Service File
File: /etc/systemd/system/testPrint.service
[Unit]
Description=Test Python escpos print
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/python3 /usr/local/etc/test/testPrint.py
[Install]
WantedBy=multi-user.target
And when I try to run the command sudo systemctl start testPrint.service
. It gives error
Error log
Command: sudo journalctl -u testPrint.service
:
python3.5[27149]: Traceback (most recent call last):
python3.5[27149]: File "/usr/local/etc/test/testPrint.py",
python3.5[27149]: from escpos.printer import Usb
python3.5[27149]: ImportError: No module named 'escpos'
systemd[1]: testPrint.service: Main process exited, code=exit
systemd[1]: Failed to start Test python escpos print.
systemd[1]: testPrint.service: Unit entered failed state.
systemd[1]: testPrint.service: Failed with result 'exit-code'
Which is the same error, if I run python without sudo "python3 printTest.py"
Edit:
Just to give out some extra info. I use sudo pip3 install python-escpos to install the module.
My OS is Ubuntu 16.04
python sudo systemd services
add a comment |
up vote
1
down vote
favorite
Description
I am trying to make a systemd service file to run a python script to print something using thermal printer. escpos is the library I am using to access the control of thermal printer. However escpos require sudo to access the usb device.
Question
How to make a systemd service file such that the exec command get the root access? Base on some answer on internet, if I don't set anything to User, the default exec should get root access automatically. But I still getting trouble to make my program run. Hope anyone can help me to spot my mistake.
Code
python
File: /usr/local/etc/test/testPrint.py
from escpos.printer import Usb
#require escpos use "pip install python-escpos" to install the library
""" Seiko Epson Corp. Receipt Printer (EPSON TM-T88III) """
p = Usb(0x4b43, 0x3538, 0, 0x82, 0x02)
p.text("Hello Worldn")
p.text("nnn")
p.cut()
I can run sudo python3 /usr/local/etc/test/testPrint.py
and print the text from the thermal printer without any problem.
Service File
File: /etc/systemd/system/testPrint.service
[Unit]
Description=Test Python escpos print
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/python3 /usr/local/etc/test/testPrint.py
[Install]
WantedBy=multi-user.target
And when I try to run the command sudo systemctl start testPrint.service
. It gives error
Error log
Command: sudo journalctl -u testPrint.service
:
python3.5[27149]: Traceback (most recent call last):
python3.5[27149]: File "/usr/local/etc/test/testPrint.py",
python3.5[27149]: from escpos.printer import Usb
python3.5[27149]: ImportError: No module named 'escpos'
systemd[1]: testPrint.service: Main process exited, code=exit
systemd[1]: Failed to start Test python escpos print.
systemd[1]: testPrint.service: Unit entered failed state.
systemd[1]: testPrint.service: Failed with result 'exit-code'
Which is the same error, if I run python without sudo "python3 printTest.py"
Edit:
Just to give out some extra info. I use sudo pip3 install python-escpos to install the module.
My OS is Ubuntu 16.04
python sudo systemd services
2
How did you installescpos
?sudo pip3 install escpos
orpip3 install escpos
? Or was this in a virtualenv you used for escpos? Because you need the module installed systemwide withsudo pip3 install
for it to be able to useescpos
.
– Thomas Ward♦
Nov 19 at 14:16
I use sudo pip3 install python-escpos to install the library
– Wan Chap
Nov 19 at 17:26
2
Welcome to Ask Ubuntu! Please don’t put the solution into the question. Use the answer field below instead. askubuntu.com/help/self-answer Also don’t add “SOLVED” to the title. In order to mark your question solved in the right way, you may accept the answer (by clicking on the tick mark (✓) next to it) that helped you. In case the helpful answer was posted by you, you'll have to wait 2 days before being able to accept it.
– Melebius
Nov 22 at 9:12
Thanks for the tips, I am still learning to be a part of AskUbuntu community.
– Wan Chap
Nov 22 at 10:01
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Description
I am trying to make a systemd service file to run a python script to print something using thermal printer. escpos is the library I am using to access the control of thermal printer. However escpos require sudo to access the usb device.
Question
How to make a systemd service file such that the exec command get the root access? Base on some answer on internet, if I don't set anything to User, the default exec should get root access automatically. But I still getting trouble to make my program run. Hope anyone can help me to spot my mistake.
Code
python
File: /usr/local/etc/test/testPrint.py
from escpos.printer import Usb
#require escpos use "pip install python-escpos" to install the library
""" Seiko Epson Corp. Receipt Printer (EPSON TM-T88III) """
p = Usb(0x4b43, 0x3538, 0, 0x82, 0x02)
p.text("Hello Worldn")
p.text("nnn")
p.cut()
I can run sudo python3 /usr/local/etc/test/testPrint.py
and print the text from the thermal printer without any problem.
Service File
File: /etc/systemd/system/testPrint.service
[Unit]
Description=Test Python escpos print
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/python3 /usr/local/etc/test/testPrint.py
[Install]
WantedBy=multi-user.target
And when I try to run the command sudo systemctl start testPrint.service
. It gives error
Error log
Command: sudo journalctl -u testPrint.service
:
python3.5[27149]: Traceback (most recent call last):
python3.5[27149]: File "/usr/local/etc/test/testPrint.py",
python3.5[27149]: from escpos.printer import Usb
python3.5[27149]: ImportError: No module named 'escpos'
systemd[1]: testPrint.service: Main process exited, code=exit
systemd[1]: Failed to start Test python escpos print.
systemd[1]: testPrint.service: Unit entered failed state.
systemd[1]: testPrint.service: Failed with result 'exit-code'
Which is the same error, if I run python without sudo "python3 printTest.py"
Edit:
Just to give out some extra info. I use sudo pip3 install python-escpos to install the module.
My OS is Ubuntu 16.04
python sudo systemd services
Description
I am trying to make a systemd service file to run a python script to print something using thermal printer. escpos is the library I am using to access the control of thermal printer. However escpos require sudo to access the usb device.
Question
How to make a systemd service file such that the exec command get the root access? Base on some answer on internet, if I don't set anything to User, the default exec should get root access automatically. But I still getting trouble to make my program run. Hope anyone can help me to spot my mistake.
Code
python
File: /usr/local/etc/test/testPrint.py
from escpos.printer import Usb
#require escpos use "pip install python-escpos" to install the library
""" Seiko Epson Corp. Receipt Printer (EPSON TM-T88III) """
p = Usb(0x4b43, 0x3538, 0, 0x82, 0x02)
p.text("Hello Worldn")
p.text("nnn")
p.cut()
I can run sudo python3 /usr/local/etc/test/testPrint.py
and print the text from the thermal printer without any problem.
Service File
File: /etc/systemd/system/testPrint.service
[Unit]
Description=Test Python escpos print
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/python3 /usr/local/etc/test/testPrint.py
[Install]
WantedBy=multi-user.target
And when I try to run the command sudo systemctl start testPrint.service
. It gives error
Error log
Command: sudo journalctl -u testPrint.service
:
python3.5[27149]: Traceback (most recent call last):
python3.5[27149]: File "/usr/local/etc/test/testPrint.py",
python3.5[27149]: from escpos.printer import Usb
python3.5[27149]: ImportError: No module named 'escpos'
systemd[1]: testPrint.service: Main process exited, code=exit
systemd[1]: Failed to start Test python escpos print.
systemd[1]: testPrint.service: Unit entered failed state.
systemd[1]: testPrint.service: Failed with result 'exit-code'
Which is the same error, if I run python without sudo "python3 printTest.py"
Edit:
Just to give out some extra info. I use sudo pip3 install python-escpos to install the module.
My OS is Ubuntu 16.04
python sudo systemd services
python sudo systemd services
edited Nov 22 at 9:59
asked Nov 19 at 14:10
Wan Chap
112
112
2
How did you installescpos
?sudo pip3 install escpos
orpip3 install escpos
? Or was this in a virtualenv you used for escpos? Because you need the module installed systemwide withsudo pip3 install
for it to be able to useescpos
.
– Thomas Ward♦
Nov 19 at 14:16
I use sudo pip3 install python-escpos to install the library
– Wan Chap
Nov 19 at 17:26
2
Welcome to Ask Ubuntu! Please don’t put the solution into the question. Use the answer field below instead. askubuntu.com/help/self-answer Also don’t add “SOLVED” to the title. In order to mark your question solved in the right way, you may accept the answer (by clicking on the tick mark (✓) next to it) that helped you. In case the helpful answer was posted by you, you'll have to wait 2 days before being able to accept it.
– Melebius
Nov 22 at 9:12
Thanks for the tips, I am still learning to be a part of AskUbuntu community.
– Wan Chap
Nov 22 at 10:01
add a comment |
2
How did you installescpos
?sudo pip3 install escpos
orpip3 install escpos
? Or was this in a virtualenv you used for escpos? Because you need the module installed systemwide withsudo pip3 install
for it to be able to useescpos
.
– Thomas Ward♦
Nov 19 at 14:16
I use sudo pip3 install python-escpos to install the library
– Wan Chap
Nov 19 at 17:26
2
Welcome to Ask Ubuntu! Please don’t put the solution into the question. Use the answer field below instead. askubuntu.com/help/self-answer Also don’t add “SOLVED” to the title. In order to mark your question solved in the right way, you may accept the answer (by clicking on the tick mark (✓) next to it) that helped you. In case the helpful answer was posted by you, you'll have to wait 2 days before being able to accept it.
– Melebius
Nov 22 at 9:12
Thanks for the tips, I am still learning to be a part of AskUbuntu community.
– Wan Chap
Nov 22 at 10:01
2
2
How did you install
escpos
? sudo pip3 install escpos
or pip3 install escpos
? Or was this in a virtualenv you used for escpos? Because you need the module installed systemwide with sudo pip3 install
for it to be able to use escpos
.– Thomas Ward♦
Nov 19 at 14:16
How did you install
escpos
? sudo pip3 install escpos
or pip3 install escpos
? Or was this in a virtualenv you used for escpos? Because you need the module installed systemwide with sudo pip3 install
for it to be able to use escpos
.– Thomas Ward♦
Nov 19 at 14:16
I use sudo pip3 install python-escpos to install the library
– Wan Chap
Nov 19 at 17:26
I use sudo pip3 install python-escpos to install the library
– Wan Chap
Nov 19 at 17:26
2
2
Welcome to Ask Ubuntu! Please don’t put the solution into the question. Use the answer field below instead. askubuntu.com/help/self-answer Also don’t add “SOLVED” to the title. In order to mark your question solved in the right way, you may accept the answer (by clicking on the tick mark (✓) next to it) that helped you. In case the helpful answer was posted by you, you'll have to wait 2 days before being able to accept it.
– Melebius
Nov 22 at 9:12
Welcome to Ask Ubuntu! Please don’t put the solution into the question. Use the answer field below instead. askubuntu.com/help/self-answer Also don’t add “SOLVED” to the title. In order to mark your question solved in the right way, you may accept the answer (by clicking on the tick mark (✓) next to it) that helped you. In case the helpful answer was posted by you, you'll have to wait 2 days before being able to accept it.
– Melebius
Nov 22 at 9:12
Thanks for the tips, I am still learning to be a part of AskUbuntu community.
– Wan Chap
Nov 22 at 10:01
Thanks for the tips, I am still learning to be a part of AskUbuntu community.
– Wan Chap
Nov 22 at 10:01
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I have solved the problem.
This bug is not caused by root permission, but rather the escpos module are not install correctly under root user. After I reinstall the escpos by sudo pip3 install python-escpos
all codes work accordingly and is able to print the text.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I have solved the problem.
This bug is not caused by root permission, but rather the escpos module are not install correctly under root user. After I reinstall the escpos by sudo pip3 install python-escpos
all codes work accordingly and is able to print the text.
add a comment |
up vote
0
down vote
I have solved the problem.
This bug is not caused by root permission, but rather the escpos module are not install correctly under root user. After I reinstall the escpos by sudo pip3 install python-escpos
all codes work accordingly and is able to print the text.
add a comment |
up vote
0
down vote
up vote
0
down vote
I have solved the problem.
This bug is not caused by root permission, but rather the escpos module are not install correctly under root user. After I reinstall the escpos by sudo pip3 install python-escpos
all codes work accordingly and is able to print the text.
I have solved the problem.
This bug is not caused by root permission, but rather the escpos module are not install correctly under root user. After I reinstall the escpos by sudo pip3 install python-escpos
all codes work accordingly and is able to print the text.
answered Nov 22 at 9:58
Wan Chap
112
112
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1094225%2fhow-to-setup-a-systemd-service-with-root-access%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
How did you install
escpos
?sudo pip3 install escpos
orpip3 install escpos
? Or was this in a virtualenv you used for escpos? Because you need the module installed systemwide withsudo pip3 install
for it to be able to useescpos
.– Thomas Ward♦
Nov 19 at 14:16
I use sudo pip3 install python-escpos to install the library
– Wan Chap
Nov 19 at 17:26
2
Welcome to Ask Ubuntu! Please don’t put the solution into the question. Use the answer field below instead. askubuntu.com/help/self-answer Also don’t add “SOLVED” to the title. In order to mark your question solved in the right way, you may accept the answer (by clicking on the tick mark (✓) next to it) that helped you. In case the helpful answer was posted by you, you'll have to wait 2 days before being able to accept it.
– Melebius
Nov 22 at 9:12
Thanks for the tips, I am still learning to be a part of AskUbuntu community.
– Wan Chap
Nov 22 at 10:01