Support forking of service.
parent
d52c74edc4
commit
5debffbd58
|
@ -16,7 +16,9 @@ def main(args):
|
||||||
parser_remote_delete = sub_parser.add_parser("remote-delete", help="Delete remote.")
|
parser_remote_delete = sub_parser.add_parser("remote-delete", help="Delete remote.")
|
||||||
|
|
||||||
parser_system_server = sub_parser.add_parser("system-server", help="Run system service (root required).")
|
parser_system_server = sub_parser.add_parser("system-server", help="Run system service (root required).")
|
||||||
|
parser_system_server.add_argument("--fork", action="store_const", const=True, default=False, help="Makes a deamon through forking.")
|
||||||
parser_user_server = sub_parser.add_parser("user-server", help="Run user service.")
|
parser_user_server = sub_parser.add_parser("user-server", help="Run user service.")
|
||||||
|
parser_user_server.add_argument("--fork", action="store_const", const=True, default=False, help="Makes a deamon through forking.")
|
||||||
|
|
||||||
# Arguments
|
# Arguments
|
||||||
result = parser.parse_args(args)
|
result = parser.parse_args(args)
|
||||||
|
@ -28,9 +30,12 @@ def main(args):
|
||||||
raise RuntimeError("System service has to run as root.")
|
raise RuntimeError("System service has to run as root.")
|
||||||
|
|
||||||
# Run deamon
|
# Run deamon
|
||||||
asyncio.run(sys_service.rpc.run_deamon()) # TODO: Change default path
|
if result.fork:
|
||||||
|
if os.fork() != 0:
|
||||||
|
return # Stop as parent process
|
||||||
|
asyncio.run(sys_service.rpc.run_deamon(fork=result.fork)) # TODO: Change default path
|
||||||
elif result.action == "user-server":
|
elif result.action == "user-server":
|
||||||
asyncio.run(user_service.rpc.run_deamon()) # TODO: Change default path of user and system socket
|
asyncio.run(user_service.rpc.run_deamon(fork=result.fork)) # TODO: Change default path of user and system socket
|
||||||
|
|
||||||
# Client actions
|
# Client actions
|
||||||
|
|
||||||
|
|
|
@ -15,5 +15,5 @@ async def callback_func(data, uid):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
async def run_deamon(path:str=defaults.DEFAULT_PATH):
|
async def run_deamon(path:str=defaults.DEFAULT_PATH, fork:bool=False):
|
||||||
await utils.run_access_socket(path, callback_func)
|
await utils.run_access_socket(path, callback_func, fork=fork)
|
|
@ -39,7 +39,7 @@ def gen_callback_func(master:BackupManager):
|
||||||
return callback_func
|
return callback_func
|
||||||
|
|
||||||
|
|
||||||
async def run_deamon(user_path:str=None, sys_path:str=defaults.DEFAULT_PATH):
|
async def run_deamon(user_path:str=None, fork:bool=False, sys_path:str=defaults.DEFAULT_PATH):
|
||||||
# Find path
|
# Find path
|
||||||
if user_path is None:
|
if user_path is None:
|
||||||
user_path = defaults.USER_PATH
|
user_path = defaults.USER_PATH
|
||||||
|
@ -55,4 +55,4 @@ async def run_deamon(user_path:str=None, sys_path:str=defaults.DEFAULT_PATH):
|
||||||
timer_task = asyncio.create_task(config.Timer().run(gen_create_backup_func(backup_manager)))
|
timer_task = asyncio.create_task(config.Timer().run(gen_create_backup_func(backup_manager)))
|
||||||
|
|
||||||
# Start serving
|
# Start serving
|
||||||
await utils.run_access_socket(user_path, gen_callback_func(backup_manager))
|
await utils.run_access_socket(user_path, gen_callback_func(backup_manager), fork=fork)
|
|
@ -21,7 +21,7 @@ async def get_user_home(name:str):
|
||||||
return proc_data[0].decode().split(":")[6]
|
return proc_data[0].decode().split(":")[6]
|
||||||
|
|
||||||
|
|
||||||
async def run_access_socket(path:str, async_callback):
|
async def run_access_socket(path:str, async_callback, fork:bool):
|
||||||
async def run_func(read, write):
|
async def run_func(read, write):
|
||||||
# Get user id
|
# Get user id
|
||||||
sock = write.get_extra_info("socket")
|
sock = write.get_extra_info("socket")
|
||||||
|
@ -33,6 +33,9 @@ async def run_access_socket(path:str, async_callback):
|
||||||
await async_callback(read, write, uid)
|
await async_callback(read, write, uid)
|
||||||
server = await asyncio.start_unix_server(run_func, path=path)
|
server = await asyncio.start_unix_server(run_func, path=path)
|
||||||
os.chmod(path, 0o666)
|
os.chmod(path, 0o666)
|
||||||
|
if fork:
|
||||||
|
if os.fork() != 0:
|
||||||
|
exit(0)
|
||||||
await server.serve_forever()
|
await server.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -13,5 +13,5 @@ setup(name="home-backup",
|
||||||
author_email="marko@marko10-000.de",
|
author_email="marko@marko10-000.de",
|
||||||
#url="", TODO: Make a project site
|
#url="", TODO: Make a project site
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
install_requires=["systemd==0.16.1", "aiofile==1.5.2"]
|
install_requires=["aiofile==1.5.2"]
|
||||||
)
|
)
|
Loading…
Reference in New Issue