Handling PID file from within init script
This commit is contained in:
@@ -9,8 +9,6 @@ from pycomm_helper.alarm import AnalogAlarm, bitAlarm
|
|||||||
import traceback
|
import traceback
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||||
from requests.packages.urllib3.exceptions import InsecurePlatformWarning
|
from requests.packages.urllib3.exceptions import InsecurePlatformWarning
|
||||||
@@ -319,16 +317,4 @@ def main():
|
|||||||
print("Error during loop: {}".format(e))
|
print("Error during loop: {}".format(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
pid = str(os.getpid())
|
main()
|
||||||
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()
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ start() {
|
|||||||
fi
|
fi
|
||||||
echo 'Starting service…' >&2
|
echo 'Starting service…' >&2
|
||||||
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
|
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
|
||||||
su -c "$CMD" $RUNAS > /dev/null
|
su -c "$CMD" $RUNAS > "$PIDFILE"
|
||||||
echo 'Service started' >&2
|
echo 'Service started' >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user