Linux: process into a service

后端 未结 3 1083
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 10:59

I am trying to make a linux executable as a service

I execute my program like this below

java -jar mytestprogram.jar

creates a proc

3条回答
  •  误落风尘
    2020-12-02 11:52

    In Ubuntu you can create the file as explained above with few lines, play around and see if it works for you.

    description "My prog"
     
     
    start on (net-device-up
              and local-filesystems
              and runlevel [2345])
    
    stop on runlevel [!2345]
     
    respawn
    respawn limit 10 5
     
    setuid root
    setgid shnmon
     
    script
        /usr/local/bin/my_script -config.path /etc/myprog/yourconfig.xyz -children false >> /var/log/myprog.log 2>&1
    end script

    The "-config.path /etc/myprog/yourconfig.xyz" is optional incase you have a config file.

    You can just edit the script part and test it and keep others default and edit the rest along the way

提交回复
热议问题