Home > Back-end >  Auto Start Script
Auto Start Script

Time:05-25

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

CodePudding user response:

Because you are using systemd, you already have all the features from your script available, and better. So you don't even need the script anymore:

[Unit]
Description=...

[Service]

# Run as user erp.
User=erp
# You probably also want to run as group erp, if it exists.
Group=erp

# Change to this directory before executing.
WorkingDirectory=/home/erp/frappe-bench

# Redirect standard output to the given log file.
StandardOutput=file:/tmp/bench_log
# Redirect standard error to the same log file.
StandardError=file:/tmp/bench_log

# Command line for starting the program. Make sure to use an absolute path!
ExecStart=/full/path/to/bench start

CodePudding user response:

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

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