Handling PID file from within init script

This commit is contained in:
Patrick McDonagh
2016-12-05 15:40:24 -06:00
parent a733ec4d9c
commit 099fe06123
2 changed files with 2 additions and 16 deletions

View File

@@ -9,8 +9,6 @@ from pycomm_helper.alarm import AnalogAlarm, bitAlarm
import traceback
import json
import requests
import os
import sys
from requests.packages.urllib3.exceptions import InsecureRequestWarning
from requests.packages.urllib3.exceptions import InsecurePlatformWarning
@@ -319,16 +317,4 @@ def main():
print("Error during loop: {}".format(e))
traceback.print_exc()
if __name__ == '__main__':
pid = str(os.getpid())
pidfile = "/root/datalogger.pid"
if os.path.isfile(pidfile):
print "%s already exists, exiting" % pidfile
sys.exit()
try:
file(pidfile, 'w').write(pid)
main()
except IOError:
print("Unable to write the PID to {}. Running the datalogger anyway.".format(pidfile))
main()
main()

View File

@@ -21,7 +21,7 @@ start() {
fi
echo 'Starting service…' >&2
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
su -c "$CMD" $RUNAS > /dev/null
su -c "$CMD" $RUNAS > "$PIDFILE"
echo 'Service started' >&2
}