0

Edited!!!!

I used this unit file and here is the output but it won't create any log files.

[Unit]
Description=PY-KMS
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/py-kms-master/server.py 192.168.1.100 1688 -v
StandardOutput=/usr/local/py-kms-master/kms.log
StandardError=/usr/local/py-kms-master/kms-error.log


[Install]
WantedBy=multi-user.target

Status:

[root@static ~]# systemctl status pykms -l
pykms.service - PY-KMS
   Loaded: loaded (/etc/systemd/system/pykms.service; enabled)
   Active: active (running) since Tue 2015-11-24 20:26:44 IRST; 3s ago
 Main PID: 2705 (server.py)
   CGroup: /system.slice/pykms.service
           └─2705 /usr/bin/python2.7 /usr/local/py-kms-master/server.py 192.168.1.100 1688 -v

Nov 24 20:26:44 static.clients.your-server.de systemd[1]: Starting PY-KMS...
Nov 24 20:26:44 static.clients.your-server.de systemd[1]: Started PY-KMS.

2 Answers 2

0

First, it's not necessary (and looks very bad) to use a shell script to start up a process in a systemd unit. Nor is it necessary to call a Python interpreter explicitly, if your Python script has the correct line at the top of it.

Start by cleaning up the unit file:

[Service]
#...
ExecStart=/usr/local/py-kms-master/server.py 192.168.1.100 1688 -v
StandardOutput=/usr/local/py-kms-master/kms.log
StandardError= (whatever you want)

Second, look in the correct file. Your service is logging to kms.log but you have been looking at kms-server.txt. Either look at the other file, or change the destination.

9
  • thank you I used your code but it won't start and gives the error below:
    – reza
    Nov 24, 2015 at 9:32
  • Loaded: loaded (/etc/systemd/system/pykms.service; enabled) Active: failed (Result: exit-code) since Tue 2015-11-24 13:00:56 IRST; 1min 27s ago pykms.service: main process exited, code=exited, status=203/EXEC Nov 24 13:00:56 static.27.79.47.78.clients.your-server.de systemd[1]: Unit pykms.service entered failed state.
    – reza
    Nov 24, 2015 at 9:34
  • How can I use python interpreter inside this code?
    – reza
    Nov 24, 2015 at 9:35
  • my python script (server.py) has these lines at the top of it:import argparse import binascii import hashlib import random import socket import SocketServer import struct import uuid import rpcBind, rpcRequest from dcerpc import MSRPCHeader from rpcBase import rpcBase
    – reza
    Nov 24, 2015 at 9:36
  • 1
    @GregL the script works now but it won't create log files. there is no errors too. I used simple service type and also tried oneshot and forking but no luck
    – reza
    Nov 24, 2015 at 16:51
0

Try (overwrite):

StandardOutput=file:/usr/local/py-kms-master/kms.log
StandardError=file:/usr/local/py-kms-master/kms-error.log

or (append)

StandardOutput=append:/usr/local/py-kms-master/kms.log
StandardError=append:/usr/local/py-kms-master/kms-error.log

if you have systemd > 240 and, since it's a python script, set the -u flag, or set:

Environment="PYTHONUNBUFFERED=1"

in the unit file so that python doesn't buffer its output for a long time before flushing it to systemd to log.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .