Syatemd startup script for command?

Discussion in 'Programming & Software Development' started by Revenger, Mar 28, 2021.

  1. Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,323
    Location:
    Armadale / Perth
    I have a command myjd_api I grabbed using pip I can run it anywhere from the command line as myjd_api.
    But I want it to start up automatically on boot.
    So can anyone help me with the startup script?

    I know this is the basis of a systemd service file.

    Code:
    Description=MY Jdownloader API
    
    [Service]
    ExecStart=/usr/bin/screen -c
    Restart=on-failure
    RestartSec=10
    KillMode=process.
    
    [Install]
    WantedBy=multi-user.target.
    When I startup the command it asks for a directory for the config file so that would need to be scripted also.

    Code:
    root@server-web:/etc/systemd/system# myjd_api
    Where do you want to store settings? Leave blank to use the current folder.
    Enter Path:/home/myjd/
    Don't need any text output when running as its just get commands.

    Code:
    192.168.1.3 - - [2021-03-28 10:37:05] "GET / HTTP/1.1" 200 109 10.648759
     
    Last edited: Mar 28, 2021
  2. Yehat

    Yehat Member

    Joined:
    Aug 4, 2002
    Messages:
    523
    Location:
    Melbourne
    edit: ignore not correct...
     
    Last edited: Mar 29, 2021
  3. OP
    OP
    Revenger

    Revenger Member

    Joined:
    Aug 7, 2002
    Messages:
    4,323
    Location:
    Armadale / Perth
    Got the email before the edit haha.
    Sometimes it asks for directory again if you wait a while other times it will restart without asking for the directoty if its within a certain timeframe I think.
    May end up trying a diffrent dashboard.
     
  4. Yehat

    Yehat Member

    Joined:
    Aug 4, 2002
    Messages:
    523
    Location:
    Melbourne
    I think I got a hack workaround I'm just not happy with it...

    Edit:

    So the way the script picks up the environment config is it prompts at the terminal (i.e. you can't just redirect from stdin) and then asks you where to save that config to.

    It takes command line parameters to let you set those environment config prompts, but it still prompts you where to save the file to, which if you're trying to run as a service isn't "ideal"...

    The hack is you tell it it's running as docker, and then in the code, it's hardcoded the path of where it expects the config files to be written to, which you can make accessible by your service, that allows the service to spawn / run. But like I said before the edit, it just looks like its better to possibly run this whole app via docker as it supports it instead of this way. Also by specifying docker as a command line arg nit sure if it hardcodes anything else as well.

    Anyway for what it's worth the hack was:

    File: /etc/systemd/system/myjd-api.service
    Code:
    [Unit]
    Description=myjd api service
    After=multi-user.target
    Conflicts=getty@tty1.service
    
    [Service]
    Type=simple
    User=testuser
    ExecStart=/usr/bin/python3 /home/testuser/.local/bin/myjd_api --jd-user=myuserid.com.au --jd-pass=mypassword --jd-device=mydeviceid.com.au --port=8080 --docker
    StandardInput=tty-force
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    
    When you specify --docker as a command line arg, it defaults to trying to use the file/folder /config/MyJD.ini so make that location writable by the user the app/service is running under and it can persist the config there.

    I've also seen sometimes it reprompts/fails anyway if it thinks (or if it has) expired the token ? So your milage may vary. Like I said before the edit, I haven't used this program before. Good luck.
     
    Last edited: Mar 29, 2021

Share This Page

Advertisement: