ubuntu 开机启动脚本

vim /etc/systemd/system/frpc.service

```

[Unit]

Description=FRP Client Service

[Service]

ExecStart=/bin/bash /usr/local/frp/frpc_run.sh

[Install]

WantedBy=multi-user-target

```

In the .service file, I needed to add /bin/bash before the path to the script.

For example, for backup.service:

ExecStart=/bin/bash /home/user/.scripts/backup.sh

As opposed to:

ExecStart=/home/user/.scripts/backup.sh

```

sudo systemctl enable frpc

sudo service frpc start

```

```

sudo systemctl daemon-reload

```


```

$ sudo systemctl list-units |grep frpc

```


Python daemon and systemd service


```

#! /usr/bin/python3

```

chmod 777 xxx.py


```

[Unit]

Description=Auto Connect Wifi service

#Require=network.target

#After=syslog.target network.target remote-fs.target nss-lookup.target

#After=network.target

Conflicts=getty@tty1.service

After=multi-user.target

[Service]

Type=simple

User=root

Group=root

WorkingDirectory=/home/lab001/workspace/startup-script/auto_connect/

#ExecStart=/home/lab001/workspace/startup-script/auto_connect/auto_connect.py

ExecStart=/usr/bin/python3 /home/lab001/workspace/startup-script/auto_connect/auto_connect.py

#ExecStart=/home/lab001/workspace/startup-script/auto_connect/auto_connect.sh

StandardInput=tty-force

StandardOutput=syslog

StandardError=syslog

#RestartSec=30

#Restart=on-failure

#Restart=on-abort

[Install]

WantedBy=multi-user.target

~                         

```


```

$ sudo systemctl daemon-reload && sudo systemctl restart auto_connect.service && sudo systemctl status auto_connect.service

```


Problem:

Failed to execute operation: Invalid argument

https://askubuntu.com/questions/814/how-to-run-scripts-on-start-up

https://haoyu.love/blog521.html

https://stackoverflow.com/questions/45776003/fixing-a-systemd-service-203-exec-failure-no-such-file-or-directory

树莓派设置frpc开机启动

Automatically start long-running script on boot and keep it running with systemd

How do I figure out why systemctl service “systemd-modules-load” fails?

https://superuser.com/questions/997938/how-do-i-figure-out-why-systemctl-service-systemd-modules-load-fails

Systemd service not executing my Python script

Python daemon and systemd service

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。