Toasty27/codecraft-init-script — comment on commit f160239c63d811d014f85180cfed2b1a2ad70558
File:  line 0
By Toasty27:

That'll work for the time being, but what I'd really like to do is set up conditional statements for the individual functions that will run different commands depending on the arguments given by the command line.

So you'd still have:

```shell
case "$1" in
start)
mc_start
;;
stop)
mc_stop
;;
*)
echo "Usage: /etc/init.d/minecraft {start|stop|worldbackup|status|restart}"
exit 1
;;
esac
```

But if you typed in "minecraft start --ramdisk", then the start funtion as given by:

```shell
mc_start() {
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "Tried to start but $SERVICE was already running!"
else
echo "$SERVICE was not running... starting."
cd $MC_PATH
as_user "cd $MC_PATH && screen -dmS $SCREEN_NAME $INVOCATION"
sleep 7
if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
then
echo "$SERVICE is now running."
else
echo "Could not start $SERVICE."
fi
fi
}
```

Would instead have a conditional statement at the beginning which looked for the flag "--ramdisk" and initiated aditional commands to start a ramdisk. Pretend the above code had some of the commands you implemented in your mc_rd_start function, but they were only ran in the event that the "--ramdisk" flag was passed to the script.

So instead of having "mc_start" and "mc_rd_start" you would have "mc_start" with a conditional statement (or maybe multiple conditional statements throughout the function) which looked for the "--ramdisk" flag and issued commands accordingly to properly initiate the ramdisk and move necessary files to said ramdisk.