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.
reza
  • 1
  • 1

2 Answers2

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.

Bill McGonigle
  • 667
  • 5
  • 8
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.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • thank you I used your code but it won't start and gives the error below: – reza Nov 24 '15 at 09: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 '15 at 09:34
  • How can I use python interpreter inside this code? – reza Nov 24 '15 at 09: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 '15 at 09:36
  • It should start with something like `#!/usr/bin/python2.7` See the [documentation](https://docs.python.org/2/using/unix.html#miscellaneous). – Michael Hampton Nov 24 '15 at 09:49
  • I added the above line at the top of my server.py file and restarted the server but it gives the error : (code=exited, status=203/EXEC) – reza Nov 24 '15 at 09:52
  • any idea? this is so important for me. – reza Nov 24 '15 at 10:12
  • What do the logs say? – GregL Nov 24 '15 at 12:53
  • 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 '15 at 16:51