Added files for quick & dirty daemonization of the app.
This commit is contained in:
62
init.sh
Executable file
62
init.sh
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
### BEGIN INIT INFO
|
||||||
|
# Provides: weblabsd
|
||||||
|
# Required-Start: $network $mysql
|
||||||
|
# Required-Stop: $network $mysql
|
||||||
|
# Default-Start: 2 3 4 5
|
||||||
|
# Default-Stop: 0 1 6
|
||||||
|
# Short-Description: Laboratory inscription daemon.
|
||||||
|
### END INIT INFO
|
||||||
|
|
||||||
|
start() {
|
||||||
|
PID=`pidof weblabsd`
|
||||||
|
if [ $? -eq 0 ]
|
||||||
|
then
|
||||||
|
echo "weblabsd already started."
|
||||||
|
return
|
||||||
|
else
|
||||||
|
echo "Starting weblabsd."
|
||||||
|
cd /home/miky/Documentos/repos/Weblabs.py
|
||||||
|
weblabsd &
|
||||||
|
echo "Done."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
PID=`pidof weblabsd`
|
||||||
|
if [ $? -eq 0 ]
|
||||||
|
then
|
||||||
|
echo "Stopping weblabsd."
|
||||||
|
kill -9 -- -`pidof weblabsd`
|
||||||
|
echo "Done."
|
||||||
|
else
|
||||||
|
echo "weblabsd already stopped."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
start
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
stop
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
PID=`pidof weblabsd`
|
||||||
|
if [ $? -eq 0 ]
|
||||||
|
then
|
||||||
|
echo "weblabsd is running."
|
||||||
|
else
|
||||||
|
echo "weblabsd is down."
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
restart)
|
||||||
|
stop
|
||||||
|
start
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: {start|stop|restart|status}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit $?
|
32
weblabsd.c
Normal file
32
weblabsd.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
FILE * err = freopen("stderr.txt", "w", stderr);
|
||||||
|
|
||||||
|
int rc = daemon(1, 1);
|
||||||
|
if (rc) {
|
||||||
|
perror("failed to daemonize");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_t pid = fork();
|
||||||
|
|
||||||
|
if (pid == 0) {
|
||||||
|
rc = execlp("/usr/bin/python", "/usr/bin/python", "/home/miky/Documentos/repos/Weblabs.py/code.py", NULL);
|
||||||
|
if (rc) {
|
||||||
|
perror("failed to exec python");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
waitpid(pid, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(err);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Reference in New Issue
Block a user