'Auto Start Script

So I am making a script that can run these commands whenever a server boot/reboot:

sudo bash
su - erp
cd frappe-bench/
bench start >/tmp/bench_log &

I found guides here and there about how can I change user in script I came out with the following script:

#! /bin/sh

sudo -u erp bash
cd /home/erp/frappe-bench/
bench start >/tmp/bench_log &

And, I have created a service at /etc/systemd/system/ and set it to run automatically when the server boots up.

The problem is, whenever I run sudo systemctl start erpnextd.service and checked the status, it came up with this

May 24 17:10:05 appbsystem2 systemd[1]: Started ERPNext | Auto Restart.
May 24 17:10:05 appbsystem2 sudo[18814]:     root : TTY=unknown ; PWD=/ ; USER=>erp ; COMMAND=/bin/bash
May 24 17:10:05 appbsystem2 systemd[1]: erpnextd.service: Succeeded.

But it still doesn't start up ERPNext.

All I wanted to do is make a script that will start erpnext automatically everytime a server reboot.

Note: I only install frappe-bench on user erp only



Solution 1:[1]

Using crontab (the script will start after every reboot/startup)

#crontab -e
@reboot sh /full/path/to/bench start >/tmp/bench_log

Solution 2:[2]

The answer provide by Thomas is very helpful.

However, I found another workaround by adding the path of my script file into the bottom of /etc/rc.local file.

Both method works, just a matter of preference ;)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Diaruys