diff options
author | Karel Kočí <cynerd@email.cz> | 2016-10-15 22:19:59 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2016-10-15 22:19:59 +0200 |
commit | 88c8b6493aea1549d71be0345295beb6c4e61c00 (patch) | |
tree | 68b8134e30dfb3d0b2547a410ad8b60b72d3af1d /local/sbin | |
parent | 02a2196150b16ee1c343a5587cadb177016fe222 (diff) | |
download | myconfigs-88c8b6493aea1549d71be0345295beb6c4e61c00.tar.gz myconfigs-88c8b6493aea1549d71be0345295beb6c4e61c00.tar.bz2 myconfigs-88c8b6493aea1549d71be0345295beb6c4e61c00.zip |
Some user services changes
Diffstat (limited to 'local/sbin')
-rwxr-xr-x | local/sbin/syncemail | 22 |
1 files changed, 17 insertions, 5 deletions
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() |