私はUbuntuでサービスを作成しようとしていますが、エラーが発生しています。linux(Ubuntu)のsystemdサービスでエラーが発生しました
私はFileSystemWatcher.py
import requests
import json
import logging
import sys
import os
import datetime
from watchdog.events import PatternMatchingEventHandler
class DirectoryChangedHandler(PatternMatchingEventHandler):
patterns = ["*.json","*.csv"]
logFileName = datetime.datetime.now().strftime('%Y%m%d_log.log')
script_dir = os.path.dirname(__file__) # <-- absolute dir the script is in
rel_path = "log/"+logFileName
abs_logfile_path = os.path.join(script_dir, rel_path)
appConfigFilePath = os.path.abspath('config/app_config.json')
with open(appConfigFilePath) as data_file:
config = json.load(data_file)
logging.basicConfig(filename=abs_logfile_path, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.NOTSET)
def process(self, event):
print event.src_path, event.event_type
try:
filelist = [('files', open(event.src_path, 'rb'))]
postUrl = self.config["apiBaseUrl"].encode('utf-8')+self.config["fileUplaodApiUrl"].encode('utf-8')
uploadResponse = requests.post(postUrl, files=filelist)
if uploadResponse.status_code == 200:
print "Upload Successful - ", event.src_path
else:
print "Upload Failed - ", event.src_path
except:
print "Unexpected error:", sys.exc_info()[0]
pass
def on_modified(self, event):
self.process(event)
def on_created(self, event):
self.process(event)
workflow.py-
#!/usr/bin/python2.7
import sys
import time
from watchdog.observers import Observer
import FileSystemWatcher as fSystemWatcher
if __name__ == '__main__':
args = sys.argv[1:]
observer = Observer()
observer.schedule(fSystemWatcher.DirectoryChangedHandler(), path=args[0] if args else '.', recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
と(/lib/systemd/system/FileWatcherSystemd.service)
[Unit]
Description=FileChangeService
[Service]
Type=forking
WorkingDirectory= /home/ashish/Documents/FileSystemWatcher
ExecStart= /home/ashish/Documents/FileSystemWatcher/workflow.py
Restart=on-failure
[Install]
WantedBy=multi-user.target
でコード -
下に書いたしかし、私は取得していますエラー -
FileWatcherSystemd.serviceを次 - FileChangeServiceがロード:( /lib/systemd/system/FileWatcherSystemd.serviceロード。有効にする。ベンダー プリセット:有効)アクティブ:非アクティブ(無効)(結果:終了コード)以来 水2017-07-19 10:44:39 IST; 8分前工程:6552 ExecStart = /ホーム/アシシュ/ドキュメント/ FileSystemWatcher/FileSystemWatcher.py (コード=終了し、ステータス= 203/EXEC)主PID:6552(コード=終了し、 ステータス= 203/EXEC)
Jul 19 10:44:39 Ashish-PC systemd [1]:FileWatcherSystemd.service:ユニット が失敗した状態になりました。 Jul 19 10:44:39 Ashish-PC systemd [1]: FileWatcherSystemd.service:結果 'exit-code'で失敗しました。 7月19 10:44:39 Ashish-PC systemd [1]:FileWatcherSystemd.service:サービス ホールドオフタイムオーバー、スケジューリング再開。 Jul 19 10:44:39 Ashish-PC systemd [1]:FileChangeServiceを停止しました。 Aug 19 10:44:39 Ashish-PC systemd [1]:FileWatcherSystemd.service:開始要求もすぐに繰り返されます 。 Jul 19 10:44:39 Ashish-PC systemd [1]:開始に失敗しました FileChangeService。
私はFileSytemWatcher.py
またはFileWatcherSystemd.service
ありがとう@Hannu。今私のサービスはType = simpleで動作しています –