fix systemd runtime
This commit is contained in:
parent
98d4802871
commit
64ac9ad155
3 changed files with 44 additions and 29 deletions
6
PKGBUILD
6
PKGBUILD
|
@ -1,6 +1,6 @@
|
|||
# Maintainer: 1ridic <i@8f.al>
|
||||
pkgname=uptimes
|
||||
pkgver=0.1.2
|
||||
pkgver=0.1.3
|
||||
pkgrel=2
|
||||
pkgdesc="status of total uptime"
|
||||
arch=('any')
|
||||
|
@ -11,8 +11,8 @@ source=(
|
|||
local://uptimes
|
||||
local://uptimesd.service
|
||||
)
|
||||
md5sums=('04c97379f5910c5c7fdcea9b6b2e0024'
|
||||
'f006fee00a5269c916d7bacddfe7035c')
|
||||
md5sums=('e70411e89528c1d4f55fdbf97c4e4736'
|
||||
'7a90889f87792317e70ebdce9dae7023')
|
||||
|
||||
package() {
|
||||
install -Dm755 uptimes "$pkgdir/usr/bin/uptimes"
|
||||
|
|
25
uptimes
25
uptimes
|
@ -18,11 +18,14 @@ def main():
|
|||
global uptime, s
|
||||
parse = argparse.ArgumentParser(description='Uptimes')
|
||||
parse.add_argument('-d', '--daemon', action='store_true', help='run as daemon')
|
||||
parse.add_argument('-s', '--systemd', action='store_true', help='run as systemd service')
|
||||
|
||||
|
||||
args = parse.parse_args()
|
||||
if args.daemon:
|
||||
daemon()
|
||||
elif args.systemd:
|
||||
daemon(fork=False)
|
||||
else:
|
||||
# check socket file
|
||||
if not os.path.exists(socket_file):
|
||||
|
@ -85,9 +88,10 @@ def pathExists():
|
|||
os.chmod(uptimes_db, 0o600)
|
||||
|
||||
|
||||
def daemon():
|
||||
def daemon(fork = True):
|
||||
global uptime, now, s
|
||||
# fork
|
||||
if fork:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
sys.exit(0)
|
||||
|
@ -95,16 +99,22 @@ def daemon():
|
|||
os.chdir('/')
|
||||
os.setsid()
|
||||
os.umask(0)
|
||||
# redirect
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
|
||||
si = open('/dev/null', 'r')
|
||||
so = open('/dev/null', 'a+')
|
||||
se = open('/dev/null', 'a+')
|
||||
|
||||
os.dup2(si.fileno(), sys.stdin.fileno())
|
||||
os.dup2(so.fileno(), sys.stdout.fileno())
|
||||
os.dup2(se.fileno(), sys.stderr.fileno())
|
||||
# fork again
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
sys.exit(0)
|
||||
|
||||
# change process name
|
||||
import setproctitle
|
||||
setproctitle.setproctitle('uptimesd')
|
||||
|
||||
# redirect
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
|
@ -117,6 +127,11 @@ def daemon():
|
|||
os.dup2(so.fileno(), sys.stdout.fileno())
|
||||
os.dup2(se.fileno(), sys.stderr.fileno())
|
||||
|
||||
|
||||
# change process name
|
||||
import setproctitle
|
||||
setproctitle.setproctitle('uptimesd')
|
||||
|
||||
# create socket file
|
||||
try:
|
||||
os.unlink(socket_file)
|
||||
|
|
|
@ -3,8 +3,8 @@ Description=uptimes: status of total uptime
|
|||
After=network.target network-online.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
Type=simple
|
||||
User=root
|
||||
ExecStart=/usr/bin/uptimes --daemon
|
||||
ExecStart=/usr/bin/uptimes --systemd
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in a new issue