2018年3月21日 星期三

[Systemd] After reboot, ngrok & ctlscript.sh will be started

python script

import os
import sys
import time

def main():
    time.sleep(10)
    cmd = "/home/freeman/webs/redmine-3.3.0-1/ctlscript.sh start &"
    os.system(cmd)
    cmd1 = "/usr/bin/screen -dm /home/freeman/APP/ngrok/ngrok http 8080" 
    os.system(cmd1)

if __name__ == '__main__':
    main()

systemd script
$ cat /etc/systemd/system/myscript.service 
[Unit]
Description=My script

[Service]
User=freeman
Group=freeman
Type=forking
ExecStart=/usr/bin/python3 /home/freeman/a.py

[Install]
WantedBy=multi-user.target

Because ctlscript.sh must execute by normal user not root.
So specifi user and group.

Type=forking is description as following.

The parent process is expected to exit when start-up is complete and all communication channels are set up. The child continues to run as the main daemon process.

Reference:

0 意見:

張貼留言