From 88c8b6493aea1549d71be0345295beb6c4e61c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sat, 15 Oct 2016 22:19:59 +0200 Subject: Some user services changes --- local/sbin/syncemail | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'local/sbin/syncemail') diff --git a/local/sbin/syncemail b/local/sbin/syncemail index d0ea682..dfd56a3 100755 --- a/local/sbin/syncemail +++ b/local/sbin/syncemail @@ -7,8 +7,17 @@ import daemon import lockfile from offlineimap import OfflineImap -if os.path.isfile('/home/cynerd/.run/syncemail.pid.lock'): - sys.exit(0) +pidfile = '/tmp/syncemail-%d.pid' % os.getuid() + +# Check if not already running +def check_running(): + if os.access(pidfile, os.F_OK): + with open(pidfile, "r") as f: + pid = f.readline() + if os.path.exists('/proc/%s' % pid): + sys.exit(0) +check_running() + accounts = [ ["email", "mail/cynerd@email.cz"], @@ -25,8 +34,11 @@ for acc in accounts: sys.argv.append('Repository_' + acc[0] + '-remote:remotepass=' + output) sys.argv.append('-s') # output to syslog +sys.argv.append('-u') +sys.argv.append('syslog') -with daemon.DaemonContext( - pidfile=lockfile.FileLock('/home/cynerd/.run/syncemail.pid') - ): +with daemon.DaemonContext(): + check_running() + with open(pidfile, "w") as f: + f.write("%s" % os.getpid()) OfflineImap().run() -- cgit v1.2.3