Starting a Python script using rc-service

Viewed 834

I am trying to make rc-service start a Python script on startup (Alpine Linux). I have made a simplified example just to get things to work, but no luck.

I have added local to the default run-level, and I have two files in /etc/local.d/ - both owned by root:

one_api.start:

#!/sbin/openrc-run
command=one_api.py

one_api.py:

#!/usr/bin/python3

import uvicorn
from fastapi import FastAPI


app = FastAPI()


@app.get('/')
async def get_root():
    return {'message':'hello, world!'}


if __name__ == '__main__':
    uvicorn.run('one_api:app', host='127.0.0.1', port=8000, log_level='info')

When I try to start local I get * Starting local ... [!!]. I looked for a log in /var/log/ but rc-service doesn't write a log to that location, and I can't find it anywhere else. If I run the Python script manually it works fine.

Trying to start the service by itself also doesn't work:

$ sudo ./one_api.start start
 * Starting one_api.start ...
Segmentation fault
 * Failed to start one_api.start       [ !! ]
 * ERROR: one_api.start failed to start
0 Answers
Related